mirror of
https://github.com/grafana/grafana.git
synced 2025-07-30 13:02:33 +08:00

* Progress * Progress * Update * Update * Update * Update * Responsive improvements * Update * Update * Update * Revert height change * Update * add missing testid * update * Fixes * update * Refactoring * fix bug in app chrome service * Fixed e2e tests * fix * fix * Update * Update * fix bookmarks e2e * Update * improve responsiveness on small screens for breadcrumbs * Always use two levels when menu is docked * Adding kiosk toggle button to dashboards only * update * Update * Update * when menu is docked and no actions use 1 level * removed formatting change that caused unnessary diff in PR * remove extra separator line after merge with main * Fix double separators * Update * remove temp change * Update
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import { createContext, useCallback, useContext } from 'react';
|
|
|
|
import { GrafanaConfig } from '@grafana/data';
|
|
import { LocationService, locationService, BackendSrv } from '@grafana/runtime';
|
|
|
|
import { AppChromeService } from '../components/AppChrome/AppChromeService';
|
|
import { NewFrontendAssetsChecker } from '../services/NewFrontendAssetsChecker';
|
|
import { KeybindingSrv } from '../services/keybindingSrv';
|
|
|
|
export interface GrafanaContextType {
|
|
backend: BackendSrv;
|
|
location: LocationService;
|
|
config: GrafanaConfig;
|
|
chrome: AppChromeService;
|
|
keybindings: KeybindingSrv;
|
|
newAssetsChecker: NewFrontendAssetsChecker;
|
|
}
|
|
|
|
export const GrafanaContext = createContext<GrafanaContextType | undefined>(undefined);
|
|
|
|
export function useGrafana(): GrafanaContextType {
|
|
const context = useContext(GrafanaContext);
|
|
if (!context) {
|
|
throw new Error('No GrafanaContext found');
|
|
}
|
|
return context;
|
|
}
|
|
|
|
// Implementation of useReturnToPrevious that's made available through
|
|
// @grafana/runtime
|
|
export function useReturnToPreviousInternal() {
|
|
const { chrome } = useGrafana();
|
|
return useCallback(
|
|
(title: string, href?: string) => {
|
|
const { pathname, search } = locationService.getLocation();
|
|
chrome.setReturnToPrevious({
|
|
title: title,
|
|
href: href ?? pathname + search,
|
|
});
|
|
},
|
|
[chrome]
|
|
);
|
|
}
|