From 126b7f8049de321ce6a3f3bc35965cda629dcebb Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Thu, 20 May 2021 15:43:34 +0100 Subject: [PATCH] Timeline: Fixes crash when there was only 1 threshold step (#34471) (#34486) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit fd6e33865133db78b195455f8bf7f3cd110f91e4) Co-authored-by: Torkel Ödegaard --- public/app/plugins/panel/state-timeline/utils.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/public/app/plugins/panel/state-timeline/utils.ts b/public/app/plugins/panel/state-timeline/utils.ts index 99edbe8aa34..9f4f0a1d44b 100644 --- a/public/app/plugins/panel/state-timeline/utils.ts +++ b/public/app/plugins/panel/state-timeline/utils.ts @@ -318,15 +318,14 @@ export function prepareTimelineLegendItems( } const items: VizLegendItem[] = []; - const first = fields[0].config; - const colorMode = first.color?.mode ?? FieldColorModeId.Fixed; + const fieldConfig = fields[0].config; + const colorMode = fieldConfig.color?.mode ?? FieldColorModeId.Fixed; + const thresholds = fieldConfig.thresholds; // If thresholds are enabled show each step in the legend - if (colorMode === FieldColorModeId.Thresholds && first.thresholds?.steps) { - const steps = first.thresholds.steps; - const disp = getValueFormat( - first.thresholds.mode === ThresholdsMode.Percentage ? 'percent' : first.unit ?? 'fixed' - ); + if (colorMode === FieldColorModeId.Thresholds && thresholds?.steps && thresholds.steps.length > 1) { + const steps = thresholds.steps; + const disp = getValueFormat(thresholds.mode === ThresholdsMode.Percentage ? 'percent' : fieldConfig.unit ?? ''); const fmt = (v: number) => formattedValueToString(disp(v));