dashfolders: Convert mobx observable to js objects and remove the observer() since we want to use the component outside the react/mobx world #10275

This commit is contained in:
Johannes Schill
2018-01-25 15:37:15 +01:00
committed by Daniel Lee
parent 0722ea04a6
commit 34f27f6b15
@@ -3,12 +3,13 @@ import { observer } from 'mobx-react';
import { NavModel, NavModelItem } from '../../nav_model_srv'; import { NavModel, NavModelItem } from '../../nav_model_srv';
import classNames from 'classnames'; import classNames from 'classnames';
import appEvents from 'app/core/app_events'; import appEvents from 'app/core/app_events';
import { toJS } from 'mobx';
export interface IProps { export interface IProps {
model: NavModel; model: NavModel;
} }
const SelectNav = observer(({ main, customCss }: { main: NavModelItem; customCss: string }) => { const SelectNav = ({ main, customCss }: { main: NavModelItem; customCss: string }) => {
const defaultSelectedItem = main.children.find(navItem => { const defaultSelectedItem = main.children.find(navItem => {
return navItem.active === true; return navItem.active === true;
}); });
@@ -43,9 +44,9 @@ const SelectNav = observer(({ main, customCss }: { main: NavModelItem; customCss
</select> </select>
</div> </div>
); );
}); };
const Tabs = observer(({ main, customCss }: { main: NavModelItem; customCss: string }) => { const Tabs = ({ main, customCss }: { main: NavModelItem; customCss: string }) => {
return ( return (
<ul className={`gf-tabs ${customCss}`}> <ul className={`gf-tabs ${customCss}`}>
{main.children.map((tab, idx) => { {main.children.map((tab, idx) => {
@@ -69,7 +70,7 @@ const Tabs = observer(({ main, customCss }: { main: NavModelItem; customCss: str
})} })}
</ul> </ul>
); );
}); };
const Navigation = ({ main }: { main: NavModelItem }) => { const Navigation = ({ main }: { main: NavModelItem }) => {
return ( return (
@@ -86,6 +87,11 @@ export default class PageHeader extends React.Component<IProps, any> {
super(props); super(props);
} }
shouldComponentUpdate() {
//Hack to re-render on changed props from angular with the @observer decorator
return true;
}
renderTitle(title: string, breadcrumbs: any[]) { renderTitle(title: string, breadcrumbs: any[]) {
if (!title && (!breadcrumbs || breadcrumbs.length === 0)) { if (!title && (!breadcrumbs || breadcrumbs.length === 0)) {
return null; return null;
@@ -141,12 +147,15 @@ export default class PageHeader extends React.Component<IProps, any> {
if (!model) { if (!model) {
return null; return null;
} }
const main = toJS(model.main); // Convert to JS if its a mobx observable
return ( return (
<div className="page-header-canvas"> <div className="page-header-canvas">
<div className="page-container"> <div className="page-container">
<div className="page-header"> <div className="page-header">
{this.renderHeaderTitle(model.main)} {this.renderHeaderTitle(main)}
{model.main.children && <Navigation main={model.main} />} {main.children && <Navigation main={main} />}
</div> </div>
</div> </div>
</div> </div>