The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/plugins/extensions/registry.ts

54 lines
1.4 KiB

import {
AppPluginConfig,
PluginExtensionTypes,
PluginsExtensionLinkConfig,
PluginsExtensionRegistry,
PluginsExtensionLink,
} from '@grafana/runtime';
export function createPluginExtensionsRegistry(apps: Record<string, AppPluginConfig> = {}): PluginsExtensionRegistry {
const registry: PluginsExtensionRegistry = {};
for (const [pluginId, config] of Object.entries(apps)) {
const extensions = config.extensions;
if (!Array.isArray(extensions)) {
continue;
}
for (const extension of extensions) {
const target = extension.target;
const item = createRegistryItem(pluginId, extension);
if (!Array.isArray(registry[target])) {
registry[target] = [item];
continue;
}
registry[target].push(item);
continue;
}
}
for (const key of Object.keys(registry)) {
Object.freeze(registry[key]);
}
return Object.freeze(registry);
}
function createRegistryItem(pluginId: string, extension: PluginsExtensionLinkConfig): PluginsExtensionLink {
const href = `/a/${pluginId}${extension.path}`;
return Object.freeze({
type: PluginExtensionTypes.link,
title: extension.title,
description: extension.description,
href: href,
key: hashKey(`${extension.title}${href}`),
});
}
function hashKey(key: string): number {
return Array.from(key).reduce((s, c) => (Math.imul(31, s) + c.charCodeAt(0)) | 0, 0);
}