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 usePartFields hook #7868

Merged
merged 1 commit into from
Aug 14, 2024

Conversation

SchrodingersGat
Copy link
Member

No description provided.

@SchrodingersGat SchrodingersGat added bug Identifies a bug which needs to be addressed user interface User Interface Related to the frontend / User Interface labels Aug 14, 2024
@SchrodingersGat SchrodingersGat added this to the 0.17.0 milestone Aug 14, 2024
Copy link

netlify bot commented Aug 14, 2024

Deploy Preview for inventree-web-pui-preview ready!

Name Link
🔨 Latest commit 027c6ae
🔍 Latest deploy log https://app.netlify.com/sites/inventree-web-pui-preview/deploys/66bbfb0a74206000089b5b06
😎 Deploy Preview https://deploy-preview-7868--inventree-web-pui-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 100 (no change from production)
Accessibility: 86 (no change from production)
Best Practices: 92 (no change from production)
SEO: 70 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@SchrodingersGat SchrodingersGat merged commit 2244f5f into inventree:master Aug 14, 2024
25 checks passed
@SchrodingersGat SchrodingersGat deleted the part-fields-fix branch August 14, 2024 00:49
@@ -13,6 +13,8 @@ export function usePartFields({
}: {
create?: boolean;
}): ApiFormFieldSet {
const settings = useGlobalSettingsState.getState();
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure, that this works?

What was your initial issue, that you tried to solve with this? That the useMemo was not retriggered when the global state updated?

Isn't the Zustand syntax something like this in a reactive way then:

Suggested change
const settings = useGlobalSettingsState.getState();
const settings = useGlobalSettingsState();

Copy link
Member Author

Choose a reason for hiding this comment

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

The initial issue was that the call to settings was buried inside the lower useMemo call which was only updated when create changed. So, AFAIK, settings value was never being re-evaluated

Copy link
Contributor

Choose a reason for hiding this comment

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

No, it should be reevaluated, on the initial render of the component and if create would have changed.

Using .getState is used to get the state outside of the component. E.g. in a hook. Ref: https://github.com/pmndrs/zustand?tab=readme-ov-file#readingwriting-state-and-reacting-to-changes-outside-of-components

If you want to subscribe to the state and bind it to a react state, just call the store, the store is a hook. But I'm not sure if this whole change is really necessary.

Copy link

codecov bot commented Nov 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.36%. Comparing base (a37d218) to head (027c6ae).
Report is 320 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7868      +/-   ##
==========================================
- Coverage   83.48%   83.36%   -0.12%     
==========================================
  Files        1128     1128              
  Lines       50264    50264              
  Branches     1733     1733              
==========================================
- Hits        41962    41904      -58     
- Misses       7860     7929      +69     
+ Partials      442      431      -11     
Flag Coverage Δ
pui 64.32% <100.00%> (-0.72%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Identifies a bug which needs to be addressed User Interface Related to the frontend / User Interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants