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/alerting/unified/components/PluginBridge.tsx

41 lines
1.1 KiB

import { ReactElement } from 'react';
import * as React from 'react';
import { usePluginBridge } from '../hooks/usePluginBridge';
import { SupportedPlugin } from '../types/pluginBridges';
export type PluginID = SupportedPlugin | string;
export interface PluginBridgeProps {
plugin: PluginID;
// shows an optional component when the plugin is not installed
notInstalledFallback?: ReactElement;
// shows an optional component when we're checking if the plugin is installed
loadingComponent?: ReactElement;
}
export const PluginBridge = ({
children,
plugin,
loadingComponent,
notInstalledFallback,
}: React.PropsWithChildren<PluginBridgeProps>) => {
const { loading, installed } = usePluginBridge(plugin);
if (loading) {
return loadingComponent ?? null;
}
if (!installed) {
return notInstalledFallback ?? null;
}
return <>{children}</>;
};
export function createBridgeURL(plugin: PluginID, path?: string, options?: Record<string, string>) {
const searchParams = new URLSearchParams(options).toString();
const pluginPath = `/a/${plugin}${path}`;
return pluginPath + (searchParams ? '?' + searchParams : '');
}