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/explore/extensions/getExploreExtensionConfigs.tsx

66 lines
2.8 KiB

import { PluginExtensionAddedLinkConfig, PluginExtensionPoints } from '@grafana/data';
import { contextSrv } from 'app/core/core';
import { dispatch } from 'app/store/store';
import { AccessControlAction } from 'app/types';
import { log } from '../../plugins/extensions/logs/log';
import { createAddedLinkConfig } from '../../plugins/extensions/utils';
import { changeCorrelationEditorDetails } from '../state/main';
import { runQueries } from '../state/query';
import { ExploreToDashboardPanel } from './AddToDashboard/ExploreToDashboardPanel';
import { getAddToDashboardTitle } from './AddToDashboard/getAddToDashboardTitle';
import { type PluginExtensionExploreContext } from './ToolbarExtensionPoint';
export function getExploreExtensionConfigs(): PluginExtensionAddedLinkConfig[] {
try {
return [
createAddedLinkConfig<PluginExtensionExploreContext>({
// This is called at the top level, so will break if we add a translation here 😱
// eslint-disable-next-line @grafana/i18n/no-untranslated-strings
title: 'Add to dashboard',
description: 'Use the query and panel from explore and create/add it to a dashboard',
targets: [PluginExtensionPoints.ExploreToolbarAction],
icon: 'apps',
category: 'Dashboards',
configure: () => {
const canAddPanelToDashboard =
contextSrv.hasPermission(AccessControlAction.DashboardsCreate) ||
contextSrv.hasPermission(AccessControlAction.DashboardsWrite);
// hide option if user has insufficient permissions
if (!canAddPanelToDashboard) {
return undefined;
}
return {};
},
onClick: (_, { context, openModal }) => {
openModal({
title: getAddToDashboardTitle(),
body: ({ onDismiss }) => <ExploreToDashboardPanel onClose={onDismiss!} exploreId={context?.exploreId!} />,
});
},
}),
createAddedLinkConfig<PluginExtensionExploreContext>({
// This is called at the top level, so will break if we add a translation here 😱
// eslint-disable-next-line @grafana/i18n/no-untranslated-strings
title: 'Add correlation',
// eslint-disable-next-line @grafana/i18n/no-untranslated-strings
description: 'Create a correlation from this query',
targets: [PluginExtensionPoints.ExploreToolbarAction],
icon: 'link',
configure: (context) => {
return context?.shouldShowAddCorrelation ? {} : undefined;
},
onClick: (_, { context }) => {
dispatch(changeCorrelationEditorDetails({ editorMode: true }));
dispatch(runQueries({ exploreId: context!.exploreId }));
},
}),
];
} catch (error) {
log.warning(`Could not configure extensions for Explore due to: "${error}"`);
return [];
}
}