From 8206a230617b1376e7b525070be8db05959174ff Mon Sep 17 00:00:00 2001 From: kay delaney <45561153+kaydelaney@users.noreply.github.com> Date: Mon, 11 Mar 2024 11:27:12 +0000 Subject: [PATCH] Scenes/Repeats: Show reduced panel menu for repeat panels (#84085) --- .../dashboard-scene/scene/PanelMenuBehavior.tsx | 14 ++++++++------ .../scene/PanelRepeaterGridItem.tsx | 14 +++++++++++--- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/public/app/features/dashboard-scene/scene/PanelMenuBehavior.tsx b/public/app/features/dashboard-scene/scene/PanelMenuBehavior.tsx index 61d958afcea..de31e624675 100644 --- a/public/app/features/dashboard-scene/scene/PanelMenuBehavior.tsx +++ b/public/app/features/dashboard-scene/scene/PanelMenuBehavior.tsx @@ -33,7 +33,7 @@ import { UnlinkLibraryPanelModal } from './UnlinkLibraryPanelModal'; /** * Behavior is called when VizPanelMenu is activated (ie when it's opened). */ -export function panelMenuBehavior(menu: VizPanelMenu) { +export function panelMenuBehavior(menu: VizPanelMenu, isRepeat = false) { const asyncFunc = async () => { // hm.. add another generic param to SceneObject to specify parent type? // eslint-disable-next-line @typescript-eslint/consistent-type-assertions @@ -64,7 +64,7 @@ export function panelMenuBehavior(menu: VizPanelMenu) { href: getViewPanelUrl(panel), }); - if (dashboard.canEditDashboard()) { + if (dashboard.canEditDashboard() && !isRepeat) { // We could check isEditing here but I kind of think this should always be in the menu, // and going into panel edit should make the dashboard go into edit mode is it's not already items.push({ @@ -86,7 +86,7 @@ export function panelMenuBehavior(menu: VizPanelMenu) { shortcut: 'p s', }); - if (dashboard.state.isEditing) { + if (dashboard.state.isEditing && !isRepeat) { moreSubMenu.push({ text: t('panel.header-menu.duplicate', `Duplicate`), onClick: () => { @@ -105,7 +105,7 @@ export function panelMenuBehavior(menu: VizPanelMenu) { }, }); - if (dashboard.state.isEditing) { + if (dashboard.state.isEditing && !isRepeat) { if (parent instanceof LibraryVizPanel) { moreSubMenu.push({ text: t('panel.header-menu.unlink-library-panel', `Unlink library panel`), @@ -153,7 +153,7 @@ export function panelMenuBehavior(menu: VizPanelMenu) { }); } - if (dashboard.canEditDashboard() && plugin && !plugin.meta.skipDataQuery) { + if (dashboard.canEditDashboard() && plugin && !plugin.meta.skipDataQuery && !isRepeat) { moreSubMenu.push({ text: t('panel.header-menu.get-help', 'Get help'), onClick: (e: React.MouseEvent) => { @@ -200,7 +200,7 @@ export function panelMenuBehavior(menu: VizPanelMenu) { }); } - if (dashboard.state.isEditing) { + if (dashboard.state.isEditing && !isRepeat) { items.push({ text: '', type: 'divider', @@ -223,6 +223,8 @@ export function panelMenuBehavior(menu: VizPanelMenu) { asyncFunc(); } +export const repeatPanelMenuBehavior = (menu: VizPanelMenu) => panelMenuBehavior(menu, true); + async function getExploreMenuItem(panel: VizPanel): Promise { const exploreUrl = await tryGetExploreUrlForPanel(panel); if (!exploreUrl) { diff --git a/public/app/features/dashboard-scene/scene/PanelRepeaterGridItem.tsx b/public/app/features/dashboard-scene/scene/PanelRepeaterGridItem.tsx index 48745d21ad7..d02442c2075 100644 --- a/public/app/features/dashboard-scene/scene/PanelRepeaterGridItem.tsx +++ b/public/app/features/dashboard-scene/scene/PanelRepeaterGridItem.tsx @@ -15,12 +15,15 @@ import { MultiValueVariable, LocalValueVariable, CustomVariable, + VizPanelMenu, + VizPanelState, } from '@grafana/scenes'; import { GRID_CELL_HEIGHT, GRID_CELL_VMARGIN } from 'app/core/constants'; import { getMultiVariableValues } from '../utils/utils'; import { LibraryVizPanel } from './LibraryVizPanel'; +import { repeatPanelMenuBehavior } from './PanelMenuBehavior'; import { DashboardRepeatsProcessedEvent } from './types'; interface PanelRepeaterGridItemState extends SceneGridItemStateLike { @@ -107,15 +110,20 @@ export class PanelRepeaterGridItem extends SceneObjectBase = { $variables: new SceneVariableSet({ variables: [ new LocalValueVariable({ name: variable.state.name, value: values[index], text: String(texts[index]) }), ], }), key: `${panelToRepeat.state.key}-clone-${index}`, - }); - + }; + if (index > 0) { + cloneState.menu = new VizPanelMenu({ + $behaviors: [repeatPanelMenuBehavior], + }); + } + const clone = panelToRepeat.clone(cloneState); repeatedPanels.push(clone); }