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

Enhance AllergyQuestion component with improved UI and functionality.… #9647

Merged
merged 3 commits into from
Jan 2, 2025

Conversation

bodhish
Copy link
Member

@bodhish bodhish commented Jan 2, 2025

This pull request includes significant changes to the AllergyQuestion component in the Questionnaire module. The changes involve updating the UI components, enhancing the handling of allergy data, and improving the overall user experience. The most important changes include replacing the table layout with a responsive grid, introducing dropdown menus for actions, and refactoring the state management for allergies.

UI Enhancements:

  • Replaced the table layout with a responsive grid for better display on different screen sizes.
  • Introduced DropdownMenu components for managing allergy actions, such as adding notes or removing allergies.

State Management Improvements:

  • Refactored the state management for allergies by removing the use of useState and directly updating the questionnaireResponse prop.
  • Added constants for initial allergy values and allergy categories to standardize the data structure.

Code Refactoring:

  • Split the AllergyQuestion component into smaller components, such as AllergyItem, to improve code readability and maintainability.
  • Updated the imports to include necessary components and remove unused ones.

@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

    • Introduced a more interactive and modular allergy management interface
    • Added ability to search and add allergies
    • Enhanced allergy entry with toggleable details and improved layout
    • Implemented a new focus event handler in the input component for enhanced user interaction
  • UI/UX Improvements

    • Redesigned allergy display with a more responsive grid system
    • Added interactive elements for managing allergy entries

… Added AllergyItem subcomponent for better management of allergies, including dropdown menus for editing and removing allergies. Updated state management for allergies and integrated new UI elements for displaying allergy details, including last occurrence and notes. Refactored code for clarity and maintainability.
@bodhish bodhish requested a review from a team as a code owner January 2, 2025 09:52
Copy link
Contributor

coderabbitai bot commented Jan 2, 2025

Walkthrough

The pull request introduces significant modifications to the AllergyQuestion component, transitioning from a table layout to a modular design utilizing the AllergyTableRow component for individual allergy entries. It simplifies state management by deriving allergies directly from questionnaireResponse, and updates functions for adding, removing, and updating allergies. Additionally, the UI is enhanced with new interactive elements like icons and dropdown menus, and the layout is improved with a grid system for better organization.

Changes

File Change Summary
src/components/Questionnaire/QuestionTypes/AllergyQuestion.tsx - Replaced table layout with AllergyTableRow component
- Simplified state management by removing setAllergies
- Updated handleAddAllergy to accept Code parameter
- Streamlined handleRemoveAllergy and handleUpdateAllergy
- Added imports for icons and dropdown components
- Adjusted layout to a grid system
- Updated method signatures and added new interfaces
src/components/ui/input.tsx - Introduced onFocus event handler for input element

Possibly related PRs

Suggested labels

tested, reviewed, P1

Suggested reviewers

  • rithviknishad
  • bodhish

Poem

🐰 In a world of allergies, we leap and bound,
Modular rows and dropdowns abound!
Simplified states, like a breeze they flow,
A grid of delight, watch the data grow!
With each little click, our joy is profound,
In this new design, happiness is found! 🌼


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c03c3cb and ab1a93a.

📒 Files selected for processing (1)
  • src/components/ui/input.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/ui/input.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 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 2, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit ab1a93a
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67769ba4585440000878f22d
😎 Deploy Preview https://deploy-preview-9647--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

cloudflare-workers-and-pages bot commented Jan 2, 2025

Deploying care-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: ab1a93a
Status: ✅  Deploy successful!
Preview URL: https://1de67b92.care-fe.pages.dev
Branch Preview URL: https://rewamp-allergy.care-fe.pages.dev

View logs

Copy link

cypress bot commented Jan 2, 2025

CARE    Run #4132

Run Properties:  status check passed Passed #4132  •  git commit ab1a93a6c1: Enhance AllergyQuestion component with improved UI and functionality.…
Project CARE
Branch Review rewamp-allergy
Run status status check passed Passed #4132
Run duration 01m 07s
Commit git commit ab1a93a6c1: Enhance AllergyQuestion component with improved UI and functionality.…
Committer Bodhish Thomas
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 3
View all changes introduced in this branch ↗︎

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 (4)
src/components/Questionnaire/QuestionTypes/AllergyQuestion.tsx (4)

52-58: Consider future translations for UI text.
ALLERGY_CATEGORIES is an excellent approach for standardized labels. If this component needs i18n support later, ensure these labels are localized.


106-127: Responsive rendering approach is well-structured.
The logic for switching between a grid for larger screens and a simpler stacked layout for smaller screens is good. Consider adding accessible labels or summary text for screen readers, if relevant.


201-264: Strings for category, status, and criticality.
Looks fine but remember to apply localization if needed.


314-326: Allow multi-line input for notes.
If users tend to provide longer descriptions, a textarea might be more user-friendly than a single-line input.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1f7410a and ddcfea8.

📒 Files selected for processing (1)
  • src/components/Questionnaire/QuestionTypes/AllergyQuestion.tsx (3 hunks)
🔇 Additional comments (9)
src/components/Questionnaire/QuestionTypes/AllergyQuestion.tsx (9)

3-8: Use of icons is clear and consistent.


11-17: UI imports look good.
No issues spotted with these added imports for DropdownMenu components.


31-33: Cleanly organized imports for typed interfaces.
No concerns here.


42-48: Confirm sensible defaults.
ALLERGY_INITIAL_VALUE sets a static default category, clinical_status, etc. Verify that these defaults reflect typical usage, and confirm that no data mismatch occurs when this is used downstream.


65-66: Questionnaire response casting.
Casting to AllergyIntolerance[] is legitimate, but watch out for possible runtime edge cases (e.g., if values[0].value is an unexpected type).


68-72: Duplicate allergy checks.
handleAddAllergy does not appear to guard against adding the same allergy multiple times. Consider whether deduplication is needed.


87-96: Update logic is concise.
Directly mapping and merging updates is both readable and efficient. No issues found.


128-133: Check large data performance.
ValueSetSelect might load a lengthy list of possible allergies. Ensure there's no noticeable performance degradation if the dataset is large.


302-313: Consider restricting invalid dates.
Last Occurrence might benefit from client-side validation (e.g., preventing future dates).

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 (2)
src/components/Questionnaire/QuestionTypes/AllergyQuestion.tsx (2)

56-62: Consider including a default notes property.
When creating a new allergy, if you plan to store notes, initializing a note property in ALLERGY_INITIAL_VALUE can help avoid potential undefined references.

Example diff:

 const ALLERGY_INITIAL_VALUE: Partial<AllergyIntolerance> = {
   code: { code: "", display: "", system: "" },
   clinical_status: "active",
   verification_status: "confirmed",
   category: "medication",
   criticality: "low",
+  note: "",
 };

316-330: Consider using a multi-line component for notes.
If the notes are likely to be more verbose, a multi-line text field or text area can improve the user experience over a single-line input.

Proposed snippet:

 {showNotes && (
   <TableRow>
     <TableCell colSpan={7} className="px-4 py-2">
       <Label className="text-xs text-gray-500">Notes</Label>
-      <Input
-        type="text"
-        placeholder="Add notes about the allergy..."
-        value={allergy.note || ""}
-        onChange={(e) => onUpdate?.({ note: e.target.value })}
-        disabled={disabled}
-        className="mt-0.5"
-      />
+      <textarea
+        placeholder="Add notes about the allergy..."
+        value={allergy.note || ""}
+        onChange={(e) => onUpdate?.({ note: e.target.value })}
+        disabled={disabled}
+        className="mt-0.5 h-16 w-full rounded-md border border-gray-300 p-2 resize-none"
+      />
     </TableCell>
   </TableRow>
 )}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ddcfea8 and c03c3cb.

📒 Files selected for processing (2)
  • src/components/Questionnaire/QuestionTypes/AllergyQuestion.tsx (3 hunks)
  • src/components/ui/input.tsx (1 hunks)
🔇 Additional comments (2)
src/components/Questionnaire/QuestionTypes/AllergyQuestion.tsx (2)

153-161: Modular component approach is well-structured.
The introduction of AllergyTableRow (and accompanying props) is a positive refactor that increases clarity and maintainability by separating concerns into a smaller, focused component.


86-87: Guard against potential undefined values.
Returning questionnaireResponse.values?.[0]?.value may cause runtime errors if values is empty or if values[0] is undefined. Consider adding a fallback or validating that values[0] exists before slicing into the array.

Below is a script to locate places in the codebase referencing questionnaireResponse.values and confirm that they’re safely accessed:

Comment on lines 16 to 18
onFocus={(e) => {
e.target.showPicker();
}}
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Remove unconditional showPicker() call from input component

The current implementation unconditionally calls showPicker() on focus for all input types, which is incorrect. Based on the codebase analysis:

  1. The showPicker() method is only used with:
    • type="date" in CreateUserForm and questionnaire components
    • type="time" in ScheduleTemplateForm and DateTimeQuestion components

The current implementation will cause errors for other input types like text, email, password, etc., which are also used throughout the application.

Fix suggestion:

onFocus={(e) => {
  if (type === 'date' || type === 'time') {
    e.target.showPicker();
  }
}}
🔗 Analysis chain

Ensure compatibility and intended usage of showPicker().
The showPicker() method is only supported by certain input types (e.g., date, time, datetime-local, etc.) and might not be fully supported in all browsers. Consider validating the type property or providing a graceful fallback for browsers that do not implement showPicker().

Here is a script to check the usage of this component and inspect input types passed:


Let me analyze the usage of the Input component and verify the concern about showPicker().


Let me try a different approach to check the input types.


Let me check the specific component implementation to understand how the showPicker() is being used.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Searching for all usage of `Input` across the codebase, displaying context.
rg -A 5 "Input[ (]"

Length of output: 40980


Script:

#!/bin/bash
# Let's check the input component definition and its type prop usage
ast-grep --pattern 'type={$_}'

Length of output: 32


Script:

#!/bin/bash
# Let's check where type="date" or type="time" is used with Input component
rg -B 2 -A 2 'type="(date|time)"'

Length of output: 4509


Script:

#!/bin/bash
# Let's examine the input component implementation
cat src/components/ui/input.tsx

Length of output: 978

@bodhish bodhish merged commit 8ce5aba into develop Jan 2, 2025
19 checks passed
@bodhish bodhish deleted the rewamp-allergy branch January 2, 2025 14:03
Copy link

github-actions bot commented Jan 2, 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

sentry-io bot commented Jan 10, 2025

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ NotAllowedError: Failed to execute 'showPicker' on 'HTMLInputElement': HTMLInputElement::showPicker() requires a u... <object>.onFocus(src/components/ui/input) View Issue

Did you find this useful? React with a 👍 or 👎

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.

2 participants