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

Fix: Improper Error handling on shifting patient #9561

Conversation

AdityaJ2305
Copy link
Contributor

@AdityaJ2305 AdityaJ2305 commented Dec 24, 2024

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

    • Enhanced error handling for consultation data fetching in the DischargeModal.
    • Users will receive notifications for errors related to consultation data retrieval.
    • Added a user-friendly error message for consultation data retrieval failures.
  • Bug Fixes

    • Improved loading state management during data fetching in the DischargeModal.

Copy link

netlify bot commented Dec 24, 2024

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 97816cb
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/6772dc2a1fda16000800ee1f
😎 Deploy Preview https://deploy-preview-9561--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 bot commented Dec 24, 2024

Walkthrough

The pull request updates the DischargeModal component to enhance data fetching and error handling. It replaces the custom hook useTanStackQueryInstead with useQuery from @tanstack/react-query, improving the retrieval of consultation data. The component now manages loading states and displays user-friendly error messages when data fetching fails. Additionally, a new error message key is added to the English locale file, providing clarity to users regarding consultation data issues.

Changes

File Change Summary
src/components/Facility/DischargeModal.tsx - Replaced useTanStackQueryInstead with useQuery for data fetching
- Enhanced error handling with user notifications
- Managed loading state with isLoading property
- Defaulted initialDiagnoses to an empty array if no data is available
public/locale/en.json - Added new key "ERROR_FETCHING_CONSULTATION": "Error while retrieving consultation data"

Assessment against linked issues

Objective Addressed Explanation
Improve error handling during data fetching [#9061]
Prevent application from getting stuck in loading state
Provide user feedback on data fetching errors

Possibly related PRs

Suggested reviewers

  • rithviknishad
  • Jacobjeevan

Poem

🐰 In the code where errors used to play,
A modal now shines bright, leading the way.
With queries so swift, and messages clear,
Fetching data with ease, there's nothing to fear!
Hooray for the changes, let the users rejoice! 🎉


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.

@AdityaJ2305
Copy link
Contributor Author

AdityaJ2305 commented Dec 24, 2024

Hey @rithviknishad, could you review this PR? It’s not fully done yet, but I’d appreciate your feedback on the changes. Am I on the right track, or is there something I might be missing?

Error I am getting when data is passed :

Property 'diagnoses' does not exist on type '({ signal }: { signal: AbortSignal; }) => Promise

@github-actions github-actions bot added needs-triage question Further information is requested labels Dec 24, 2024
@rithviknishad rithviknishad removed question Further information is requested needs-triage labels Dec 24, 2024
@AdityaJ2305 AdityaJ2305 marked this pull request as ready for review December 24, 2024 20:31
@AdityaJ2305 AdityaJ2305 requested a review from a team as a code owner December 24, 2024 20:31
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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b84feda and ae2f5aa.

📒 Files selected for processing (1)
  • src/components/Facility/DischargeModal.tsx (2 hunks)
🔇 Additional comments (3)
src/components/Facility/DischargeModal.tsx (3)

23-23: Looks good.

Importing useAppHistory is appropriate for handling in-app navigation callbacks.


96-97: Ensure graceful fallback if goBack is triggered multiple times.

While the introduction of goBack is logical, consider verifying that it won't lead to unexpected navigation behavior (e.g., multiple consecutive calls ending up at the wrong page or empty history).


98-109: ⚠️ Potential issue

Address potential data type mismatch in the query.

You mentioned encountering a type error 'diagnoses' does not exist on type '(...) => Promise<ConsultationModel>'. Verify that ConsultationModel actually includes the diagnoses property. If not, update the interface or handle missing fields to avoid runtime or TypeScript errors.

src/components/Facility/DischargeModal.tsx Show resolved Hide resolved
Copy link
Contributor

@Jacobjeevan Jacobjeevan left a comment

Choose a reason for hiding this comment

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

Minor things, but otherwise lgtm.

src/components/Facility/DischargeModal.tsx Outdated Show resolved Hide resolved
src/components/Facility/DischargeModal.tsx Outdated Show resolved Hide resolved
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: 1

🧹 Nitpick comments (1)
src/components/Facility/DischargeModal.tsx (1)

105-107: Consider enhancing error handling.

While the basic error handling is implemented, consider:

  1. Adding error type checking for more specific error messages
  2. Implementing error retry logic for transient failures
-  if (error) {
-    Notification.Error({ msg: t("ERROR_FETCHING_CONSULTATION") });
-  }
+  if (error) {
+    if (error instanceof Error) {
+      Notification.Error({ 
+        msg: t("ERROR_FETCHING_CONSULTATION"),
+        description: error.message 
+      });
+    } else {
+      Notification.Error({ msg: t("ERROR_FETCHING_CONSULTATION") });
+    }
+  }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ae2f5aa and 11d012f.

📒 Files selected for processing (2)
  • public/locale/en.json (1 hunks)
  • src/components/Facility/DischargeModal.tsx (4 hunks)
🔇 Additional comments (3)
src/components/Facility/DischargeModal.tsx (2)

1-1: LGTM: Import statements are correctly added.

The required imports for TanStack Query and the query utility are properly added.

Also applies to: 32-32


109-109: LGTM: Data and loading states are properly handled.

The implementation correctly:

  1. Handles undefined data with nullish coalescing
  2. Shows loading state while data is being fetched

Also applies to: 192-192

public/locale/en.json (1)

51-51: LGTM: Error message is properly added.

The error message follows the established conventions:

  1. Uses consistent key naming (all caps with underscores)
  2. Provides clear user feedback
  3. Is properly placed alphabetically in the file

src/components/Facility/DischargeModal.tsx Show resolved Hide resolved
@nihal467
Copy link
Member

LGTM

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

♻️ Duplicate comments (1)
src/components/Facility/DischargeModal.tsx (1)

96-103: 🛠️ Refactor suggestion

Align query implementation with codebase patterns

The current implementation deviates from the established patterns in the codebase:

  1. Query key structure is simplified
  2. Direct usage of useQuery instead of the wrapper

Replace with:

-  const { data, isLoading, error } = useQuery({
-    queryKey: [routes.getConsultation.path, consultationData.id],
-    queryFn: query(routes.getConsultation, {
-      pathParams: { id: consultationData.id },
-      silent: true,
-    }),
-    enabled: consultationData.id !== undefined,
-  });
+  const { data, isLoading, error } = useTanStackQueryInstead(
+    routes.getConsultation,
+    {
+      pathParams: { id: consultationData.id },
+      silent: true,
+    },
+    {
+      enabled: consultationData.id !== undefined,
+    }
+  );
🧹 Nitpick comments (1)
src/components/Facility/DischargeModal.tsx (1)

111-111: Enhance type safety for diagnoses data

While the nullish coalescing operator provides a safe fallback, consider adding runtime type validation:

-  const initialDiagnoses = data?.diagnoses ?? [];
+  const initialDiagnoses = Array.isArray(data?.diagnoses) ? data.diagnoses : [];
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 11d012f and 97816cb.

📒 Files selected for processing (1)
  • src/components/Facility/DischargeModal.tsx (4 hunks)
🔇 Additional comments (3)
src/components/Facility/DischargeModal.tsx (3)

1-1: LGTM: Import changes align with tanstack migration

The addition of useQuery and query imports supports the migration to @tanstack/react-query.

Also applies to: 32-32


105-109: LGTM: Error handling follows best practices

The error handling implementation:

  1. Correctly uses useEffect to prevent multiple notifications
  2. Properly utilizes translations for user-friendly error messages

194-194: LGTM: Loading state properly handled

The loading state implementation correctly uses the isLoading flag from useQuery and renders an appropriate loading component.

@rithviknishad
Copy link
Member

No longer relevant in form-field-v1

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

Successfully merging this pull request may close these issues.

Improper Error Handling while moving the Shifting Cards
4 participants