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

Navigator: simplify backwards navigation APIs #63317

Merged
merged 20 commits into from
Aug 16, 2024
Merged

Conversation

ciampo
Copy link
Contributor

@ciampo ciampo commented Jul 9, 2024

What?

As discussed in #60927 , this PR introduces a few simplifications (and deprecations) to the Navigator component.

Why?

We're simplifying the component's API ahead of promoting to stable.

How?

  • marked NavigatorToParentButton, NavigatorBackButton.goToParent and useNavigator().goToParent() as deprecated
  • updated docs
  • useNavigator().goBack() and NavigatorBackButton will navigate to the parent screen, instead of navigating to whatever screen was visited prior to the current one (according to the expected URL-based path assigned to screens)

Questions

  • should we hard deprecate goToParent and NavigatorToParentButton ?
  • does the replace option make any sense with "go to parent"-only backwards navigation?

Next steps

  • Rename using agreed compound component notation
  • Export unprefixed, stable version
  • Deprecate prefixed version

Testing Instructions

Navigator should continue to behave as on trunk in Storybook and in the block editor

@ciampo ciampo requested a review from jsnajdr July 10, 2024 10:20
@ciampo ciampo force-pushed the feat/navigator-simplify-apis branch 2 times, most recently from f9155ed to 1a6ecf2 Compare July 11, 2024 09:53
@ciampo ciampo added [Type] Code Quality Issues or PRs that relate to code quality [Package] Components /packages/components labels Jul 11, 2024
@ciampo ciampo force-pushed the feat/navigator-simplify-apis branch from 05b5131 to 7650c06 Compare August 15, 2024 17:30
@ciampo ciampo marked this pull request as ready for review August 15, 2024 17:51
@ciampo ciampo requested a review from ajitbohra as a code owner August 15, 2024 17:51
@ciampo ciampo requested a review from a team August 15, 2024 17:51
Copy link

github-actions bot commented Aug 15, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@ciampo ciampo self-assigned this Aug 15, 2024
Comment on lines +27 to +28
raw: '/ "\'><=invalid_path',
escaped: "/ &quot;'&gt;<=invalid_path",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because of "going back" always behaving like "go to parent", all paths need to start with / in order to work well with the component's pattern matching logic

Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

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

This looks good to me 👍

Left a few minor suggestions.

I appreciate the simplification here. Makes the API clearer and more predictable, and the consumers better aware that they should prepare their navigation structure in a more hierarchical one-to-one way.

@@ -4,6 +4,8 @@
This feature is still experimental. “Experimental” means this is an early implementation subject to drastic and breaking changes.
Copy link
Member

Choose a reason for hiding this comment

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

Sounds like we can remove the experimental callout now.

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 was planning on removing those experimental callouts and Storybook tags once we also export the component without the experimental prefix (in a follow-up PR)

packages/components/src/navigator/test/index.tsx Outdated Show resolved Hide resolved
packages/components/src/navigator/types.ts Outdated Show resolved Hide resolved
deprecated( '`goToParent` prop in wp.components.NavigatorBackButton', {
since: '6.7',
alternative:
'"back" navigations are always treated as going to the parent screen',
Copy link
Member

Choose a reason for hiding this comment

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

Should we just suggest goBack()? For someone attempting to use goToParent, it's not immediately clear in their IDE that goBack is the recommended alternative.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The NavigatorBackButton doesn't have a goBack prop, since "going back" was already the default behavior. The goToParent prop was changing that behaviour, but now that the default behaviour of "going back" is the same as "going to parent", that prop basically became a no-op and can just be omitted.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, got it, makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually thanks to your comment, I realised that this deprecation was not necessary because that was a code path that could not be hit anymore. I just removed the code instead: da79e35

Copy link
Member

Choose a reason for hiding this comment

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

Perfect 🧹

@ciampo ciampo force-pushed the feat/navigator-simplify-apis branch from 14dbcb8 to c24eec9 Compare August 16, 2024 14:58
@ciampo ciampo enabled auto-merge (squash) August 16, 2024 14:58
@ciampo ciampo merged commit 42db13f into trunk Aug 16, 2024
61 checks passed
@ciampo ciampo deleted the feat/navigator-simplify-apis branch August 16, 2024 15:34
@github-actions github-actions bot added this to the Gutenberg 19.1 milestone Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants