-
Notifications
You must be signed in to change notification settings - Fork 30
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(app-project): data-fetching for assigned workflow level #6219
base: master
Are you sure you want to change the base?
Conversation
0fbf132
to
d9b87f8
Compare
d9b87f8
to
c6307c6
Compare
#6201 broke these tests for assigned workflow level in front-end-monorepo/packages/app-project/src/screens/ClassifyPage/ClassifyPageContainer.spec.js Lines 210 to 297 in 22707c9
|
c6307c6
to
f884247
Compare
f884247
to
77d09b6
Compare
@eatyourgreens Re:
Yes they can change levels. The project team has full control over workflow level configuration. Does that fact change any code in this PR? |
I shouldn't imagine so, but you can adjust the revalidation options if the hook is constantly requesting the same level from Panoptes, for a given workflow. https://swr.vercel.app/docs/revalidation You can also turn off revalidation completely for immutable resources. https://swr.vercel.app/docs/revalidation#disable-automatic-revalidations |
Right now, in production, the Classify page requests the workflow config from Panoptes on every visit to the page, even if it already has it. Workflow select buttons then repeat the request, even though the app already has the workflow config for the missing workflow. EDIT: in Strict Mode, I see the That can be improved by checking if the workflow config is already present in page props, before making a request to Panoptes, and by caching the API response for reuse. |
front-end-monorepo/packages/app-project/src/hooks/useAssignedLevel.js Lines 20 to 23 in 6fc2c84
If the assigned workflow ID in my user preferences is an inactive workflow, then fetchedWorkflow will be undefined here and assignedWorkflowLevel will be set to NaN . I've updated this PR to catch that case and return 1.
|
56a2c14
to
2ae8c54
Compare
2ae8c54
to
084a0de
Compare
Fix missing dependency errors in the `useAssignedLevel` hook by using `useSWR` to fetch and cache the assigned workflow level. SWR also adds revalidation for cases where I might classify in the same tab over several days or weeks. Also fixes the workflow assignment tests in `ClassifyPageContainer` so that they test against the correct levels.
084a0de
to
ca9cac5
Compare
Fix missing dependency errors in the
useAssignedLevel
hook by usinguseSWR
to fetch and cache the assigned workflow level. SWR also adds revalidation of the Panoptes API request for cases where I might classify in the same tab over several days or weeks.*Adds conditional data-fetching, so that we only fetch a workflow configuration if we don’t already have it in the
workflows
page prop.Also fixes the workflow assignment tests in
ClassifyPageContainer
so that they test against the correct levels, and restores skipped tests to double check that nothing is broken.*do workflow levels change over time? If not, the fetched value can be cached indefinitely.
Please request review from
@zooniverse/frontend
team or an individual member of that team.Package
Linked Issue and/or Talk Post
useAssignedLevel
is used more than once in the page or the page is run in React Strict Mode.How to Review
Testing for this should be the same as #6201.
useAssignedLevel
should only call the API once for a given workflow, even if it’s invoked from multiple components.If you load Gravity Spy with the workflow choice menu, you can check that the Classify page only makes one API request for any missing workflows, even though
useAssignedLevel
is used twice on the page. The assigned level should also be cached in the client-side project app for the duration of your session.https://local.zooniverse.org:3000/projects/zooniverse/gravity-spy/classify?env=production
Checklist
PR Creator - Please cater the checklist to fit the review needed for your code changes.
PR Reviewer - Use the checklist during your review. Each point should be checkmarked or discussed before PR approval.
General
yarn panic && yarn bootstrap
ordocker-compose up --build
and FEM works as expectedGeneral UX
Example Staging Project: i-fancy-cats
Bug Fix