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

Prevent Unnecessary Update Request in Facilities Section #8956

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

Conversation

kihan2518B
Copy link

@kihan2518B kihan2518B commented Oct 28, 2024

Proposed Changes

image

  • Added isDirty state to the Form component
  • managing button disable state by isDirty state in Form component.
  • Utilizing Form component in BedCapacity and StaffCapacity .

@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

@kihan2518B kihan2518B requested a review from a team as a code owner October 28, 2024 18:06
Copy link

netlify bot commented Oct 28, 2024

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 5151974
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/672133886c68e80008e0520f
😎 Deploy Preview https://deploy-preview-8956--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.

src/components/Facility/BedCapacity.tsx Show resolved Hide resolved
src/components/Facility/BedCapacity.tsx Outdated Show resolved Hide resolved
src/components/Facility/StaffCapacity.tsx Outdated Show resolved Hide resolved
src/components/Facility/StaffCapacity.tsx Show resolved Hide resolved
src/components/Form/Form.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove package-lock from commit.

@Jacobjeevan
Copy link
Contributor

Jacobjeevan commented Oct 29, 2024

There's already another PR for the infinite load issues for Beds. In the future, make sure to get issue assigned or mention in the original thread before starting to work on an issue.

@kihan2518B
Copy link
Author

I had made those necessary changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

So, this will just remove the file from develop branch. You can make use to checkout command to check package-lock file from develop and then commit that.

data-testid="submit-button"
type="submit"
disabled={disabled || !isDirty}
label={"Save & Add More"}
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's pass in the label as showSaveAndAddMoreBtn prop. Refer to the original files on how we are updating this label, i.e. 'Save and Add More' vs 'Save Bed/Staff Capacity'.

Copy link
Author

Choose a reason for hiding this comment

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

ok got it and made those changes.

if (btnType == "Save and Exit") handleClose();
if (
btnType !== "save-and-add-more" ||
bedTypes.length === BED_TYPES.length
Copy link
Contributor

Choose a reason for hiding this comment

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

The latter comparison wouldn't work as bedTypes length will always be the same.

Here, you want to bring updatedBedTypes out of scope earlier*, calculate the number of beds that are disabled and then do a check (if it exists + if it equals to BED_TYPES length).

Something like:

const disabledBedTypesLength = updatedBedTypes?.filter((item) => item.disabled).length;

*In this case, we can't use bedTypes right away since we are updating it (state may or may not be updated in time).

Copy link
Author

Choose a reason for hiding this comment

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

Got it.

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.

Add package-lock back in (checked out from develop branch).

@@ -115,11 +135,21 @@ const Form = <T extends FormDetails>({
onClick={props.onCancel}
label={props.cancelLabel ?? "Cancel"}
/>
{props.showSaveAndAddMoreBtn && (
Copy link
Contributor

@Jacobjeevan Jacobjeevan Oct 29, 2024

Choose a reason for hiding this comment

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

This works, but it's a bit confusing with the button text and labeling, since regular submitBtn seems to be using showSaveAndAddMoreBtn as label.

We could change it so that buttonText corresponds to Save/Update Bed/Staff Capacity and showSaveAndAddMoreBtn passes in Save & Add More.

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