mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 01:53:33 -06:00
* Change nav structure when topnav is enable to do initial tests with new information architecture * Support for nested sections * Updated * sentance case * Progress on plugin challange * Rewrite to functional component * Progress * Updates * Progress * Progress on things * missing file * Fixing issue with runtime, need to use setter way to set component exposed via runtime * Move PageLayoutType to grafana/data * Fixing breadcrumb issue, adding more tests * reverted backend change * fix recursive issue with cleanup
71 lines
2.3 KiB
TypeScript
71 lines
2.3 KiB
TypeScript
import { Location as HistoryLocation } from 'history';
|
|
|
|
import { GrafanaPlugin, NavIndex, NavModel, NavModelItem, PanelPluginMeta, PluginType } from '@grafana/data';
|
|
import { config } from '@grafana/runtime';
|
|
import { getNavModel } from 'app/core/selectors/navModel';
|
|
|
|
import { importPanelPluginFromMeta } from './importPanelPlugin';
|
|
import { getPluginSettings } from './pluginSettings';
|
|
import { importAppPlugin, importDataSourcePlugin } from './plugin_loader';
|
|
|
|
export async function loadPlugin(pluginId: string): Promise<GrafanaPlugin> {
|
|
const info = await getPluginSettings(pluginId);
|
|
let result: GrafanaPlugin | undefined;
|
|
|
|
if (info.type === PluginType.app) {
|
|
result = await importAppPlugin(info);
|
|
}
|
|
if (info.type === PluginType.datasource) {
|
|
result = await importDataSourcePlugin(info);
|
|
}
|
|
if (info.type === PluginType.panel) {
|
|
const panelPlugin = await importPanelPluginFromMeta(info as PanelPluginMeta);
|
|
result = panelPlugin as unknown as GrafanaPlugin;
|
|
}
|
|
if (info.type === PluginType.renderer) {
|
|
result = { meta: info } as GrafanaPlugin;
|
|
}
|
|
|
|
if (!result) {
|
|
throw new Error('Unknown Plugin type: ' + info.type);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
export function buildPluginSectionNav(location: HistoryLocation, pluginNav: NavModel | null, navIndex: NavIndex) {
|
|
// When topnav is disabled we only just show pluginNav like before
|
|
if (!config.featureToggles.topnav) {
|
|
return pluginNav;
|
|
}
|
|
|
|
const originalSection = getNavModel(navIndex, 'apps').main;
|
|
const section = { ...originalSection };
|
|
|
|
// If we have plugin nav don't set active page in section as it will cause double breadcrumbs
|
|
const currentUrl = config.appSubUrl + location.pathname + location.search;
|
|
let activePage: NavModelItem | undefined;
|
|
|
|
// Set active page
|
|
section.children = (section?.children ?? []).map((child) => {
|
|
if (child.children) {
|
|
return {
|
|
...child,
|
|
children: child.children.map((pluginPage) => {
|
|
if (currentUrl.startsWith(pluginPage.url ?? '')) {
|
|
activePage = {
|
|
...pluginPage,
|
|
active: true,
|
|
};
|
|
return activePage;
|
|
}
|
|
return pluginPage;
|
|
}),
|
|
};
|
|
}
|
|
return child;
|
|
});
|
|
|
|
return { main: section, node: activePage ?? section };
|
|
}
|