mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Breadcrumbs: Remove logic that is no longer needed (#75263)
This commit is contained in:
parent
3ee40d3a5a
commit
6e246a5fd2
@ -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', () => {
|
it('does ignore duplicates', () => {
|
||||||
const pageNav: NavModelItem = {
|
const pageNav: NavModelItem = {
|
||||||
text: 'My page',
|
text: 'My page',
|
||||||
|
@ -13,21 +13,9 @@ export function buildBreadcrumbs(sectionNav: NavModelItem, pageNav?: NavModelIte
|
|||||||
}
|
}
|
||||||
|
|
||||||
// construct the URL to match
|
// construct the URL to match
|
||||||
// we want to ignore query params except for the editview query param
|
|
||||||
const urlParts = node.url?.split('?') ?? ['', ''];
|
const urlParts = node.url?.split('?') ?? ['', ''];
|
||||||
let urlToMatch = urlParts[0];
|
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
|
// Check if we found home/root if if so return early
|
||||||
if (homeNav && urlToMatch === homeNav.url) {
|
if (homeNav && urlToMatch === homeNav.url) {
|
||||||
crumbs.unshift({ text: homeNav.text, href: node.url ?? '' });
|
crumbs.unshift({ text: homeNav.text, href: node.url ?? '' });
|
||||||
@ -35,6 +23,11 @@ export function buildBreadcrumbs(sectionNav: NavModelItem, pageNav?: NavModelIte
|
|||||||
return;
|
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) {
|
if (!node.hideFromBreadcrumbs && !isSamePathAsLastBreadcrumb) {
|
||||||
crumbs.unshift({ text: node.text, href: node.url ?? '' });
|
crumbs.unshift({ text: node.text, href: node.url ?? '' });
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user