diff --git a/public/app/plugins/panel/barchart/BarChartPanel.tsx b/public/app/plugins/panel/barchart/BarChartPanel.tsx index 3b54eed78d4..3d133a5b429 100644 --- a/public/app/plugins/panel/barchart/BarChartPanel.tsx +++ b/public/app/plugins/panel/barchart/BarChartPanel.tsx @@ -31,7 +31,9 @@ export const BarChartPanel = (props: PanelProps) => { // const { dataLinkPostProcessor } = usePanelContext(); const theme = useTheme2(); - const { onAddAdHocFilter } = usePanelContext(); + const { onAddAdHocFilter, canExecuteActions } = usePanelContext(); + + const userCanExecuteActions = useMemo(() => canExecuteActions?.() ?? false, [canExecuteActions]); const { barWidth, @@ -210,6 +212,7 @@ export const BarChartPanel = (props: PanelProps) => { dataLinks={dataLinks} adHocFilters={adHocFilters} hideZeros={options.tooltip.hideZeros} + canExecuteActions={userCanExecuteActions} /> ); }} diff --git a/public/app/plugins/panel/heatmap/HeatmapPanel.tsx b/public/app/plugins/panel/heatmap/HeatmapPanel.tsx index 779c56bd67c..33ae7a0e32f 100644 --- a/public/app/plugins/panel/heatmap/HeatmapPanel.tsx +++ b/public/app/plugins/panel/heatmap/HeatmapPanel.tsx @@ -45,9 +45,11 @@ export const HeatmapPanel = ({ }: HeatmapPanelProps) => { const theme = useTheme2(); const styles = useStyles2(getStyles); - const { sync, eventsScope, canAddAnnotations, onSelectRange } = usePanelContext(); + const { sync, eventsScope, canAddAnnotations, onSelectRange, canExecuteActions } = usePanelContext(); const cursorSync = sync?.() ?? DashboardCursorSync.Off; + const userCanExecuteActions = useMemo(() => canExecuteActions?.() ?? false, [canExecuteActions]); + // temp range set for adding new annotation set by TooltipPlugin2, consumed by AnnotationPlugin2 const [newAnnotationRange, setNewAnnotationRange] = useState(null); @@ -220,6 +222,7 @@ export const HeatmapPanel = ({ maxHeight={options.tooltip.maxHeight} maxWidth={options.tooltip.maxWidth} replaceVariables={replaceVariables} + canExecuteActions={userCanExecuteActions} /> ); }} diff --git a/public/app/plugins/panel/status-history/StatusHistoryPanel.tsx b/public/app/plugins/panel/status-history/StatusHistoryPanel.tsx index bfa2dbdcf99..a92d1460d94 100644 --- a/public/app/plugins/panel/status-history/StatusHistoryPanel.tsx +++ b/public/app/plugins/panel/status-history/StatusHistoryPanel.tsx @@ -48,11 +48,12 @@ export const StatusHistoryPanel = ({ // temp range set for adding new annotation set by TooltipPlugin2, consumed by AnnotationPlugin2 const [newAnnotationRange, setNewAnnotationRange] = useState(null); - const { sync, eventsScope, canAddAnnotations, eventBus } = usePanelContext(); + const { sync, eventsScope, canAddAnnotations, eventBus, canExecuteActions } = usePanelContext(); const { dataLinkPostProcessor } = useDataLinksContext(); const cursorSync = sync?.() ?? DashboardCursorSync.Off; const enableAnnotationCreation = Boolean(canAddAnnotations && canAddAnnotations()); + const userCanExecuteActions = useMemo(() => canExecuteActions?.() ?? false, [canExecuteActions]); const { frames, warn } = useMemo( () => prepareTimelineFields(data.series, false, timeRange, theme), @@ -153,6 +154,7 @@ export const StatusHistoryPanel = ({ maxHeight={options.tooltip.maxHeight} replaceVariables={replaceVariables} dataLinks={dataLinks} + canExecuteActions={userCanExecuteActions} /> ); }} diff --git a/public/app/plugins/panel/trend/TrendPanel.tsx b/public/app/plugins/panel/trend/TrendPanel.tsx index ecfaff896e0..95ce2330283 100644 --- a/public/app/plugins/panel/trend/TrendPanel.tsx +++ b/public/app/plugins/panel/trend/TrendPanel.tsx @@ -11,7 +11,7 @@ import { useDataLinksContext, } from '@grafana/data'; import { config, PanelDataErrorView } from '@grafana/runtime'; -import { KeyboardPlugin, TooltipDisplayMode, TooltipPlugin2 } from '@grafana/ui'; +import { KeyboardPlugin, TooltipDisplayMode, TooltipPlugin2, usePanelContext } from '@grafana/ui'; import { TooltipHoverMode } from '@grafana/ui/internal'; import { XYFieldMatchers } from 'app/core/components/GraphNG/types'; import { preparePlotFrame } from 'app/core/components/GraphNG/utils'; @@ -35,6 +35,10 @@ export const TrendPanel = ({ id, }: PanelProps) => { const { dataLinkPostProcessor } = useDataLinksContext(); + const { canExecuteActions } = usePanelContext(); + + const userCanExecuteActions = useMemo(() => canExecuteActions?.() ?? false, [canExecuteActions]); + // Need to fallback to first number field if no xField is set in options otherwise panel crashes 😬 const trendXFieldName = options.xField ?? data.series[0]?.fields.find((field) => field.type === FieldType.number)?.name; @@ -143,6 +147,7 @@ export const TrendPanel = ({ replaceVariables={replaceVariables} dataLinks={dataLinks} hideZeros={options.tooltip.hideZeros} + canExecuteActions={userCanExecuteActions} /> ); }} diff --git a/public/app/plugins/panel/xychart/XYChartPanel.tsx b/public/app/plugins/panel/xychart/XYChartPanel.tsx index e3e667730c2..86d088b1d96 100644 --- a/public/app/plugins/panel/xychart/XYChartPanel.tsx +++ b/public/app/plugins/panel/xychart/XYChartPanel.tsx @@ -12,6 +12,7 @@ import { VizLegendItem, useStyles2, useTheme2, + usePanelContext, } from '@grafana/ui'; import { getDisplayValuesForCalcs, TooltipHoverMode } from '@grafana/ui/internal'; @@ -28,6 +29,9 @@ export const XYChartPanel2 = (props: Props2) => { const styles = useStyles2(getStyles); const theme = useTheme2(); + const { canExecuteActions } = usePanelContext(); + const userCanExecuteActions = useMemo(() => canExecuteActions?.() ?? false, [canExecuteActions]); + let { mapping, series: mappedSeries } = props.options; // regenerate series schema when mappings or data changes @@ -128,6 +132,7 @@ export const XYChartPanel2 = (props: Props2) => { seriesIdx={seriesIdx!} replaceVariables={props.replaceVariables} dataLinks={dataLinks} + canExecuteActions={userCanExecuteActions} /> ); }} diff --git a/public/app/plugins/panel/xychart/XYChartTooltip.tsx b/public/app/plugins/panel/xychart/XYChartTooltip.tsx index 585910e9184..1d176b5d82f 100644 --- a/public/app/plugins/panel/xychart/XYChartTooltip.tsx +++ b/public/app/plugins/panel/xychart/XYChartTooltip.tsx @@ -24,6 +24,7 @@ export interface Props { xySeries: XYSeries[]; replaceVariables: InterpolateFunction; dataLinks: LinkModel[]; + canExecuteActions?: boolean; } function stripSeriesName(fieldName: string, seriesName: string) { @@ -51,6 +52,7 @@ export const XYChartTooltip = ({ isPinned, replaceVariables, dataLinks, + canExecuteActions, }: Props) => { const rowIndex = dataIdxs.find((idx) => idx !== null)!; @@ -130,7 +132,7 @@ export const XYChartTooltip = ({ if (isPinned || hasOneClickLink) { const yFieldFrame = data.find((frame) => frame.fields.includes(yField))!; - const actions = getFieldActions(yFieldFrame, yField, replaceVariables, rowIndex); + const actions = canExecuteActions ? getFieldActions(yFieldFrame, yField, replaceVariables, rowIndex) : []; footer = ; }