From 0e6bcba4a8b6fb036094a5cba8191ed505cb6c3f Mon Sep 17 00:00:00 2001 From: Sergej-Vlasov <37613182+Sergej-Vlasov@users.noreply.github.com> Date: Tue, 10 Dec 2024 10:06:07 +0000 Subject: [PATCH] Dashboards: Fixes issue with panel header showing even when hide time override was enabled (#97389) 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 * fixes * fixed test (cherry picked from commit 6fd3620d50e6204c2113ec523020084aa84e760b) Co-authored-by: Torkel Ödegaard --- .../PanelDataQueriesTab.test.tsx | 16 +++++++++ .../PanelDataPane/PanelDataQueriesTab.tsx | 33 ++++++++----------- .../panel-edit/getPanelFrameOptions.tsx | 19 +++++++++-- .../transformSaveModelToScene.test.ts | 12 +++++++ .../transformSaveModelToScene.ts | 4 ++- 5 files changed, 62 insertions(+), 22 deletions(-) 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,