Submit
Path:
~
/
/
usr
/
share
/
grafana
/
public
/
app
/
core
/
components
/
Breadcrumbs
/
File Content:
utils.ts
import { NavModelItem } from '@grafana/data'; import { Breadcrumb } from './types'; export function buildBreadcrumbs(sectionNav: NavModelItem, pageNav?: NavModelItem, homeNav?: NavModelItem) { const crumbs: Breadcrumb[] = []; let foundHome = false; let lastPath: string | undefined = undefined; function addCrumbs(node: NavModelItem, shouldDedupe = false) { if (foundHome) { return; } // construct the URL to match const urlParts = node.url?.split('?') ?? ['', '']; let urlToMatch = urlParts[0]; const urlSearchParams = new URLSearchParams(urlParts[1]); if (urlSearchParams.has('editview')) { urlToMatch += `?editview=${urlSearchParams.get('editview')}`; } // Check if we found home/root if if so return early if (homeNav && urlToMatch === homeNav.url) { crumbs.unshift({ text: homeNav.text, href: node.url ?? '' }); foundHome = true; return; } const isSamePathAsLastBreadcrumb = urlToMatch.length > 0 && lastPath === urlToMatch; // Remember this path for the next breadcrumb lastPath = urlToMatch; const shouldAddCrumb = !node.hideFromBreadcrumbs && !(shouldDedupe && isSamePathAsLastBreadcrumb); if (shouldAddCrumb) { crumbs.unshift({ text: node.text, href: node.url ?? '' }); } if (node.parentItem) { addCrumbs(node.parentItem); } } if (pageNav) { addCrumbs(pageNav); } // shouldDedupe = true enables app plugins to control breadcrumbs of their root pages addCrumbs(sectionNav, true); return crumbs; }
Edit
Rename
Chmod
Delete
FILE
FOLDER
INFO
Name
Size
Permission
Action
BreadcrumbItem.tsx
2524 bytes
0644
Breadcrumbs.test.tsx
1723 bytes
0644
Breadcrumbs.tsx
1285 bytes
0644
types.ts
232 bytes
0644
utils.test.ts
4210 bytes
0644
utils.ts
1560 bytes
0644
N4ST4R_ID | Naxtarrr