Skip to content

Commit

Permalink
Update Subnav to use the new nav data structure (#11324)
Browse files Browse the repository at this point in the history
<!--
  ☝️How to write a good PR title:
- Prefix it with [ComponentName] (if applicable), for example: [Button]
  - Start with a verb, for example: Add, Delete, Improve, Fix…
  - Give as much context as necessary and as little as possible
  - Open it as a draft if it’s a work in progress
-->

### WHY are these changes introduced?

[Fixes #0000](#11322) <!-- link
to issue if one exists -->

<!--
  Context about the problem that’s being addressed.
-->

### WHAT is this pull request doing?
The `nav.json` data was updated and the `Subnav` did not update to match
the new structure, so we were not getting the data properly. This is
updating to match by passing in `nav.children`



https://github.com/Shopify/polaris/assets/4642404/ab987492-3888-42c3-9d46-a7c2e7f9168f


<!--
  Summary of the changes committed.

Before / after screenshots are appreciated for UI changes. Make sure to
include alt text that describes the screenshot.

  Include a video if your changes include interactive content.

If you include an animated gif showing your change, wrapping it in a
details tag is recommended. Gifs usually autoplay, which can cause
accessibility issues for people reviewing your PR:

  <details>
    <summary>Summary of your gif(s)</summary>
    <img src="..." alt="Description of what the gif shows">
  </details>
-->

### How to 🎩

🖥 [Local development
instructions](https://github.com/Shopify/polaris/blob/main/README.md#install-dependencies-and-build-workspaces)
🗒 [General tophatting
guidelines](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md)
📄 [Changelog
guidelines](https://github.com/Shopify/polaris/blob/main/.github/CONTRIBUTING.md#changelog)

### 🎩 checklist

- [ ] Tested a
[snapshot](https://github.com/Shopify/polaris/blob/main/documentation/Releasing.md#-snapshot-releases)
- [ ] Tested on
[mobile](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md#cross-browser-testing)
- [ ] Tested on [multiple
browsers](https://help.shopify.com/en/manual/shopify-admin/supported-browsers)
- [ ] Tested for
[accessibility](https://github.com/Shopify/polaris/blob/main/documentation/Accessibility%20testing.md)
- [ ] Updated the component's `README.md` with documentation changes
- [ ] [Tophatted
documentation](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting%20documentation.md)
changes in the style guide
  • Loading branch information
Yuraima Estevez authored Dec 12, 2023
1 parent 235bc7d commit 2fce504
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions polaris.shopify.com/src/components/Subnav/Subnav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ function getNavItems(path: string): {[key: string]: NavItem} | undefined {
const paths = path.split('/').filter((segment) => segment);

const navItemPath = paths.join('.children.');
const currentNavItem = getObjectValue<NavItem>(nav, navItemPath);
const currentNavItem = getObjectValue<NavItem>(nav.children, navItemPath);

const isOverviewPage = currentNavItem?.children !== undefined;

// Get the parent nav item if we're on a subpage
const parentItemPath = paths.slice(0, -1).join('.children.');
const parentNavItem = isOverviewPage
? currentNavItem
: getObjectValue<NavItem>(nav, parentItemPath);
: getObjectValue<NavItem>(nav.children, parentItemPath);

// Return if we're on a page that doesn't have a subnav
if (!parentNavItem) return;
Expand Down

0 comments on commit 2fce504

Please sign in to comment.