From ede278c767f5c081500cedbf50b8917203644ada Mon Sep 17 00:00:00 2001 From: Ivan Ortega Alba Date: Thu, 9 Jan 2025 18:30:06 +0100 Subject: [PATCH] [v11.4.x] Dashboards: Fixes issue with panel header showing even when hide time override was enabled (#98747) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Dashboards: Fixes issue with panel header showing even when hide time override was enabled (#95814) * Dashboards: Fixes issue with panel header showing even when hide time override was enabled (cherry picked from commit 6fd3620d50e6204c2113ec523020084aa84e760b) Co-authored-by: Torkel Ödegaard --- pkg/build/wire/go.sum | 1 + .../PanelDataQueriesTab.test.tsx | 16 +++++++++ .../PanelDataPane/PanelDataQueriesTab.tsx | 33 ++++++++----------- .../panel-edit/getPanelFrameOptions.tsx | 19 +++++++++-- .../transformSaveModelToScene.test.ts | 12 +++++++ .../transformSaveModelToScene.ts | 4 ++- 6 files changed, 63 insertions(+), 22 deletions(-) diff --git a/pkg/build/wire/go.sum b/pkg/build/wire/go.sum index eb414872065..08a9aafd7ab 100644 --- a/pkg/build/wire/go.sum +++ b/pkg/build/wire/go.sum @@ -7,5 +7,6 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0= golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= +golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24= golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ= diff --git a/public/app/features/dashboard-scene/panel-edit/PanelDataPane/PanelDataQueriesTab.test.tsx b/public/app/features/dashboard-scene/panel-edit/PanelDataPane/PanelDataQueriesTab.test.tsx index 5a406406282..c086588f098 100644 --- a/public/app/features/dashboard-scene/panel-edit/PanelDataPane/PanelDataQueriesTab.test.tsx +++ b/public/app/features/dashboard-scene/panel-edit/PanelDataPane/PanelDataQueriesTab.test.tsx @@ -425,6 +425,22 @@ describe('PanelDataQueriesTab', () => { expect(panel.state.$timeRange).toBeInstanceOf(PanelTimeRange); }); + it('should update hoverHeader', async () => { + const { queriesTab, panel } = await setupScene('panel-1'); + + panel.setState({ title: '', hoverHeader: true }); + + panel.state.$data?.activate(); + + queriesTab.onQueryOptionsChange({ + dataSource: { name: 'grafana-testdata', type: 'grafana-testdata-datasource', default: true }, + queries: [], + timeRange: { from: '1h' }, + }); + + expect(panel.state.hoverHeader).toBe(false); + }); + it('should update PanelTimeRange object on time options update', async () => { const { queriesTab, panel } = await setupScene('panel-1'); diff --git a/public/app/features/dashboard-scene/panel-edit/PanelDataPane/PanelDataQueriesTab.tsx b/public/app/features/dashboard-scene/panel-edit/PanelDataPane/PanelDataQueriesTab.tsx index 23f663ca9f5..9eb246042fd 100644 --- a/public/app/features/dashboard-scene/panel-edit/PanelDataPane/PanelDataQueriesTab.tsx +++ b/public/app/features/dashboard-scene/panel-edit/PanelDataPane/PanelDataQueriesTab.tsx @@ -24,8 +24,9 @@ import { updateQueries } from 'app/features/query/state/updateQueries'; import { isSharedDashboardQuery } from 'app/plugins/datasource/dashboard'; import { QueryGroupOptions } from 'app/types'; -import { PanelTimeRange, PanelTimeRangeState } from '../../scene/PanelTimeRange'; +import { PanelTimeRange } from '../../scene/PanelTimeRange'; import { getDashboardSceneFor, getPanelIdForVizPanel, getQueryRunnerFor } from '../../utils/utils'; +import { getUpdatedHoverHeader } from '../getPanelFrameOptions'; import { PanelDataPaneTab, TabId, PanelDataTabHeaderProps } from './types'; @@ -190,12 +191,11 @@ export class PanelDataQueriesTab extends SceneObjectBase { - const panelObj = this.state.panelRef.resolve(); + const panel = this.state.panelRef.resolve(); const dataObj = this.queryRunner; - const timeRangeObj = panelObj.state.$timeRange; const dataObjStateUpdate: Partial = {}; - const timeRangeObjStateUpdate: Partial = {}; + const panelStateUpdate: Partial = {}; if (options.maxDataPoints !== dataObj.state.maxDataPoints) { dataObjStateUpdate.maxDataPoints = options.maxDataPoints ?? undefined; @@ -205,23 +205,16 @@ export class PanelDataQueriesTab extends SceneObjectBase { expect(vizPanel.state.hoverHeader).toEqual(true); }); + it('should set hoverHeader to true if timeFrom and hideTimeOverride is true', () => { + const panel = { + type: 'test-plugin', + timeFrom: '2h', + hideTimeOverride: true, + }; + + const { vizPanel } = buildGridItemForTest(panel); + + expect(vizPanel.state.hoverHeader).toBe(true); + }); + it('should initalize the VizPanel with min interval set', () => { const panel = { title: '', diff --git a/public/app/features/dashboard-scene/serialization/transformSaveModelToScene.ts b/public/app/features/dashboard-scene/serialization/transformSaveModelToScene.ts index 5979197500c..1d74aec3e99 100644 --- a/public/app/features/dashboard-scene/serialization/transformSaveModelToScene.ts +++ b/public/app/features/dashboard-scene/serialization/transformSaveModelToScene.ts @@ -291,6 +291,8 @@ export function buildGridItemForPanel(panel: PanelModel): DashboardGridItem { titleItems.push(new PanelNotices()); + const timeOverrideShown = (panel.timeFrom || panel.timeShift) && !panel.hideTimeOverride; + const vizPanelState: VizPanelState = { key: getVizPanelKeyForPanelId(panel.id), title: panel.title, @@ -301,7 +303,7 @@ export function buildGridItemForPanel(panel: PanelModel): DashboardGridItem { pluginVersion: panel.pluginVersion, displayMode: panel.transparent ? 'transparent' : undefined, // To be replaced with it's own option persited option instead derived - hoverHeader: !panel.title && !panel.timeFrom && !panel.timeShift, + hoverHeader: !panel.title && !timeOverrideShown, hoverHeaderOffset: 0, $data: createPanelDataProvider(panel), titleItems,