From 2e1e45bbb17dea2257f3ab52e0190799c069f20d Mon Sep 17 00:00:00 2001 From: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> Date: Wed, 10 Apr 2024 17:12:33 -0400 Subject: [PATCH] datatrails: ensure breakdown yaxis sync is maintained when layout changes (#85380) fix: ensure breakdown yaxis sync is maintained when layout changes --- .../trails/ActionTabs/BreakdownScene.tsx | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/public/app/features/trails/ActionTabs/BreakdownScene.tsx b/public/app/features/trails/ActionTabs/BreakdownScene.tsx index dc8fc9527f6..edc2d09dec2 100644 --- a/public/app/features/trails/ActionTabs/BreakdownScene.tsx +++ b/public/app/features/trails/ActionTabs/BreakdownScene.tsx @@ -80,16 +80,28 @@ export class BreakdownScene extends SceneObjectBase { } }); + const metricScene = sceneGraph.getAncestor(this, MetricScene); + const metric = metricScene.state.metric; + this._query = getAutoQueriesForMetric(metric).breakdown; + + // The following state changes (and conditions) will each result in a call to `clearBreakdownPanelAxisValues`. + // By clearing the axis, subsequent calls to `reportBreakdownPanelData` will adjust to an updated axis range. + // These state changes coincide with the panels having their data updated, making a call to `reportBreakdownPanelData`. + // If the axis was not cleared by `clearBreakdownPanelAxisValues` any calls to `reportBreakdownPanelData` which result + // in the same axis will result in no updates to the panels. + const trail = getTrailFor(this); trail.state.$timeRange?.subscribeToState(() => { - // The change in time range will cause a refresh of panel values, - // so we clear the axis range so it can be recalculated when the calls - // to `reportBreakdownPanelData` start being made from the panels' behavior. + // The change in time range will cause a refresh of panel values. this.clearBreakdownPanelAxisValues(); }); - const metric = sceneGraph.getAncestor(this, MetricScene).state.metric; - this._query = getAutoQueriesForMetric(metric).breakdown; + metricScene.subscribeToState(({ layout }, old) => { + if (layout !== old.layout) { + // Change in layout will set up a different set of panel objects that haven't received the current yaxis range + this.clearBreakdownPanelAxisValues(); + } + }); this.updateBody(variable); }