From 2e7b77a94a35679614d28e3747d59e5b50818a53 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Tue, 16 May 2023 12:18:35 -0700 Subject: [PATCH] StateTimeline: Support hideFrom field config (#68586) --- .yarn/sdks/prettier/package.json | 2 +- .../core/components/TimelineChart/utils.ts | 20 ++++++++++++------- .../plugins/panel/state-timeline/module.tsx | 2 ++ .../plugins/panel/status-history/module.tsx | 2 ++ 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/.yarn/sdks/prettier/package.json b/.yarn/sdks/prettier/package.json index 3f8599ab154..f2362f14d65 100644 --- a/.yarn/sdks/prettier/package.json +++ b/.yarn/sdks/prettier/package.json @@ -1,6 +1,6 @@ { "name": "prettier", - "version": "2.8.1-sdk", + "version": "2.8.4-sdk", "main": "./index.js", "type": "commonjs" } diff --git a/public/app/core/components/TimelineChart/utils.ts b/public/app/core/components/TimelineChart/utils.ts index 16872dd3b14..d424525956f 100644 --- a/public/app/core/components/TimelineChart/utils.ts +++ b/public/app/core/components/TimelineChart/utils.ts @@ -444,6 +444,9 @@ export function prepareTimelineFields( const fields: Field[] = []; for (let field of nullToValue(nulledFrame).fields) { + if (field.config.custom?.hideFrom?.viz) { + continue; + } switch (field.type) { case FieldType.time: isTimeseries = true; @@ -558,6 +561,7 @@ export function getFieldLegendItem(fields: Field[], theme: GrafanaTheme2): VizLe const thresholds = fieldConfig.thresholds; // If thresholds are enabled show each step in the legend + // This ignores the hide from legend since the range is valid if (colorMode === FieldColorModeId.Thresholds && thresholds?.steps && thresholds.steps.length > 1) { return getThresholdItems(fieldConfig, theme); } @@ -567,15 +571,17 @@ export function getFieldLegendItem(fields: Field[], theme: GrafanaTheme2): VizLe return undefined; // eventually a color bar } - let stateColors: Map = new Map(); + const stateColors: Map = new Map(); fields.forEach((field) => { - field.values.forEach((v) => { - let state = field.display!(v); - if (state.color) { - stateColors.set(state.text, state.color!); - } - }); + if (!field.config.custom?.hideFrom?.legend) { + field.values.forEach((v) => { + let state = field.display!(v); + if (state.color) { + stateColors.set(state.text, state.color!); + } + }); + } }); stateColors.forEach((color, label) => { diff --git a/public/app/plugins/panel/state-timeline/module.tsx b/public/app/plugins/panel/state-timeline/module.tsx index dd97e7ebae4..ce0eea81101 100644 --- a/public/app/plugins/panel/state-timeline/module.tsx +++ b/public/app/plugins/panel/state-timeline/module.tsx @@ -60,6 +60,8 @@ export const plugin = new PanelPlugin(StateTimelinePanel) shouldApply: (f) => f.type !== FieldType.time, process: identityOverrideProcessor, }); + + commonOptionsBuilder.addHideFrom(builder); }, }) .setPanelOptions((builder) => { diff --git a/public/app/plugins/panel/status-history/module.tsx b/public/app/plugins/panel/status-history/module.tsx index 6b4d7af5032..9266f326231 100644 --- a/public/app/plugins/panel/status-history/module.tsx +++ b/public/app/plugins/panel/status-history/module.tsx @@ -40,6 +40,8 @@ export const plugin = new PanelPlugin(StatusHistoryPanel) step: 1, }, }); + + commonOptionsBuilder.addHideFrom(builder); }, }) .setPanelOptions((builder) => {