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

feat(app-project): remember current workflow in a same-site session cookie #6216

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

eatyourgreens
Copy link
Contributor

@eatyourgreens eatyourgreens commented Aug 17, 2024

  • Store your selected workflow in a workflow_id session cookie on the zooniverse.org domain, scoped to the current project.
  • Set that cookie when you choose a workflow with the WorkflowSelectButton component, or when you level up by following a workflow link in Gravity Spy.
  • Read the cookie in the Project model, and store it as project.selectedWorkflow. Return the stored value from project.defaultWorkflow.
  • Use project.defaultWorkflow on the Classify page, if there's no workflow in the URL.
  • Use props.workflowID on the Classify page, if there is a workflow in the URL.
  • Add the project context to tests.
Cookies for local.zooniverse.org in Firefox, showing 3 workflow_id cookies for 3 projects.

Please request review from @zooniverse/frontend team or an individual member of that team.

Package

  • app-project

Linked Issue and/or Talk Post

How to Review

On a project with multiple workflows, clicking a link to choose a workflow should now set a project session cookie that remembers the workflow ID.

  • when you leave the project to go to another Zooniverse page, and come back to /classify, it should use the cookie to load a workflow, then update the window location bar to show that workflow.
  • when you leave the project and come back to /classify/workflow/[workflowID], it should respect the workflow in the URL.
  • when you use client-side navigation within the project app, your selected workflow should be remembered when you go back to Classify.
  • when you enter the project from outside the Zooniverse (eg. a link in an email), it should ignore the same-site cookie.

https://local.zooniverse.org:3000/projects/abbsta/south-coast-threatened-fauna-recovery-project?env=production
The big change here is that the Classify link in the project navigation should now reflect your selected workflow (either 21967 or 21968.) That workflow should also be remembered in a session cookie, when you leave the React app and return to https://local.zooniverse.org:3000/projects/abbsta/south-coast-threatened-fauna-recovery-project/classify?env=production

If you shut down the browser, then 'restore previous session', the browser will probably restore the session cookie too. Otherwise, ending your browser session should clear session cookies for all projects, and you'll be asked to choose a workflow when you next classify on a project.

I’ve tested with Gravity Spy and South Coast Threatened Fauna, but any project with more than one workflow should work.

Next.js turns off client-side navigation in development mode, so you’ll need to run the app in production mode to test the project navigation menu.

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

  • Tests are passing locally and on Github
  • Documentation is up to date and changelog has been updated if appropriate
  • You can yarn panic && yarn bootstrap or docker-compose up --build and FEM works as expected
  • FEM works in all major desktop browsers: Firefox, Chrome, Edge, Safari (Use Browserstack account as needed)
  • FEM works in a mobile browser

General UX

Example Staging Project: i-fancy-cats

  • All pages of a FEM project load: Home Page, Classify Page, and About Pages
  • Can submit a classification
  • Can sign-in and sign-out
  • The component is accessible

New Feature

  • The PR creator has listed user actions to use when testing the new feature
  • Unit tests are included for the new feature
  • A storybook story has been created or updated
    • Example of SlideTutorial component with docgen comments, and its story

@coveralls
Copy link

coveralls commented Aug 17, 2024

Coverage Status

coverage: 78.791% (-0.04%) from 78.83%
when pulling af2eedf on eatyourgreens:project-selected-workflow
into 9dc3dc3 on zooniverse:master.

@eatyourgreens eatyourgreens marked this pull request as ready for review August 17, 2024 09:22
@eatyourgreens eatyourgreens force-pushed the project-selected-workflow branch 7 times, most recently from 8f6c365 to 32b8a27 Compare August 17, 2024 17:06
const activeWorkflows = self.links['active_workflows']
let singleActiveWorkflow
if (activeWorkflows.length === 1) {
[singleActiveWorkflow] = self.links['active_workflows']
}
return singleActiveWorkflow
return singleActiveWorkflow || workflowFromCookie || self.selectedWorkflow
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm probably missing something obvious, but self.selectedWorkflow here is sometimes empty, after setting the workflow_id cookie.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed by making sure that selectedWorkflow is added to incoming project snapshots.

Copy link
Contributor Author

@eatyourgreens eatyourgreens Aug 19, 2024

Choose a reason for hiding this comment

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

Client-side routing in Next.js applies a new project snapshot to the store, from page props, on each route change. The incoming snapshot overwrites any local changes you’ve made to the stored project.

@eatyourgreens eatyourgreens force-pushed the project-selected-workflow branch 5 times, most recently from 7ebaf77 to a85f46d Compare August 18, 2024 07:07
@eatyourgreens
Copy link
Contributor Author

Here's a short video of me navigating South Coast Threatened Fauna with these changes. Note that when I go to Talk, then /classify, my selected workflow is restored.

Screen.Recording.2024-08-18.at.08.58.54.mov

@eatyourgreens eatyourgreens force-pushed the project-selected-workflow branch 3 times, most recently from 348092d to 8e52500 Compare August 20, 2024 08:23
@goplayoutside3
Copy link
Contributor

Thank you @eatyourgreens for your Issue and linked PR (also tagging @yshish as an fyi). As a heads up, the frontend team has a large backlog of work toward new features and code maintenance scheduled for the rest of the year. Please feel free to keep this Issue open / updated, but PR review will happen a few months from now. Apologies for the slow process.

@eatyourgreens eatyourgreens force-pushed the project-selected-workflow branch 2 times, most recently from eee2dea to f465265 Compare August 28, 2024 08:40
setSelectedWorkflow(workflowId) {
if (typeof document !== 'undefined') {
self.selectedWorkflow = workflowId
document.cookie = `workflow_id=${workflowId}; path=/projects/${self.slug}; domain=zooniverse.org; SameSite=Strict`
Copy link
Contributor Author

@eatyourgreens eatyourgreens Aug 29, 2024

Choose a reason for hiding this comment

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

SameSite=Strict means the cookie is only read while navigating the zooniverse.org domain. For example, it will work when going to Talk and back but it will be ignored if I enter the site from a link in an email, or a link on an external site. In those latter cases, I’ll be asked to choose a workflow, unless one is specified in the link.

That should protect against a case where a project team mails out a new link to their project, but recipients might have a stale workflow stored on their device.

@eatyourgreens eatyourgreens changed the title feat(app-project): remember current workflow in a cookie feat(app-project): remember current workflow in a same-site session cookie Aug 30, 2024
@goplayoutside3 goplayoutside3 self-assigned this Sep 5, 2024
- Store your selected workflow in a `workflow_id` session cookie on the `zooniverse.org` domain, scoped to the current project.
- Set that cookie when you choose a workflow with the `WorkflowSelectButton` component.
- Read the cookie in the Project model, and store it as `project.selectedWorkflow`. Fall back to `project.defaultWorkflow` for backwards compatibility.
- Use `project.defaultWorkflow` on the Classify page, if there's no workflow in the URL.
- Use `props.workflowID` on the Classify page, if there is a workflow in the URL.
- Add the project context to tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Client-side navigation in the project app doesn't remember my selected workflow
3 participants