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 navigation behavior on enterprise settings panel tabs #11799

Conversation

murjax
Copy link
Contributor

@murjax murjax commented Nov 10, 2023

What? Why?

Panel navigation through back and forward buttons isn't working on enterprise settings page. The tab selection changes, but the content does not change.

What should we test?

  1. As an admin, go to an enterprise edit settings page (admin/enterprises/[ENTERPRISE-SLUG]/edit#/primary_details).
  2. Navigate with the left panel, and see content on the right is changing
  3. Using the browser's back and forward buttons observe the url path and the content both change appropriately.

Other: Make changes to form fields. Back/Forward navigation should show the "unsaved changes" alert.

Screencast.from.11-10-2023.01.13.42.PM.webm

Release notes

Changelog Category (reviewers may add a label for the release notes):

  • User facing changes
  • API changes (V0, V1, DFC or Webhook)
  • Technical changes only
  • Feature toggled

The title of the pull request will be included in the release notes.

Dependencies

Documentation updates

@murjax murjax marked this pull request as ready for review November 10, 2023 18:53
Copy link
Member

@mkllnk mkllnk left a comment

Choose a reason for hiding this comment

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

Nice one. Thank you!

@@ -37,6 +37,16 @@ export default class extends Controller {
window.addEventListener("tabs-and-panels:click", (event) => {
this.simulateClick(event.detail.tab, event.detail.panel);
});

window.addEventListener("popstate", (event) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

TIL about popstate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Worth noting that this doesn't fire only on user navigation actions, but also any programmatic changes to history entries, such as history.pushState(). That's why I have to compare the panels to make sure we're responding to a new tab change. Other than that, popstate is a really useful event for solving this!

Copy link
Collaborator

@rioug rioug left a comment

Choose a reason for hiding this comment

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

Nice one 👍

@filipefurtad0 filipefurtad0 self-assigned this Nov 16, 2023
@filipefurtad0 filipefurtad0 added the pr-staged-uk staging.openfoodnetwork.org.uk label Nov 16, 2023
@filipefurtad0
Copy link
Contributor

Hey @murjax ,

This is looking great. I've tried to sum it up in a video, as a quick demonstration: the above section displays a staging server in which the PR was not staged; below, we see a section from a server in which this PR was staged:

https://www.loom.com/share/1e683d593f0b4087a9d04a6706861929?sid=ed2122ae-fc6c-4482-9ab1-adbb91fc61d8

This makes it possible to navigate back to sections which were changed, but not saved. Thanks!
Merging.

@filipefurtad0 filipefurtad0 merged commit 37436aa into openfoodfoundation:master Nov 16, 2023
52 checks passed
@filipefurtad0 filipefurtad0 removed the pr-staged-uk staging.openfoodnetwork.org.uk label Nov 16, 2023
filipefurtad0 added a commit to filipefurtad0/openfoodnetwork that referenced this pull request Dec 22, 2023
… spec where a modal does not need acceptance

Tests forward navigation
mkllnk added a commit that referenced this pull request Jan 3, 2024
…igation

Moves test introduced by #11799 to avoid non-explicit modal acceptance
fleblond07 pushed a commit to fleblond07/openfoodnetwork that referenced this pull request Mar 13, 2024
… spec where a modal does not need acceptance

Tests forward navigation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Enterprise settings panels don't work with back and forward browser's buttons
4 participants