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

Show Readable Names in Breadcrumbs Instead of Using External Identifiers #10015

Conversation

DonXavierdev
Copy link
Contributor

@DonXavierdev DonXavierdev commented Jan 16, 2025

Proposed Changes

@ohcnetwork/care-fe-code-reviewers

Merge Checklist

  • Add specs that demonstrate bug / test a new feature.
  • Update product documentation.
  • Ensure that UI text is kept in I18n files.
  • Prep screenshot or demo video for changelog entry, and attach it to issue.
  • Request for Peer Reviews
  • Completion of QA

Summary by CodeRabbit

  • New Features

    • Added facility data fetching across multiple components using React Query.
    • Enhanced breadcrumb navigation with dynamic facility names.
    • Introduced patient data fetching in the appointment booking process.
    • Improved loading states for facility and patient data retrieval.
  • Improvements

    • Integrated contextual information in user interfaces.
    • Implemented more robust data fetching mechanisms.
    • Added dynamic breadcrumb replacements for better navigation.

@DonXavierdev DonXavierdev requested a review from a team as a code owner January 16, 2025 12:33
Copy link
Contributor

coderabbitai bot commented Jan 16, 2025

Walkthrough

The pull request introduces a consistent approach to fetching facility data across multiple components using React Query's useQuery hook. The changes focus on dynamically replacing facility and patient IDs in breadcrumbs with their corresponding names. Components like FacilityUsers, PatientHome, PatientRegistration, UserHome, BookAppointment, EncounterList, and EncounterShow now implement similar data fetching patterns to enhance navigation context.

Changes

File Change Summary
src/components/Facility/FacilityUsers.tsx Added facility query to fetch facility data
src/components/Patient/EncounterQuestionnaire.tsx Added encounter data query and dynamic breadcrumb updates
src/components/Patient/PatientHome.tsx Implemented facility data query for breadcrumbs
src/components/Patient/PatientRegistration.tsx Added facility query and updated Page component props
src/components/Users/UserHome.tsx Introduced facility data query with loading state management
src/pages/Appointments/BookAppointment.tsx Added queries for facility and patient data
src/pages/Encounters/EncounterList.tsx Implemented facility data query for breadcrumbs
src/pages/Encounters/EncounterShow.tsx Added facility query for breadcrumb context
src/pages/FacilityOrganization/FacilityOrganizationIndex.tsx Introduced additional facility data query

Assessment against linked issues

Objective Addressed Explanation
Replace External IDs in breadcrumbs with names [#9822]

Possibly related PRs

Suggested labels

tested


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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 Jan 16, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 78a1e7c
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/678df9fdf9e6a0000812e90b
😎 Deploy Preview https://deploy-preview-10015--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

🧹 Nitpick comments (10)
src/components/Users/UserHome.tsx (1)

72-72: Consider optimizing the loading check.

The loading check includes facilityQuery.isLoading unconditionally, but it might be unnecessary when facilityId is not provided.

-  if (loading || facilityQuery.isLoading || !userData) {
+  if (loading || (props.facilityId && facilityQuery.isLoading) || !userData) {
src/components/Facility/FacilityUsers.tsx (1)

127-134: Consider adding error handling for the facility query.

While the query is well-structured, it would benefit from error handling to gracefully handle failed facility data fetches.

 const facilityQuery = useQuery({
   queryKey: ["facility", props.facilityId],
   queryFn: query(routes.getPermittedFacility, {
     pathParams: {
       id: props.facilityId,
     },
   }),
+  onError: (error) => {
+    console.error('Failed to fetch facility:', error);
+  },
 });
src/components/Patient/PatientHome.tsx (1)

29-36: Consider adding error boundaries for facility data fetches.

While the query implementation is correct, adding error boundaries would improve the user experience when facility data fetches fail.

 const facilityQuery = useQuery({
   queryKey: ["facility", props.facilityId],
   queryFn: query(routes.getPermittedFacility, {
     pathParams: {
       id: props.facilityId || "",
     },
   }),
+  onError: (error) => {
+    console.error('Failed to fetch facility:', error);
+  },
 });
src/pages/Encounters/EncounterShow.tsx (1)

95-102: Add error handling and loading states for the facility query.

The facility query implementation looks good, but it should handle error and loading states to ensure a smooth user experience.

 const facilityQuery = useQuery({
   queryKey: ["facility", props.facilityId],
   queryFn: query(routes.getPermittedFacility, {
     pathParams: {
       id: props.facilityId,
     },
   }),
+  retry: false,
+  staleTime: 5 * 60 * 1000, // Cache for 5 minutes since facility data rarely changes
 });
src/pages/Appointments/BookAppointment.tsx (1)

71-86: Add error handling and enable queries conditionally.

The queries look good but could be improved with error handling and conditional enabling.

 const facilityQuery = useQuery({
   queryKey: ["facility", props.facilityId],
   queryFn: query(routes.getPermittedFacility, {
     pathParams: {
       id: props.facilityId,
     },
   }),
+  enabled: !!props.facilityId,
+  retry: false,
+  staleTime: 5 * 60 * 1000,
 });

 const patientQuery = useQuery({
   queryKey: ["patient", props.patientId],
   queryFn: query(routes.patient.getPatient, {
     pathParams: {
       id: props.patientId,
     },
   }),
+  enabled: !!props.patientId,
+  retry: false,
 });
src/components/Patient/PatientRegistration.tsx (1)

160-167: Add error handling and enable query conditionally.

The facility query implementation could be improved with error handling and conditional enabling.

 const facilityQuery = useQuery({
   queryKey: ["facility", props.facilityId],
   queryFn: query(routes.getPermittedFacility, {
     pathParams: {
       id: props.facilityId,
     },
   }),
+  enabled: !!props.facilityId,
+  retry: false,
+  staleTime: 5 * 60 * 1000,
 });
src/pages/Encounters/EncounterList.tsx (2)

205-212: Improve error handling and remove empty string fallback.

The facility query implementation could be improved:

  1. Add error handling
  2. Remove empty string fallback for facilityId
 const facilityQuery = useQuery({
   queryKey: ["facility", facilityId],
   queryFn: query(routes.getPermittedFacility, {
     pathParams: {
-      id: facilityId || "",
+      id: facilityId,
     },
   }),
+  enabled: !!facilityId,
+  retry: false,
+  staleTime: 5 * 60 * 1000,
 });

248-254: Remove empty string fallback in breadcrumb replacements.

The implementation should avoid using empty string fallback for facilityId.

 <Page
   title={t("encounters")}
   hideBack={true}
   crumbsReplacements={{
-    [facilityId || ""]: { name: facilityQuery.data?.name },
+    [facilityId]: { name: facilityQuery.data?.name },
   }}
 >
src/pages/FacilityOrganization/FacilityOrganizationIndex.tsx (2)

39-45: LGTM! Consider adding error handling.

The facility data query is well-structured and aligns with React Query best practices. However, consider handling potential error states to provide a better user experience when the facility data fetch fails.

  const { data: facilityData, isLoading: isFacilityLoading } = useQuery({
    queryKey: ["facility", facilityId],
    queryFn: query(routes.getPermittedFacility, {
      pathParams: { id: facilityId },
    }),
    enabled: !!facilityId,
+   onError: (error) => {
+     // Handle error state, e.g., show a toast notification
+     console.error('Failed to fetch facility data:', error);
+   }
  });

97-103: Add optional chaining for safer property access.

While the breadcrumb replacement logic is clean, we should handle the case where facilityData might be undefined.

  <Page
    title={t("facility_organizations")}
    hideBack={true}
    crumbsReplacements={{
-     [facilityId]: { name: facilityData?.name },
+     [facilityId]: facilityData && { name: facilityData.name },
    }}
  >
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a4b4206 and 237f499.

📒 Files selected for processing (9)
  • src/components/Facility/FacilityUsers.tsx (2 hunks)
  • src/components/Patient/EncounterQuestionnaire.tsx (3 hunks)
  • src/components/Patient/PatientHome.tsx (2 hunks)
  • src/components/Patient/PatientRegistration.tsx (2 hunks)
  • src/components/Users/UserHome.tsx (4 hunks)
  • src/pages/Appointments/BookAppointment.tsx (3 hunks)
  • src/pages/Encounters/EncounterList.tsx (2 hunks)
  • src/pages/Encounters/EncounterShow.tsx (2 hunks)
  • src/pages/FacilityOrganization/FacilityOrganizationIndex.tsx (2 hunks)
🔇 Additional comments (9)
src/components/Patient/EncounterQuestionnaire.tsx (2)

32-41: LGTM! Well-structured query implementation.

The encounter query is well-implemented with proper error handling and conditional enabling.


47-57: LGTM! Comprehensive breadcrumb replacements.

The implementation efficiently uses the encounter data to replace multiple identifiers with readable names in a single query.

src/components/Users/UserHome.tsx (1)

64-70: LGTM! Well-structured facility query.

The facility query is properly implemented with correct path parameters.

src/components/Patient/PatientHome.tsx (1)

60-63: LGTM! Well-structured breadcrumb replacements.

The implementation correctly combines both patient and facility names in the breadcrumbs.

src/pages/Encounters/EncounterShow.tsx (1)

205-207: LGTM! Clean implementation of breadcrumb replacements.

The implementation safely handles undefined facility data using optional chaining.

src/pages/Appointments/BookAppointment.tsx (1)

224-230: LGTM! Clean implementation of breadcrumb replacements.

The implementation safely handles undefined data using optional chaining for both facility and patient names.

src/components/Patient/PatientRegistration.tsx (1)

295-300: LGTM! Clean implementation of breadcrumb replacements.

The implementation safely handles undefined facility data using optional chaining.

src/pages/FacilityOrganization/FacilityOrganizationIndex.tsx (2)

46-46: LGTM! Comprehensive loading state handling.

The combined loading check ensures a smooth user experience by showing the skeleton UI until all data is available.


39-45: Verify consistent implementation across components.

Let's verify that this breadcrumb enhancement pattern is consistently implemented across other components mentioned in the AI summary.

Also applies to: 97-103

✅ Verification successful

Implementation verified as consistent across components

The facility data query implementation follows a consistent pattern across the codebase, with proper query keys and conditional fetching. The variations found in some components appear to be intentional based on different access requirements.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistent implementation of facility name in breadcrumbs
# across components mentioned in the AI summary

# Search for similar useQuery patterns with facility data
echo "Checking for consistent facility data query implementation..."
rg -l "useQuery.*getPermittedFacility.*crumbsReplacements" \
  src/components/Facility/FacilityUsers.tsx \
  src/components/Patient/PatientHome.tsx \
  src/components/Patient/PatientRegistration.tsx \
  src/pages/Appointments/BookAppointment.tsx

# Search for potential performance bottlenecks
echo "Checking for potential duplicate queries..."
rg "queryKey.*facility.*facilityId" -A 2

Length of output: 6170

@DonXavierdev
Copy link
Contributor Author

@rithviknishad Can you please check this . I had to close the other PR related to this.

@github-actions github-actions bot added the merge conflict pull requests with merge conflict label Jan 20, 2025
Copy link

👋 Hi, @DonXavierdev,
Conflicts have been detected against the base branch. Please rebase your branch against the base branch.


This message is automatically generated by prince-chrismc/label-merge-conflicts-action so don't hesitate to report issues/improvements there.

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

🧹 Nitpick comments (2)
src/pages/Encounters/EncounterList.tsx (1)

254-260: Consider handling loading and error states for breadcrumb replacements.

While the implementation works, it might be good to handle loading and error states for a better user experience.

Consider adding a loading state and fallback:

 <Page
   title={t("encounters")}
   hideBack={true}
   crumbsReplacements={{
-    [facilityId || ""]: { name: facilityQuery.data?.name },
+    [facilityId || ""]: {
+      name: facilityQuery.data?.name,
+      loading: facilityQuery.isLoading,
+      error: facilityQuery.error?.message
+    },
   }}
 >
src/components/Patient/PatientRegistration.tsx (1)

320-325: Consider handling loading and error states for breadcrumb replacements.

While the implementation works, it might be good to handle loading and error states for a better user experience.

Consider adding a loading state and fallback:

 <Page
   title={title}
   crumbsReplacements={{
-    [facilityId]: { name: facilityQuery.data?.name },
+    [facilityId]: {
+      name: facilityQuery.data?.name,
+      loading: facilityQuery.isLoading,
+      error: facilityQuery.error?.message
+    },
   }}
 >
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 237f499 and 78a1e7c.

📒 Files selected for processing (2)
  • src/components/Patient/PatientRegistration.tsx (2 hunks)
  • src/pages/Encounters/EncounterList.tsx (2 hunks)
🔇 Additional comments (2)
src/pages/Encounters/EncounterList.tsx (1)

214-221: LGTM! The facility query implementation is consistent.

The implementation follows the established pattern for facility data fetching across components.

src/components/Patient/PatientRegistration.tsx (1)

168-176: LGTM! The facility query implementation is consistent.

The implementation follows the established pattern for facility data fetching across components.

@github-actions github-actions bot removed the merge conflict pull requests with merge conflict label Jan 20, 2025
Copy link
Member

@bodhish bodhish left a comment

Choose a reason for hiding this comment

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

Not a fan of fetching data just for breadcrumbs :(

@DonXavierdev
Copy link
Contributor Author

Not a fan of fetching data just for breadcrumbs :(

Another way would be to pass it via props but then still i would have to fetch it at some point right ? @bodhish

@github-actions github-actions bot added needs-triage question Further information is requested labels Jan 21, 2025
@github-actions github-actions bot added the merge conflict pull requests with merge conflict label Jan 21, 2025
Copy link

👋 Hi, @DonXavierdev,
Conflicts have been detected against the base branch. Please rebase your branch against the base branch.


This message is automatically generated by prince-chrismc/label-merge-conflicts-action so don't hesitate to report issues/improvements there.

@rithviknishad
Copy link
Member

Let's hold this for now, if we switch to tanstack router, this can be achieved easily with route contexts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion required merge conflict pull requests with merge conflict question Further information is requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace External IDs in breadcrumbs with names
4 participants