import React from 'react';
import { observer } from 'mobx-react';
import { NavModel, NavModelItem } from '../../nav_model_srv';
import classNames from 'classnames';
import appEvents from 'app/core/app_events';
import { toJS } from 'mobx';
export interface IProps {
model: NavModel;
}
const SelectNav = ({ main, customCss }: { main: NavModelItem; customCss: string }) => {
const defaultSelectedItem = main.children.find(navItem => {
return navItem.active === true;
});
const gotoUrl = evt => {
var element = evt.target;
var url = element.options[element.selectedIndex].value;
appEvents.emit('location-change', { href: url });
};
return (
{/* Label to make it clickable */}
);
};
const Tabs = ({ main, customCss }: { main: NavModelItem; customCss: string }) => {
return (
{main.children.map((tab, idx) => {
if (tab.hideFromTabs) {
return null;
}
const tabClasses = classNames({
'gf-tabs-link': true,
active: tab.active,
});
return (
{tab.text}
);
})}
);
};
const Navigation = ({ main }: { main: NavModelItem }) => {
return (
);
};
@observer
export default class PageHeader extends React.Component {
constructor(props) {
super(props);
}
shouldComponentUpdate() {
//Hack to re-render on changed props from angular with the @observer decorator
return true;
}
renderTitle(title: string, breadcrumbs: any[]) {
if (!title && (!breadcrumbs || breadcrumbs.length === 0)) {
return null;
}
if (!breadcrumbs || breadcrumbs.length === 0) {
return {title} ;
}
const breadcrumbsResult = [];
for (let i = 0; i < breadcrumbs.length; i++) {
const bc = breadcrumbs[i];
if (bc.url) {
breadcrumbsResult.push(
{bc.title}
);
} else {
breadcrumbsResult.push( / {bc.title} );
}
}
breadcrumbsResult.push( / {title} );
return {breadcrumbsResult} ;
}
renderHeaderTitle(main) {
return (
{main.icon && }
{main.img && }
{this.renderTitle(main.text, main.breadcrumbs)}
{main.subTitle &&
{main.subTitle}
}
{main.subType && (
{main.subType.text}
)}
);
}
render() {
const { model } = this.props;
if (!model) {
return null;
}
const main = toJS(model.main); // Convert to JS if its a mobx observable
return (
{this.renderHeaderTitle(main)}
{main.children && }
);
}
}