|
|
@ -2,6 +2,7 @@ import { useObservable } from 'react-use'; |
|
|
|
import { BehaviorSubject } from 'rxjs'; |
|
|
|
import { BehaviorSubject } from 'rxjs'; |
|
|
|
|
|
|
|
|
|
|
|
import { NavModelItem } from '@grafana/data'; |
|
|
|
import { NavModelItem } from '@grafana/data'; |
|
|
|
|
|
|
|
import store from 'app/core/store'; |
|
|
|
import { isShallowEqual } from 'app/core/utils/isShallowEqual'; |
|
|
|
import { isShallowEqual } from 'app/core/utils/isShallowEqual'; |
|
|
|
|
|
|
|
|
|
|
|
import { RouteDescriptor } from '../../navigation/types'; |
|
|
|
import { RouteDescriptor } from '../../navigation/types'; |
|
|
@ -11,14 +12,19 @@ export interface AppChromeState { |
|
|
|
sectionNav: NavModelItem; |
|
|
|
sectionNav: NavModelItem; |
|
|
|
pageNav?: NavModelItem; |
|
|
|
pageNav?: NavModelItem; |
|
|
|
actions?: React.ReactNode; |
|
|
|
actions?: React.ReactNode; |
|
|
|
|
|
|
|
searchBarHidden?: boolean; |
|
|
|
|
|
|
|
megaMenuOpen?: boolean; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const defaultSection: NavModelItem = { text: 'Grafana' }; |
|
|
|
const defaultSection: NavModelItem = { text: 'Grafana' }; |
|
|
|
|
|
|
|
|
|
|
|
export class AppChromeService { |
|
|
|
export class AppChromeService { |
|
|
|
|
|
|
|
searchBarStorageKey = 'SearchBar_Hidden'; |
|
|
|
|
|
|
|
|
|
|
|
readonly state = new BehaviorSubject<AppChromeState>({ |
|
|
|
readonly state = new BehaviorSubject<AppChromeState>({ |
|
|
|
chromeless: true, // start out hidden to not flash it on pages without chrome
|
|
|
|
chromeless: true, // start out hidden to not flash it on pages without chrome
|
|
|
|
sectionNav: defaultSection, |
|
|
|
sectionNav: defaultSection, |
|
|
|
|
|
|
|
searchBarHidden: store.getBool(this.searchBarStorageKey, false), |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
routeMounted(route: RouteDescriptor) { |
|
|
|
routeMounted(route: RouteDescriptor) { |
|
|
@ -42,6 +48,16 @@ export class AppChromeService { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
toggleMegaMenu = () => { |
|
|
|
|
|
|
|
this.update({ megaMenuOpen: !this.state.getValue().megaMenuOpen }); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
toggleSearchBar = () => { |
|
|
|
|
|
|
|
const searchBarHidden = !this.state.getValue().searchBarHidden; |
|
|
|
|
|
|
|
store.set(this.searchBarStorageKey, searchBarHidden); |
|
|
|
|
|
|
|
this.update({ searchBarHidden }); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
useState() { |
|
|
|
useState() { |
|
|
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
|
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
|
|
return useObservable(this.state, this.state.getValue()); |
|
|
|
return useObservable(this.state, this.state.getValue()); |
|
|
|