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: #11090 improve mobile experience for questionnaire errors #11091

Merged
merged 2 commits into from
Mar 6, 2025

Conversation

bodhish
Copy link
Member

@bodhish bodhish commented Mar 6, 2025

Fixes #11090

Summary by CodeRabbit

  • New Features
    • Enhanced error feedback in forms with clear, structured messages during submission issues.
    • Improved error messaging for batch processing, providing more detailed notifications when validation problems occur.

…ve collapsible component and always show validation errors
@bodhish bodhish requested a review from a team as a code owner March 6, 2025 20:11
Copy link
Contributor

coderabbitai bot commented Mar 6, 2025

Walkthrough

This pull request enhances error handling and type definitions across the application. In the questionnaire form component, it adds a new server validation error interface, renames an existing interface for clarity, and integrates a ValidationErrorDisplay component to show errors. In the batch processing types, it updates interfaces to include additional error details and refines response union types.

Changes

File(s) Change Summary
src/components/Questionnaire/QuestionnaireForm.tsx Added ServerValidationError interface; renamed BatchRequest to FormBatchRequest; introduced ValidationErrorDisplay with props and helper methods for error display; updated state management and error filtering in form submission.
src/types/.../batch.ts Updated BatchRequestResult to include reference_id and optional data; removed BaseValidationError and added detailed error interfaces; redefined batch response union types.

Sequence Diagram(s)

sequenceDiagram
  participant U as User
  participant QF as QuestionnaireForm
  participant S as Server
  participant V as ValidationErrorDisplay

  U->>+QF: Submit Form
  QF->>+S: Send Request
  S-->>-QF: Response (status_code, error data)
  alt Error Detected
      QF->>QF: Filter non-200 responses
      QF->>+V: Pass serverErrors data
      V-->>-QF: Render error messages
  else Success
      QF->>QF: Process valid response
  end
Loading

Suggested labels

needs review, tested

Suggested reviewers

  • rithviknishad
  • Jacobjeevan

Poem

In a code garden under the moonlight glow,
I, a little rabbit, see errors ebb and flow.
With checks and types now neatly arranged,
Each bug and mistake gracefully exchanged.
Hopping through files with a joyful cheer,
Celebrating changes that make our code clear!
🐰✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
  • @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

cloudflare-workers-and-pages bot commented Mar 6, 2025

Deploying care-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: d1d487b
Status: ✅  Deploy successful!
Preview URL: https://65798b6a.care-fe.pages.dev
Branch Preview URL: https://fix-11090-questionnaire-mobi.care-fe.pages.dev

View logs

Copy link

netlify bot commented Mar 6, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 2c615cc
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67ca0180f1cbd600087479d7
😎 Deploy Preview https://deploy-preview-11091.preview.ohc.network
📱 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.

@bodhish
Copy link
Member Author

bodhish commented Mar 6, 2025

@amjithtitus09 I am merging this as a temp fix

Copy link

netlify bot commented Mar 6, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit d1d487b
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67ca01ad8175250008dc5278
😎 Deploy Preview https://deploy-preview-11091.preview.ohc.network
📱 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.

@bodhish bodhish merged commit 1fdd91f into develop Mar 6, 2025
17 of 26 checks passed
@bodhish bodhish deleted the fix/11090-questionnaire-mobile-errors branch March 6, 2025 20:16
Copy link

github-actions bot commented Mar 6, 2025

@bodhish 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! 🙌

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 (17)
src/components/Questionnaire/QuestionnaireForm.tsx (8)

45-50: Leverage specific HTTP method type instead of string.
Declaring method as a plain string may reduce type safety. Consider using a more specific type (e.g., a union of allowed HTTP verbs) to catch typos and invalid methods at compile-time.

 interface FormBatchRequest {
   url: string;
-  method: string;
+  method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
   body: Record<string, any>;
   reference_id: string;
 }

52-56: Add doc comments for clarity.
Though straightforward, adding minimal doc comments (JSDoc/TSDoc) for each property in ServerValidationError can help future contributors quickly understand the error fields.


68-71: Optionally enforce strictness on props.
Having serverErrors optional is fine, but consider whether defaulting to an empty array would simplify usage by reducing the need to check for undefined.


73-83: Extract smaller helper utilities.
The ValidationErrorDisplay component is large and includes multiple helper functions. Splitting utility functions (e.g., findQuestionText) into smaller, more testable units could improve readability and maintainability.


132-274: Remove repeated scroll/visual highlight logic.
Scrolling and highlighting are repeated in multiple places for both server-level and form-level errors. Abstracting these steps into a shared helper function would reduce duplication and simplify future changes.

-                // Scrolling logic repeated in lines 167–200 & 232–264
+                // Suggest using a helper like scrollToQuestion(questionId)

289-289: Consider initializing with an empty array.
Using [ ] as the default value for serverErrors instead of undefined can simplify checks and reduce the likelihood of null/undefined references.


310-310: Use empty array instead of undefined for consistency.
Similarly here, setting serverErrors to [] might be more consistent than undefined if all calling code expects an array.


315-383: Refactor large error-processing block.
This block of error parsing, mapping, and server error extraction is quite extensive. Extracting it into a dedicated function or custom hook (e.g., useServerErrorHandler) could reduce complexity within this component and ease maintenance.

src/types/questionnaire/batch.ts (9)

16-22: Add doc comments for clarity.
QuestionValidationError would benefit from short descriptions on each field to help new contributors understand how these properties interplay in validation scenarios.


24-31: Consider a more descriptive name for ctx.
ctx is flexible but somewhat vague. Clarifying its content in documentation or renaming it (e.g., contextData) may help readability.


33-42: Maintain consistent naming.
BatchRequestError properties such as msg and error overlap in meaning. Consider merging or clarifying them to avoid ambiguity.


55-61: Restrict HTTP methods if possible.
Like in FormBatchRequest, your BatchRequest could also use a union of string literal types for method to reduce possible runtime errors from incorrect method strings.


63-65: Use more explicit naming.
The BatchErrorData name is fine, but a doc comment indicating that this interface holds an array of BatchRequestError clarifies usage.


67-70: Tag base fields with doc comments.
BatchResponseBase is frequently extended. Adding short doc comments for reference_id and status_code can improve readability and serve as a quick reference for future maintainers.


72-74: Validate data shape for BatchErrorResponse.
Consider whether StructuredDataError[] might need a more precise type (e.g., each item also guaranteeing certain fields). This could strengthen type-safety.


81-86: Mark errors as optional if partial failures are possible.
In some scenarios, the response might contain additional data even when there's only a warning, but no full error. If partial error states occur, updating the interface accordingly can prevent confusion.


88-93: Unify or consolidate union types.
Consider merging BatchResponseResult, BatchRequestResult, and BatchResponse to ensure you don’t have overlapping definitions. This can help maintain a single source of truth.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4b132b1 and d1d487b.

📒 Files selected for processing (2)
  • src/components/Questionnaire/QuestionnaireForm.tsx (6 hunks)
  • src/types/questionnaire/batch.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Redirect rules - care-ohc
  • GitHub Check: Header rules - care-ohc
  • GitHub Check: Pages changed - care-ohc
  • GitHub Check: cypress-run (1)
  • GitHub Check: Cloudflare Pages: care-fe
🔇 Additional comments (5)
src/components/Questionnaire/QuestionnaireForm.tsx (2)

557-557: Initialization is straightforward.
Using a typed array for storing requests is fine. No further action needed here.


819-823: Placement of ValidationErrorDisplay is effective.
Rendering ValidationErrorDisplay after the questionnaire forms is logical. It ensures all form data and errors are collected before displaying them.

src/types/questionnaire/batch.ts (3)

2-3: Ensure alignment with server definitions.
reference_id and data are fundamental fields. Confirm that the server’s response always provides these fields. If data can be empty or missing, the ? is correct; otherwise, consider removing the optional to enforce data presence.


44-53: StructuredDataError structure looks consistent.
Ensure each nested error object consistently matches the shape expected by validating code. No immediate concerns here.


76-78: Check for potential empty success response.
If data might be empty or null, consider marking it optional or handle it in your application logic so you don’t rely on a missing property.

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

Successfully merging this pull request may close these issues.

Its super hard to debug questionnaire errors on mobile
1 participant