Open Grafana Pathfinder instead of the help menu if its installed (#110592)
* Link to Grafana Pathfinder if available Signed-off-by: Jack Baldry <jack.baldry@grafana.com> * refactor: `getComponentIdFromComponentMeta()` only receives the title * Making sure we pass helpNode without Parents to the pathfinder app. * minor refactoring to isolate the code. * Fix tests Signed-off-by: Jack Baldry <jack.baldry@grafana.com> * cleaned up the structure and exposing the helpNavItem via a hook * added missing files. * Add support for old and new pathfinder IDs Signed-off-by: Jack Baldry <jack.baldry@grafana.com> * Rename hook for consistency Signed-off-by: Jack Baldry <jack.baldry@grafana.com> --------- Signed-off-by: Jack Baldry <jack.baldry@grafana.com> Co-authored-by: Levente Balogh <balogh.levente.hu@gmail.com> Co-authored-by: Marcus Andersson <marcus.andersson@grafana.com>
This commit is contained in:
co-authored by
Levente Balogh
Marcus Andersson
parent
e05cfb676a
commit
09a3498552
@@ -30,6 +30,7 @@ export {
|
||||
type UsePluginFunctionsOptions,
|
||||
type UsePluginFunctionsResult,
|
||||
} from './pluginExtensions/usePluginFunctions';
|
||||
export { setHelpNavItemHook, useHelpNavItem, type UseHelpNavItem } from './navigation/useHelpNavItem';
|
||||
export { getObservablePluginLinks } from './pluginExtensions/getObservablePluginLinks';
|
||||
export { getObservablePluginComponents } from './pluginExtensions/getObservablePluginComponents';
|
||||
export {
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import { NavModelItem } from '@grafana/data';
|
||||
|
||||
export type UseHelpNavItem = () => NavModelItem | undefined;
|
||||
|
||||
let singleton: UseHelpNavItem | undefined;
|
||||
|
||||
export function setHelpNavItemHook(hook: UseHelpNavItem): void {
|
||||
// We allow overriding the registry in tests
|
||||
if (singleton && process.env.NODE_ENV !== 'test') {
|
||||
throw new Error('setHelpNavItemHook() function should only be called once, when Grafana is starting.');
|
||||
}
|
||||
singleton = hook;
|
||||
}
|
||||
|
||||
export function useHelpNavItem(): NavModelItem | undefined {
|
||||
if (!singleton) {
|
||||
throw new Error('useHelpNavItem() can only be used after the Grafana instance has started.');
|
||||
}
|
||||
return singleton();
|
||||
}
|
||||
Reference in New Issue
Block a user