Breadcrumbs: Remove logic that is no longer needed (#75263)

pull/75646/head
Torkel Ödegaard 2 years ago committed by GitHub
parent 3ee40d3a5a
commit 6e246a5fd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 25
      public/app/core/components/Breadcrumbs/utils.test.ts
  2. 17
      public/app/core/components/Breadcrumbs/utils.ts

@ -120,31 +120,6 @@ describe('breadcrumb utils', () => {
]);
});
it('does not match the home nav if the editview param is different', () => {
const pageNav: NavModelItem = {
text: 'My page',
url: '/my-page',
parentItem: {
text: 'My parent page',
url: '/home?orgId=1&editview=settings',
},
};
const sectionNav: NavModelItem = {
text: 'My section',
url: '/my-section',
parentItem: {
text: 'My parent section',
url: '/my-parent-section',
},
};
expect(buildBreadcrumbs(sectionNav, pageNav, mockHomeNav)).toEqual([
{ text: 'My parent section', href: '/my-parent-section' },
{ text: 'My section', href: '/my-section' },
{ text: 'My parent page', href: '/home?orgId=1&editview=settings' },
{ text: 'My page', href: '/my-page' },
]);
});
it('does ignore duplicates', () => {
const pageNav: NavModelItem = {
text: 'My page',

@ -13,21 +13,9 @@ export function buildBreadcrumbs(sectionNav: NavModelItem, pageNav?: NavModelIte
}
// construct the URL to match
// we want to ignore query params except for the editview query param
const urlParts = node.url?.split('?') ?? ['', ''];
let urlToMatch = urlParts[0];
const urlSearchParams = new URLSearchParams(urlParts[1]);
if (urlSearchParams.has('editview')) {
urlToMatch += `?editview=${urlSearchParams.get('editview')}`;
}
// This enabled app plugins to control breadcrumbs of their root pages
const isSamePathAsLastBreadcrumb = urlToMatch.length > 0 && lastPath === urlToMatch;
// Remember this path for the next breadcrumb
lastPath = urlToMatch;
// Check if we found home/root if if so return early
if (homeNav && urlToMatch === homeNav.url) {
crumbs.unshift({ text: homeNav.text, href: node.url ?? '' });
@ -35,6 +23,11 @@ export function buildBreadcrumbs(sectionNav: NavModelItem, pageNav?: NavModelIte
return;
}
// This enabled app plugins to control breadcrumbs of their root pages
const isSamePathAsLastBreadcrumb = urlToMatch.length > 0 && lastPath === urlToMatch;
// Remember this path for the next breadcrumb
lastPath = urlToMatch;
if (!node.hideFromBreadcrumbs && !isSamePathAsLastBreadcrumb) {
crumbs.unshift({ text: node.text, href: node.url ?? '' });
}

Loading…
Cancel
Save