From 658388573e14d5d16cc59ade582e7281a1f466f8 Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Thu, 10 Jun 2021 05:53:18 -0400 Subject: [PATCH] StatPanel: Fixes issue with graph look when switching color mode (#35460) (#35482) --- .../src/components/Sparkline/Sparkline.tsx | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/grafana-ui/src/components/Sparkline/Sparkline.tsx b/packages/grafana-ui/src/components/Sparkline/Sparkline.tsx index 476f58acfee..cfb321c3bf8 100755 --- a/packages/grafana-ui/src/components/Sparkline/Sparkline.tsx +++ b/packages/grafana-ui/src/components/Sparkline/Sparkline.tsx @@ -70,20 +70,21 @@ export class Sparkline extends PureComponent { componentDidUpdate(prevProps: SparklineProps, prevState: State) { const { alignedDataFrame } = this.state; - let stateUpdate = {}; + + if (!alignedDataFrame) { + return; + } + + let rebuildConfig = false; if (prevProps.sparkline !== this.props.sparkline) { - if (!alignedDataFrame) { - return; - } - const hasStructureChanged = !compareDataFrameStructures(this.state.alignedDataFrame, prevState.alignedDataFrame); - if (hasStructureChanged) { - const configBuilder = this.prepareConfig(alignedDataFrame); - stateUpdate = { configBuilder }; - } + rebuildConfig = !compareDataFrameStructures(this.state.alignedDataFrame, prevState.alignedDataFrame); + } else if (prevProps.config !== this.props.config) { + rebuildConfig = true; } - if (Object.keys(stateUpdate).length > 0) { - this.setState(stateUpdate); + + if (rebuildConfig) { + this.setState({ configBuilder: this.prepareConfig(alignedDataFrame) }); } }