-
Notifications
You must be signed in to change notification settings - Fork 29
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
fix(app-project): data-fetching for assigned workflow level #6219
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
084a0de
to
ca9cac5
Compare
f0edbb1
to
06c5461
Compare
06c5461
to
015ff9c
Compare
015ff9c
to
6c6a17b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something isn't quite right with displaying locked vs unlocked in this PR. When I'm signed-in with the zootester1
account at https://www.zooniverse.org/projects/zooniverse/gravity-spy I correctly see six workflows unlocked. When I run app-project on this branch locally with yarn start
at https://local.zooniverse.org:3000/projects/zooniverse/gravity-spy, I only see one workflow unlocked.
See details for expected behavior when a user account is assigned a workflow id and that workflow is inactive/complete: #6198
6c6a17b
to
e72fdee
Compare
@goplayoutside3 that's my fault. I made the data fetching options too restrictive. Switching to |
I've added a story for the case where the assigned workflow is missing from the workflows list, using MSW to mock the Panoptes API. It should assign you to level 3, and unlock levels 1 and 2. EDIT: adding |
1a6abb1
to
472cad3
Compare
If you’d like to check out the storybook with API mocks, I’ve pushed those changes here: I've opened #6406 for that branch. It adds a story to test the case where the assigned workflow is complete. The changes here shouldn't break that. |
6930291
to
241d9a2
Compare
This is looking much better. When signed in with various accounts, I see the expected unlocked workflows on Gravity Spy, and when signed out I see only the first level unlocked. However, I need to double check how truly immutable our workflow levels are. Implementing |
You can pass the same options into By default, the immutable hook doesn’t refetch when you switch focus back to a tab, when you wake the computer from sleep, or when the fetched resource becomes stale, but those are all configurable. |
241d9a2
to
ea5b029
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.
ea5b029
to
f22b905
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reverted to useSWR
instead of useSWRImmutable
. Workflow level
can be changed by project teams at any point, so I made this change to avoid future confusion.
In that case, you'll want to set That was my mistake in the original version of this PR. |
Locked and unlocked levels are displayed as expected after this PR. The SWR options mentioned only apply to cases where the If you'd like to rebase #6406 and change any SWR options in |
Ok. The options now are set to the options for |
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.Adds Mock Service Worker, for mocking API requests in stories.I've moved the story for this into #6406. It sets up a test case where the assigned workflow, level 3, is complete and must be fetched from the Panoptes API.*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