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: Bed capacity pop up errors #9123

Conversation

AdityaJ2305
Copy link
Contributor

@AdityaJ2305 AdityaJ2305 commented Nov 15, 2024

Proposed Changes

@ohcnetwork/care-fe-code-reviewers
@nihal467

ScreenRecording

Screen.Recording.2024-11-15.at.10.28.55.AM.1.mov

Merge Checklist

  • Prep screenshot or demo video for changelog entry, and attach it to issue.
  • Request for Peer Reviews

Summary by CodeRabbit

  • New Features

    • Simplified rendering logic for the "Save Bed Capacity" and "Save" buttons, improving user experience.
  • Bug Fixes

    • Enhanced loading state management for better UI responsiveness when options are disabled.

@AdityaJ2305 AdityaJ2305 requested a review from a team as a code owner November 15, 2024 05:06
Copy link
Contributor

coderabbitai bot commented Nov 15, 2024

Walkthrough

The changes in the BedCapacity component involve restructuring the conditional rendering logic for the submit buttons and adjusting the loading state management. The "Save Bed Capacity" button is now always displayed when the header is "Add Bed Capacity," while the "Save" button is conditionally shown based on the isLastOptionType. Additionally, the loading state is managed more accurately by moving the setIsLoading(false) call to immediately follow the clearing of bedTypes. The validation logic remains unchanged.

Changes

File Change Summary
src/components/Facility/BedCapacity.tsx Restructured button rendering logic; adjusted loading state management; preserved validation logic.

Assessment against linked issues

Objective Addressed Explanation
Modify pop-up behavior when bed types are exhausted (#9121) The changes do not address the pop-up closing issue after saving.
Ensure proper loading state when no bed types are available (#9121) It is unclear if the loading state issue is fully resolved.

Possibly related PRs

Suggested labels

needs review, tested, urgent

Suggested reviewers

  • Jacobjeevan
  • rithviknishad

Poem

In the land of beds where options play,
A button now shines bright as day.
With loading states that dance and twirl,
Our pop-up's charm begins to unfurl.
So hop along, let changes be,
For every bed's a joy, you see! 🐰✨


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 15, 2024

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 02ac927
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/673c3647621bec000852c575
😎 Deploy Preview https://deploy-preview-9123--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 (1)
src/components/Facility/BedCapacity.tsx (1)

289-295: Consider UX improvements for better user guidance

While the current changes fix the immediate issues, consider these improvements to fully meet the PR objectives:

  1. Add a tooltip to explain why the "Add Bed" button is disabled when no options are available
  2. Consider combining the two save buttons to reduce UI complexity

Here's a suggested implementation:

- {headerText === "Add Bed Capacity" && (
-   <Submit
-     id="bed-capacity-save-and-exit"
-     onClick={(e) => handleSubmit(e, "Save and Exit")}
-     label="Save Bed Capacity"
-   />
- )}
- {!isLastOptionType && (
-   <Submit
-     id="bed-capacity-save"
-     onClick={(e) => handleSubmit(e)}
-     label={buttonText}
-   />
- )}
+ {headerText === "Add Bed Capacity" ? (
+   <Submit
+     id="bed-capacity-save"
+     onClick={(e) => handleSubmit(e, isLastOptionType ? "Save and Exit" : undefined)}
+     label={buttonText}
+     title={bedTypes.length === 0 ? "All bed types have been added" : undefined}
+     disabled={bedTypes.length === 0}
+   />
+ ) : (
+   <Submit
+     id="bed-capacity-save"
+     onClick={(e) => handleSubmit(e)}
+     label={buttonText}
+   />
+ )}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between da5d576 and 75d8131.

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

80-81: LGTM: Loading state fix addresses infinite loading issue

The immediate clearing of loading state after setting empty bed types correctly fixes the infinite loading bug that occurred when all bed types were already added.


282-288: LGTM: Button rendering fix addresses pop-up closing issue

The "Save Bed Capacity" button is now correctly shown when adding bed capacity, ensuring users can always save and close the pop-up.


80-81: Verify edge cases in the updated flow

Please ensure these edge cases are covered:

  1. Race conditions: Multiple rapid clicks on save buttons during loading state
  2. Form validation: The min attribute on number inputs might not prevent all negative number scenarios

Also applies to: 282-295

✅ Verification successful

Based on the shell script results, I can now provide a final response:

Edge cases are properly handled in the current implementation

  1. Race conditions during loading state:
  • The code properly manages loading state with setIsLoading(false) in both success and error cases
  • Loading state updates are properly sequenced with state resets (setBedTypes([]))
  1. Form validation for negative numbers:
  • All number inputs have proper validation with min={0} or appropriate minimum values
  • The bed capacity form specifically enforces:
    • Minimum total capacity of 1 with min={1}
    • Current occupancy between 0 and total capacity with min={0} max={state.form.totalCapacity}
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for loading state management patterns
rg "setIsLoading" -A 5

# Search for number input validation
rg "type=\"number\"" -A 5

Length of output: 78082

@nihal467
Copy link
Member

LGTM @khavinshankar review and merge them , non related test failure

@khavinshankar khavinshankar merged commit 570ed1e into ohcnetwork:develop Nov 19, 2024
16 checks passed
Copy link

@AdityaJ2305 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Modify the bed capacity pop-up when the dropdown options are going to exhaust
3 participants