mirror of
https://github.com/grafana/grafana.git
synced 2025-01-15 19:22:34 -06:00
1d689888b0
* Updated package json but not updated source files * Update eslint plugin * updated files
54 lines
1.1 KiB
TypeScript
54 lines
1.1 KiB
TypeScript
import { NavModel, NavModelItem, NavIndex } from '@grafana/data';
|
|
|
|
const getNotFoundModel = (): NavModel => {
|
|
const node: NavModelItem = {
|
|
id: 'not-found',
|
|
text: 'Page not found',
|
|
icon: 'exclamation-triangle',
|
|
subTitle: '404 Error',
|
|
url: 'not-found',
|
|
};
|
|
|
|
return {
|
|
node: node,
|
|
main: node,
|
|
};
|
|
};
|
|
|
|
export const getNavModel = (navIndex: NavIndex, id: string, fallback?: NavModel, onlyChild = false): NavModel => {
|
|
if (navIndex[id]) {
|
|
const node = navIndex[id];
|
|
|
|
let main: NavModelItem;
|
|
if (!onlyChild && node.parentItem) {
|
|
main = { ...node.parentItem };
|
|
|
|
main.children =
|
|
main.children &&
|
|
main.children.map((item) => {
|
|
return {
|
|
...item,
|
|
active: item.url === node.url,
|
|
};
|
|
});
|
|
} else {
|
|
main = node;
|
|
}
|
|
|
|
return {
|
|
node,
|
|
main,
|
|
};
|
|
}
|
|
|
|
if (fallback) {
|
|
return fallback;
|
|
}
|
|
|
|
return getNotFoundModel();
|
|
};
|
|
|
|
export const getTitleFromNavModel = (navModel: NavModel) => {
|
|
return `${navModel.main.text}${navModel.node.text ? ': ' + navModel.node.text : ''}`;
|
|
};
|