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:
Torkel Ödegaard
2022-09-15 14:04:58 +02:00
committed by GitHub
parent 7352c181c2
commit b8e72d6173
24 changed files with 216 additions and 143 deletions

View File

@@ -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();

View File

@@ -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 });
}