mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
TopNav: KioskMode rewrite move to AppChrome responsibility and make it a global feature (#55149)
* Initial progress * Moving keybindingSrv to context * Simplfy KioskMode * Removed unused logic * Make kiosk=tv behave as before but when topnav is enabled * Minor fix * Fixing tests * Fixing bug with notice when entering kiosk mode * Fixed test
This commit is contained in:
@@ -5,21 +5,21 @@ import Drop from 'tether-drop';
|
||||
import { locationSearchToObject, navigationLogger, reportPageview } from '@grafana/runtime';
|
||||
|
||||
import { useGrafana } from '../context/GrafanaContext';
|
||||
import { keybindingSrv } from '../services/keybindingSrv';
|
||||
|
||||
import { GrafanaRouteComponentProps, RouteDescriptor } from './types';
|
||||
|
||||
export interface Props extends Omit<GrafanaRouteComponentProps, 'queryParams'> {}
|
||||
|
||||
export function GrafanaRoute(props: Props) {
|
||||
const { chrome } = useGrafana();
|
||||
const { chrome, keybindings } = useGrafana();
|
||||
|
||||
chrome.registerRouteRender(props.route);
|
||||
chrome.setMatchedRoute(props.route);
|
||||
|
||||
useEffect(() => {
|
||||
keybindings.clearAndInitGlobalBindings();
|
||||
|
||||
updateBodyClassNames(props.route);
|
||||
cleanupDOM();
|
||||
reportPageview();
|
||||
navigationLogger('GrafanaRoute', false, 'Mounted', props.match);
|
||||
|
||||
return () => {
|
||||
@@ -30,12 +30,6 @@ export function GrafanaRoute(props: Props) {
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
// unbinds all and re-bind global keybindins
|
||||
keybindingSrv.reset();
|
||||
keybindingSrv.initGlobals();
|
||||
}, [chrome, props.route]);
|
||||
|
||||
useEffect(() => {
|
||||
cleanupDOM();
|
||||
reportPageview();
|
||||
|
||||
@@ -1,33 +1,9 @@
|
||||
import { t } from '@lingui/macro';
|
||||
|
||||
import { AppEvents, UrlQueryMap } from '@grafana/data';
|
||||
import { locationService } from '@grafana/runtime';
|
||||
import { UrlQueryMap } from '@grafana/data';
|
||||
|
||||
import { KioskMode } from '../../types';
|
||||
import appEvents from '../app_events';
|
||||
|
||||
export function toggleKioskMode() {
|
||||
let kiosk = locationService.getSearchObject().kiosk;
|
||||
|
||||
switch (kiosk) {
|
||||
case 'tv':
|
||||
kiosk = true;
|
||||
appEvents.emit(AppEvents.alertSuccess, [
|
||||
t({ id: 'navigation.kiosk.tv-alert', message: 'Press ESC to exit Kiosk mode' }),
|
||||
]);
|
||||
break;
|
||||
case '1':
|
||||
case true:
|
||||
kiosk = null;
|
||||
break;
|
||||
default:
|
||||
kiosk = 'tv';
|
||||
}
|
||||
|
||||
locationService.partial({ kiosk });
|
||||
}
|
||||
|
||||
export function getKioskMode(queryParams: UrlQueryMap): KioskMode {
|
||||
// TODO Remove after topnav feature toggle is permanent and old NavBar is removed
|
||||
export function getKioskMode(queryParams: UrlQueryMap): KioskMode | null {
|
||||
switch (queryParams.kiosk) {
|
||||
case 'tv':
|
||||
return KioskMode.TV;
|
||||
@@ -36,10 +12,6 @@ export function getKioskMode(queryParams: UrlQueryMap): KioskMode {
|
||||
case true:
|
||||
return KioskMode.Full;
|
||||
default:
|
||||
return KioskMode.Off;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function exitKioskMode() {
|
||||
locationService.partial({ kiosk: null });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user