Skip to content

Commit 04f8989

Browse files
authored
fix: correct same level side navigation on breadcrumbs (#6710)
* fix: correct same level side navigation on breadcrumbs * chore: add comment for matching route path handling
1 parent 97b851f commit 04f8989

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

components/withBreadcrumbs.tsx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,19 @@ import { useClientContext, useMediaQuery, useSiteNavigation } from '@/hooks';
88
import type { NavigationKeys } from '@/types';
99
import { dashToCamelCase } from '@/util/stringUtils';
1010

11-
const WithBreadcrumbs: FC = () => {
12-
const { navigationItems, getSideNavigation } = useSiteNavigation();
11+
type WithBreadcrumbsProps = {
12+
navKeys?: Array<NavigationKeys>;
13+
};
14+
15+
const WithBreadcrumbs: FC<WithBreadcrumbsProps> = ({ navKeys = [] }) => {
16+
const { getSideNavigation } = useSiteNavigation();
1317
const { pathname } = useClientContext();
1418
const isMobileScreen = useMediaQuery('(max-width: 639px)');
1519

1620
const maxLength = isMobileScreen ? 2 : 4;
1721

1822
const getBreadrumbs = () => {
19-
const [navigationKey] =
20-
navigationItems.find(([, item]) => pathname.includes(item.link)) || [];
21-
22-
if (navigationKey === undefined) {
23-
return [];
24-
}
25-
26-
const navigationTree = getSideNavigation([navigationKey as NavigationKeys]);
23+
const navigationTree = getSideNavigation(navKeys);
2724

2825
const pathList = pathname
2926
.split('/')
@@ -34,9 +31,15 @@ const WithBreadcrumbs: FC = () => {
3431

3532
// Reduce the pathList to a breadcrumbs array by finding each path in the current navigation layer,
3633
// updating the currentNode to the found node's items(next layer) for the next iteration.
37-
return pathList.reduce((breadcrumbs, path) => {
34+
return pathList.reduce((breadcrumbs, path, index) => {
3835
const nodeWithCurrentPath = currentNode.find(
39-
([nodePath]) => nodePath === path
36+
([nodePath, entry]) =>
37+
nodePath === path &&
38+
// Skip checking child path if it is the last path since there is no more child item inside
39+
(index === pathList.length - 1 ||
40+
entry.items.some(
41+
([childPath]) => childPath === pathList[index + 1]
42+
))
4043
);
4144

4245
if (nodeWithCurrentPath) {

layouts/About.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const AboutLayout: FC<PropsWithChildren> = ({ children }) => (
1717

1818
<WithMetaBar />
1919

20-
<WithBreadcrumbs />
20+
<WithBreadcrumbs navKeys={['about', 'getInvolved']} />
2121
</ArticleLayout>
2222
</>
2323
);

layouts/Learn.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const LearnLayout: FC<PropsWithChildren> = ({ children }) => (
2222

2323
<WithMetaBar />
2424

25-
<WithBreadcrumbs />
25+
<WithBreadcrumbs navKeys={['learn']} />
2626
</ArticleLayout>
2727
</>
2828
);

navigation.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@
9292
"link": "/about/governance",
9393
"label": "components.navigation.about.links.governance"
9494
},
95-
"releases": {
95+
"previousReleases": {
9696
"link": "/about/previous-releases",
9797
"label": "components.navigation.about.links.releases"
9898
},
99-
"security": {
99+
"securityReporting": {
100100
"link": "/about/security-reporting",
101101
"label": "components.navigation.about.links.security"
102102
}
@@ -113,7 +113,7 @@
113113
"link": "/about/get-involved/collab-summit",
114114
"label": "components.navigation.getInvolved.links.collabSummit"
115115
},
116-
"upcomingEvents": {
116+
"events": {
117117
"link": "/about/get-involved/events",
118118
"label": "components.navigation.getInvolved.links.upcomingEvents"
119119
},

0 commit comments

Comments
 (0)