From ab045184e42eb2e02ec308607788973aaa72691d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Tue, 13 Sep 2022 10:19:59 +0200 Subject: [PATCH] PanelMenu: Remove hide legend action as it was showing on all panel types (#54876) * PanelMenu: Remove hide legend action * Fix test * Updated --- .betterer.results | 7 +++--- .../dashboard/utils/getPanelMenu.test.ts | 12 --------- .../features/dashboard/utils/getPanelMenu.ts | 25 ++++++++++--------- 3 files changed, 16 insertions(+), 28 deletions(-) diff --git a/.betterer.results b/.betterer.results index 7bc72b3ff20..5705282280a 100644 --- a/.betterer.results +++ b/.betterer.results @@ -4200,13 +4200,12 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "7"], [0, 0, 0, "Unexpected any. Specify a different type.", "8"], [0, 0, 0, "Unexpected any. Specify a different type.", "9"], - [0, 0, 0, "Unexpected any. Specify a different type.", "10"], - [0, 0, 0, "Do not use any type assertions.", "11"], + [0, 0, 0, "Do not use any type assertions.", "10"], + [0, 0, 0, "Unexpected any. Specify a different type.", "11"], [0, 0, 0, "Unexpected any. Specify a different type.", "12"], [0, 0, 0, "Unexpected any. Specify a different type.", "13"], [0, 0, 0, "Unexpected any. Specify a different type.", "14"], - [0, 0, 0, "Unexpected any. Specify a different type.", "15"], - [0, 0, 0, "Unexpected any. Specify a different type.", "16"] + [0, 0, 0, "Unexpected any. Specify a different type.", "15"] ], "public/app/features/dashboard/utils/panelMerge.test.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], diff --git a/public/app/features/dashboard/utils/getPanelMenu.test.ts b/public/app/features/dashboard/utils/getPanelMenu.test.ts index 094be864769..ab6751711f7 100644 --- a/public/app/features/dashboard/utils/getPanelMenu.test.ts +++ b/public/app/features/dashboard/utils/getPanelMenu.test.ts @@ -45,12 +45,6 @@ describe('getPanelMenu', () => { "shortcut": "x", "text": "Explore", }, - Object { - "iconClassName": "exchange-alt", - "onClick": [Function], - "shortcut": "p l", - "text": "Show legend", - }, Object { "iconClassName": "info-circle", "onClick": [Function], @@ -135,12 +129,6 @@ describe('getPanelMenu', () => { "shortcut": "x", "text": "Explore", }, - Object { - "iconClassName": "exchange-alt", - "onClick": [Function], - "shortcut": "p l", - "text": "Show legend", - }, Object { "iconClassName": "info-circle", "onClick": [Function], diff --git a/public/app/features/dashboard/utils/getPanelMenu.ts b/public/app/features/dashboard/utils/getPanelMenu.ts index 821b89899e7..13a5e639819 100644 --- a/public/app/features/dashboard/utils/getPanelMenu.ts +++ b/public/app/features/dashboard/utils/getPanelMenu.ts @@ -48,11 +48,6 @@ export function getPanelMenu( sharePanel(dashboard, panel); }; - const onToggleLegend = (event: React.MouseEvent) => { - event.preventDefault(); - toggleLegend(panel); - }; - const onAddLibraryPanel = (event: React.MouseEvent) => { event.preventDefault(); addLibraryPanel(dashboard, panel); @@ -96,6 +91,10 @@ export function getPanelMenu( store.dispatch(navigateToExplore(panel, { getDataSourceSrv, getTimeSrv, getExploreUrl, openInNewWindow }) as any); }; + const onToggleLegend = (event: React.MouseEvent) => { + event.preventDefault(); + toggleLegend(panel); + }; const menu: PanelMenuItem[] = []; if (!panel.isEditing) { @@ -141,13 +140,6 @@ export function getPanelMenu( }); } - menu.push({ - text: panel.options.legend?.showLegend ? 'Hide legend' : 'Show legend', - iconClassName: 'exchange-alt', - onClick: onToggleLegend, - shortcut: 'p l', - }); - const inspectMenu: PanelMenuItem[] = []; // Only show these inspect actions for data plugins @@ -192,6 +184,7 @@ export function getPanelMenu( id: 'panel.header-menu.inspect', message: `Inspect`, }); + menu.push({ type: 'submenu', text: inspectTextTranslation, @@ -251,6 +244,14 @@ export function getPanelMenu( } } + if (panel.options.legend) { + subMenu.push({ + text: panel.options.legend.showLegend ? 'Hide legend' : 'Show legend', + onClick: onToggleLegend, + shortcut: 'p l', + }); + } + if (!panel.isEditing && subMenu.length) { const moreTextTranslation = t({ id: 'panel.header-menu.more',