grafana/public/app/core/selectors/navModel.ts
Ivana Huckova 1c58202b26
@grafana/ui: Replace various icons using Icon component (#23442)
* Replace icons in dashboard and settings

* Replace icons in alerting

* Update batch of icons

* Implement icons accross various files

* Style updates

* Search: Fix recent and starred icons

* Update styling and details

* Replace new icon created by unicons

* Fix e2e test, styling

* Minor styling updates

Co-authored-by: Clarity-89 <homes89@ukr.net>
2020-04-12 22:20:02 +02:00

54 lines
1.1 KiB
TypeScript

import { NavModel, NavModelItem, NavIndex } from '@grafana/data';
function 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 function 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: node,
main: main,
};
}
if (fallback) {
return fallback;
}
return getNotFoundModel();
}
export const getTitleFromNavModel = (navModel: NavModel) => {
return `${navModel.main.text}${navModel.node.text ? ': ' + navModel.node.text : ''}`;
};