Actions: Add permission check to missing panels (#111021)
This commit is contained in:
@@ -31,7 +31,9 @@ export const BarChartPanel = (props: PanelProps<Options>) => {
|
||||
// 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<Options>) => {
|
||||
dataLinks={dataLinks}
|
||||
adHocFilters={adHocFilters}
|
||||
hideZeros={options.tooltip.hideZeros}
|
||||
canExecuteActions={userCanExecuteActions}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
|
||||
@@ -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<TimeRange2 | null>(null);
|
||||
|
||||
@@ -220,6 +222,7 @@ export const HeatmapPanel = ({
|
||||
maxHeight={options.tooltip.maxHeight}
|
||||
maxWidth={options.tooltip.maxWidth}
|
||||
replaceVariables={replaceVariables}
|
||||
canExecuteActions={userCanExecuteActions}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
|
||||
@@ -48,11 +48,12 @@ export const StatusHistoryPanel = ({
|
||||
|
||||
// temp range set for adding new annotation set by TooltipPlugin2, consumed by AnnotationPlugin2
|
||||
const [newAnnotationRange, setNewAnnotationRange] = useState<TimeRange2 | null>(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}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
|
||||
@@ -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<Options>) => {
|
||||
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}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
|
||||
@@ -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}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
|
||||
@@ -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 = <VizTooltipFooter dataLinks={dataLinks} actions={actions} />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user