import React, { FormEvent } from 'react'; import { css } from 'emotion'; import { Tab, TabsBar, Icon, IconName } from '@grafana/ui'; import appEvents from 'app/core/app_events'; import { NavModel, NavModelItem, NavModelBreadcrumb } from '@grafana/data'; import { CoreEvents } from 'app/types'; export interface Props { model: NavModel; } const SelectNav = ({ children, customCss }: { children: NavModelItem[]; customCss: string }) => { if (!children || children.length === 0) { return null; } const defaultSelectedItem = children.find(navItem => { return navItem.active === true; }); const gotoUrl = (evt: FormEvent) => { const element = evt.target as HTMLSelectElement; const url = element.options[element.selectedIndex].value; appEvents.emit(CoreEvents.locationChange, { href: url }); }; return (
); }; const Navigation = ({ children }: { children: NavModelItem[] }) => { if (!children || children.length === 0) { return null; } const goToUrl = (index: number) => { children.forEach((child, i) => { if (i === index) { appEvents.emit(CoreEvents.locationChange, { href: child.url }); } }); }; return ( ); }; export default class PageHeader extends React.Component { constructor(props: Props) { super(props); } shouldComponentUpdate() { //Hack to re-render on changed props from angular with the @observer decorator return true; } renderTitle(title: string, breadcrumbs: NavModelBreadcrumb[]) { if (!title && (!breadcrumbs || breadcrumbs.length === 0)) { return null; } if (!breadcrumbs || breadcrumbs.length === 0) { return

{title}

; } const breadcrumbsResult = []; for (const bc of breadcrumbs) { if (bc.url) { breadcrumbsResult.push( {bc.title} ); } else { breadcrumbsResult.push( / {bc.title}); } } breadcrumbsResult.push( / {title}); return

{breadcrumbsResult}

; } renderHeaderTitle(main: NavModelItem) { const iconClassName = main.icon === 'grafana' ? css` margin-top: 12px; ` : css` margin-top: 14px; `; return (
{main.icon && } {main.img && }
{this.renderTitle(main.text, main.breadcrumbs ?? [])} {main.subTitle &&
{main.subTitle}
}
); } render() { const { model } = this.props; if (!model) { return null; } const main = model.main; const children = main.children; return (
{this.renderHeaderTitle(main)} {children && children.length && }
); } }