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

Support For BULK beds creation in location #10815

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from

Conversation

AdityaJ2305
Copy link
Contributor

@AdityaJ2305 AdityaJ2305 commented Feb 25, 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
    • Enhanced translations with clear messages for bed count and descriptive labels.
    • Updated the location form to include a new optional field for specifying the number of beds (defaulting to 1).
    • Enabled batch creation of locations based on the specified bed count, with notifications reflecting the created number.
    • Improved localization support for error messages in the form.

@AdityaJ2305 AdityaJ2305 requested a review from a team as a code owner February 25, 2025 18:37
Copy link
Contributor

coderabbitai bot commented Feb 25, 2025

Walkthrough

The pull request introduces new localization keys in the en.json file and updates the LocationForm component. Three new entries provide validation error messages and a label related to bed counts. In the form component, a new beds_count field is added with a minimum value validation, a default value set to 1, and the submission logic enhanced to support batch creation when applicable. Error and success messages have been updated to utilize localization functions.

Changes

File Change Summary
public/locale/en.json Added three new keys: "bed_count_validation_error": "Number of beds must be greater than 0", "beds_creation_failed": "Failed to create beds", and "total_number_of_beds": "Total number of beds".
src/pages/Facility/settings/locations/LocationForm.tsx Introduced new beds_count field with minimum value validation, updated defaultValues, modified onSubmit to handle batch creation based on beds_count, and updated localized error and success messages.

Possibly Related PRs

Suggested Labels

needs testing, needs review

Suggested Reviewers

  • rithviknishad
  • Jacobjeevan

Poem

I'm a bunny on the run,
Hopping through code that shines like fun.
With keys and fields so fresh and bright,
My little paws click through day and night.
In this garden of code, changes bloom true—
Celebrating each commit with a joyful "woo!"
🐇🥕

Tip

CodeRabbit's docstrings feature is now available as part of our Pro Plan! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


📜 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 bbf4206 and 8e9b796.

📒 Files selected for processing (2)
  • public/locale/en.json (2 hunks)
  • src/pages/Facility/settings/locations/LocationForm.tsx (8 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • public/locale/en.json
⏰ 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: Test
  • GitHub Check: cypress-run (1)
🔇 Additional comments (4)
src/pages/Facility/settings/locations/LocationForm.tsx (4)

95-96: Good extraction of reusable condition.

Creating the isEditMode variable makes the code more readable and helps avoid repeatedly checking !!location?.id throughout the component.


136-149: Well-implemented batch mutation.

The batch submission mutation is properly set up with appropriate success and error handlers. The success handler displays a dynamic message based on the count of created beds, and the error handler shows a localized message.


160-177: Effective batch creation implementation.

The batch creation logic is well-structured and handles the conditional flow appropriately. It creates multiple beds with sequentially numbered names based on the user input.

One suggestion to consider: adding a reasonable upper limit to the number of beds that can be created at once to prevent potential performance issues with very large batch requests.


268-284: Conditional rendering of beds_count field is appropriate.

The beds_count field is only shown when creating beds (form type is "bd") and not in edit mode, which is the correct behavior.

However, it would be helpful to show the user a preview of the bed names that will be created based on their input. Consider adding a preview section that shows a few examples (or all if the count is small) of the generated bed names.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.
  • @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 Feb 25, 2025

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 8e9b796
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/67bedaea785f120008f6ee62
😎 Deploy Preview https://deploy-preview-10815.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.

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/pages/Facility/settings/locations/LocationForm.tsx (2)

136-149: Implemented batch submission mutation.

The batch submission mutation is added to handle creating multiple beds at once. However, there is a commented-out error handler that should be either implemented or removed.

Consider either implementing the error handling by uncommenting and updating the error toast:

- // onError: () => {
- //   toast.error(t("submission_failed"));
- // },
+ onError: () => {
+   toast.error(t("bed_creation_failed"));
+ },

Or remove the commented-out code if it's not needed.


152-177: Implemented bulk bed creation functionality.

This implementation allows creating multiple beds at once when beds_count > 1.

However, there's an inconsistency in the mode parameter between single and batch submissions.

In line 180, the single submission uses mode: "kind", but in the batch submission body, it uses mode: "instance". Consider using the same mode value for consistency:

const data: LocationWrite = {
  ...values,
- mode: "instance",
+ mode: "kind",
  description: values.description || "",
  organizations: values.organizations,
  parent: values.parent || undefined,
};
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a51d39c and ae84991.

📒 Files selected for processing (2)
  • public/locale/en.json (2 hunks)
  • src/pages/Facility/settings/locations/LocationForm.tsx (9 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Redirect rules - care-ohc
  • GitHub Check: Header rules - care-ohc
  • GitHub Check: Pages changed - care-ohc
  • GitHub Check: Test
  • GitHub Check: cypress-run (1)
  • GitHub Check: OSSAR-Scan
🔇 Additional comments (10)
public/locale/en.json (2)

471-471: Localization key added for bed count validation.

This localization key provides an error message for validation when the number of beds is not greater than zero, supporting the new bulk bed creation feature.


2297-2297: Localization key added for bed count field label.

This localization key provides the label text for the total number of beds field, supporting the new bulk bed creation feature.

src/pages/Facility/settings/locations/LocationForm.tsx (8)

3-3: Added direct i18next import for translations.

Good addition of the direct import of the translation function, which is used for schema validation messages.


39-42: Added batch operation type imports.

These imports support the new bulk beds creation functionality by providing the types needed for batch requests.


45-45: Updated validation message to use translation function.

Good improvement for internationalization by using the translation function for the field validation error message.


51-54: Added beds_count field to form schema.

The beds_count field is properly defined with appropriate validation using the translation function for the error message.


73-73: Added default value for beds_count.

Setting a default value of 1 for beds_count is appropriate and ensures the form has a valid initial state.


95-96: Added isEditMode flag for better code readability.

Good addition of this variable which makes the code more readable and avoids repeating the condition checking throughout the component.


231-244: Added real-time preview of generated bed names.

Great UX enhancement! This preview shows users exactly what bed names will be created based on their input, helping them understand the batch creation process.


361-364: Updated button text with translations.

Good improvement for internationalization by using the translation function for the action button, with different text based on create/update mode.

@AdityaJ2305
Copy link
Contributor Author

Screen.Recording.2025-02-26.at.12.19.23.AM.mov

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: 2

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ae84991 and bbf4206.

📒 Files selected for processing (2)
  • public/locale/en.json (2 hunks)
  • src/pages/Facility/settings/locations/LocationForm.tsx (9 hunks)
🔇 Additional comments (8)
public/locale/en.json (3)

471-471: LGTM: Added validation error message for bed count.

The new error message is clear and descriptive, ensuring users understand they must enter a positive number for bed count.


474-474: LGTM: Added error message for bed creation failure.

This provides appropriate feedback when bulk bed creation fails.


2298-2298: LGTM: Added label for total number of beds field.

This label clearly describes the purpose of the beds_count field in the form.

src/pages/Facility/settings/locations/LocationForm.tsx (5)

152-177: LGTM: Added bulk bed creation functionality.

The implementation of bulk bed creation correctly:

  1. Checks if the form type is for beds ("bd")
  2. Verifies it's not in edit mode
  3. Ensures beds_count is greater than 1
  4. Builds a batch request with multiple locations

This will significantly improve workflow efficiency for users who need to add multiple beds at once.


289-306: LGTM: Added beds_count field to the form.

The implementation correctly:

  1. Shows the field only when creating beds (form type is "bd")
  2. Hides it in edit mode
  3. Uses proper form control and validation
  4. Sets appropriate minimum value

95-96: LGTM: Added clear isEditMode flag.

Using a dedicated variable for checking edit mode improves code readability and maintainability throughout the component.


136-149: LGTM: Added batch submission mutation.

The implementation properly handles:

  1. Success case with appropriate toast message
  2. Error case with user-friendly error message
  3. Query invalidation to refresh the data

180-180:

✅ Verification successful

Verify change in location mode from "instance" to "kind".

You've changed the mode from "instance" (in the bulk creation) to "kind" for the regular submission. Please verify this is intentional and won't affect functionality.


🏁 Script executed:

#!/bin/bash
# Search for other usages of mode to understand the expected values
echo "Searching for mode usage in location-related files..."
rg -A 2 -B 2 "mode.*['\"]kind['\"]|mode.*['\"]instance['\"]" --type ts

Length of output: 2502


Confirmed: The change to use mode "kind" for regular submission is intentional.

  • The code in src/pages/Facility/settings/locations/LocationForm.tsx now uses mode "instance" for bulk creation and mode "kind" for regular submissions.
  • The check in src/pages/Facility/settings/locations/LocationView.tsx verifies that locations display correctly when location.mode === "kind".
  • Components like <LocationSearch> already support both "kind" and "instance" as valid values.

@AdityaJ2305
Copy link
Contributor Author

Screen.Recording.2025-02-26.at.2.40.39.PM.mov

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.

Support for bulk creating beds inside a location
2 participants