Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Breadcrumb to Display Detailed Name Instead of ID #9200

Merged

Conversation

rayyjeb
Copy link
Contributor

@rayyjeb rayyjeb commented Nov 25, 2024

Proposed Changes

@ohcnetwork/care-fe-code-reviewers

Summary by CodeRabbit

  • New Features

    • Introduced crumbsReplacements for enhanced breadcrumb navigation on the Sample Details and Shift Details pages, displaying the patient's name.
    • Updated clipboard functionality in Shift Details to improve user experience.
    • Conditional rendering of the logo in printed data based on specific properties.
  • Bug Fixes

    • Updated the patient_name property type in the SampleTestModel for better data handling.

@rayyjeb rayyjeb requested a review from a team as a code owner November 25, 2024 10:02
Copy link
Contributor

coderabbitai bot commented Nov 25, 2024

Walkthrough

The changes in this pull request introduce a new property, crumbsReplacements, to the Page component in both the SampleDetails.tsx and ShiftDetails.tsx files, allowing breadcrumbs to display the patient's name instead of an ID. Additionally, the patient_name property type in the SampleTestModel interface is updated from number to string in models.tsx. These modifications enhance breadcrumb navigation and ensure proper data representation in the patient model.

Changes

File Path Change Summary
src/components/Patient/SampleDetails.tsx Added crumbsReplacements property to Page component.
src/components/Patient/models.tsx Changed patient_name property type from number to string in SampleTestModel interface.
src/components/Shifting/ShiftDetails.tsx Added crumbsReplacements property to Page component; updated showCopyToclipBoard function to include new data parameter; modified printData function to conditionally render logo based on is_kasp.

Assessment against linked issues

Objective Addressed Explanation
Fix breadcrumb to display detailed name instead of ID (#[9197])
Change patient_name type from number to string in models (#[9197])

Possibly related PRs

Suggested labels

needs review, tested

Suggested reviewers

  • Jacobjeevan
  • rithviknishad
  • khavinshankar

Poem

🐇 In the garden where names bloom bright,
Breadcrumbs now shine with patient light.
No more IDs to lead the way,
Just friendly names to guide the day!
With models updated, all feels right,
Hooray for changes, a joyful sight! 🌼


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1fd9ca8 and ee54afc.

📒 Files selected for processing (2)
  • src/components/Patient/SampleDetails.tsx (1 hunks)
  • src/components/Patient/models.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/components/Patient/SampleDetails.tsx
  • src/components/Patient/models.tsx

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Nov 25, 2024

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit ee54afc
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/674814dd70b67d000866d6d0
😎 Deploy Preview https://deploy-preview-9200--care-ohc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (4)
src/components/Patient/SampleDetails.tsx (1)

302-304: Consider adding a type check for patient_name.

While the loading check prevents null/undefined errors, it would be good to add an additional type check for patient_name to handle edge cases where the API response might be incomplete.

 <Page
   title={t("sample_test_details")}
-  crumbsReplacements={{ [id]: { name: sampleDetails.patient_name } }}
+  crumbsReplacements={{ [id]: { name: sampleDetails.patient_name || t("unknown_patient") } }}
   backUrl="/sample"
src/components/Shifting/ShiftDetails.tsx (3)

481-483: LGTM! Consider enhancing null safety.

The implementation correctly replaces the ID with the patient's name in the breadcrumb navigation. However, we could enhance the null safety by providing a fallback value.

  crumbsReplacements={{
-   [props.id]: { name: data?.patient_object?.name },
+   [props.id]: { name: data?.patient_object?.name || t("unknown_patient") },
  }}

Line range hint 32-38: Fix clipboard copy feedback and timer management.

The clipboard copy functionality has potential issues:

  1. The isCopied state isn't reset when copying different data
  2. The setTimeout for resetting isCopied could cause memory leaks

Consider refactoring the clipboard functionality:

+ import { useEffect } from "react";

  const [isCopied, setIsCopied] = useState(false);
+ 
+ useEffect(() => {
+   if (isCopied) {
+     const timer = setTimeout(() => {
+       setIsCopied(false);
+     }, 5000);
+     return () => clearTimeout(timer);
+   }
+ }, [isCopied]);

  const showCopyToclipBoard = (data: any) => {
    return (
      <a href="#">
        <CopyToClipboard
          text={copyContent(data)}
-         onCopy={() => setIsCopied(true)}
+         onCopy={() => {
+           setIsCopied(false); // Reset first to ensure state change even if same data
+           setIsCopied(true);
+         }}
        >

Also applies to: 481-483


Line range hint 1-783: Consider splitting the component for better maintainability.

The component has grown quite large and handles multiple responsibilities. Consider splitting it into smaller, focused components:

  1. Extract print-related logic into a separate component
  2. Move facility and patient card rendering into their own components
  3. Consider using a custom hook for clipboard functionality

Example structure:

// ShiftDetailsPrint.tsx
export const ShiftDetailsPrint = ({ data, onClose }) => {
  // printData logic here
};

// ShiftDetailsCards.tsx
export const FacilityCard = ({ facility }) => {
  // showFacilityCard logic here
};

export const PatientCard = ({ patient }) => {
  // showPatientCard logic here
};

// hooks/useClipboard.ts
export const useClipboard = (timeout = 5000) => {
  // clipboard logic here
};
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fdfc53d and 9ca4a4a.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • src/components/Patient/SampleDetails.tsx (1 hunks)
  • src/components/Patient/models.tsx (1 hunks)
  • src/components/Shifting/ShiftDetails.tsx (1 hunks)
🔇 Additional comments (5)
src/components/Patient/models.tsx (2)

168-168: LGTM! Type change aligns with requirements

The change from number to string for patient_name is correct and maintains consistency with other interfaces in the file that use string-based name fields.


168-168: Verify the impact of this breaking change

This type change from number to string could affect existing code that expects patient_name to be a number.

Let's verify the usage across the codebase:

src/components/Patient/SampleDetails.tsx (3)

303-303: LGTM! Breadcrumb replacement implementation looks correct.

The implementation correctly uses the patient_name from sampleDetails to replace the ID in the breadcrumb. The null check on line 302 (if (isLoading || !sampleDetails)) ensures this prop is only set when data is available.


303-303: Verify consistency of patient name display.

The patient name is displayed in both the breadcrumb and the details section. Let's verify that the same value is used consistently.

Also applies to: 371-373

✅ Verification successful

Based on the search results, I can now provide a final response regarding the consistency of patient name display:

Patient name is consistently displayed in both locations

The SampleDetails component consistently uses sampleDetails.patient_name in both locations:

  • In the breadcrumb: crumbsReplacements={{ [id]: { name: sampleDetails.patient_name } }}
  • In the details section: <span id="patient_name">{sampleDetails?.patient_name}</span>

The same data source is used for both displays, ensuring consistency.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistent patient name usage across components
# Look for all occurrences of patient_name to ensure consistent usage

rg -A 2 'patient_name' --type tsx --type ts

Length of output: 71


Script:

#!/bin/bash
# Search for patient_name occurrences without file type restrictions
rg -A 2 'patient_name'

Length of output: 6878


Script:

#!/bin/bash
# Search for components that might display patient names using common patterns
rg -A 2 'patient\.name|patientName|patient_name'

Length of output: 21615


Script:

#!/bin/bash
# Look for the SampleDetails component implementation
ast-grep --pattern 'const SampleDetails = $_'

Length of output: 38042


303-303: Verify Page component compatibility and type definitions.

Let's verify that:

  1. The Page component properly handles the crumbsReplacements prop
  2. The patient_name type is correctly defined as string in models.tsx
✅ Verification successful

The crumbsReplacements prop and patient_name type are properly defined

Based on the verification results:

  1. The Page component correctly inherits and handles the crumbsReplacements prop through PageTitleProps interface, which is properly typed as { [key: string]: { name?: string; uri?: string; style?: string } }.
  2. The patient_name is correctly defined as an optional string (patient_name?: string) in the SampleTestModel interface in models.tsx.

The usage in SampleDetails.tsx is type-safe and consistent with these definitions.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify Page component props and patient_name type definition

# Check Page component props
ast-grep --pattern 'interface $props {
  $$$
  crumbsReplacements?: $_
  $$$
}'

# Check patient_name type in models
ast-grep --pattern 'interface $model {
  $$$
  patient_name: string
  $$$
}'

Length of output: 160


Script:

#!/bin/bash
# Let's try a different approach to find the Page component and its props
# Search for Page component definition and crumbsReplacements usage
rg -A 5 "interface PageProps" 

# Search for any interface or type containing patient_name
rg -A 3 "patient_name.*:" 

# Search for actual usage of crumbsReplacements in Page component
rg "crumbsReplacements"

# Look for Page component implementation
ast-grep --pattern 'const Page = $_'

Length of output: 7303


Script:

#!/bin/bash
# Let's check the PageTitleProps interface and crumbsReplacements type definition
rg -A 10 "interface PageTitleProps"

# Check the actual implementation of crumbsReplacements in PageTitle
cat src/components/Common/PageTitle.tsx

# Check the patient_name type in the specific interface from models.tsx
cat src/components/Patient/models.tsx

Length of output: 15508

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor thing, but can you get changes in package-lock removed from the commit?

You can reset the HEAD, remove from staging and do a force push.

@rayyjeb rayyjeb closed this Nov 25, 2024
@rayyjeb rayyjeb force-pushed the issues/9197/BreadCrumb_ID_Fix branch from 9ca4a4a to 2fdffa2 Compare November 25, 2024 17:31
@Jacobjeevan
Copy link
Contributor

@rayyjeb Ensure that other changes are in staging though.

@rayyjeb
Copy link
Contributor Author

rayyjeb commented Nov 25, 2024

@Jacobjeevan Should I reopen the pull request once again since, the it is showing as closed

@github-actions github-actions bot added needs-triage question Further information is requested labels Nov 25, 2024
@Jacobjeevan
Copy link
Contributor

@Jacobjeevan Should I reopen the pull request once again since, the it is showing as closed

Yea

@Jacobjeevan Jacobjeevan removed question Further information is requested needs-triage labels Nov 25, 2024
@rayyjeb rayyjeb reopened this Nov 25, 2024
@rayyjeb
Copy link
Contributor Author

rayyjeb commented Nov 29, 2024

@rithviknishad Could you please review the PR again? If there's anything, Do let me know

@github-actions github-actions bot added needs-triage question Further information is requested labels Nov 29, 2024
@Jacobjeevan
Copy link
Contributor

@rithviknishad Could you please review the PR again? If there's anything, Do let me know

He already approved it 🤔 and there hasn't been any changes since approval.

@Jacobjeevan Jacobjeevan removed question Further information is requested needs-triage labels Nov 29, 2024
@rithviknishad
Copy link
Member

rithviknishad commented Nov 29, 2024

@rayyjeb It's queued for testing. @nihal467 would do QA and mark it as tested. Once that's done, we are good to merge it.

@nihal467
Copy link
Member

LGTM

@rithviknishad rithviknishad merged commit 7d56fdc into ohcnetwork:develop Nov 30, 2024
21 checks passed
Copy link

@rayyjeb Your efforts have helped advance digital healthcare and TeleICU systems. 🚀 Thank you for taking the time out to make CARE better. We hope you continue to innovate and contribute; your impact is immense! 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix Breadcrumb to Display Detailed Name Instead of ID
4 participants