From 6e62afa9502c5c41973e3b427732349567e05beb Mon Sep 17 00:00:00 2001 From: Kristina Date: Tue, 26 Nov 2024 10:40:25 -0600 Subject: [PATCH] StateTimeline: Fix use of hidden fields in data links (#95095) * Use hideFrom in GraphNG to hide fields if value is defined. Remove other filtering from timeline chart * make hidefrom logic more robust * remove unneeded decoupling, filter fields when there are no links * add omitHideFromViz prop to GraphNG * Add more to comment on property --------- Co-authored-by: Leon Sorokin --- public/app/core/components/GraphNG/GraphNG.tsx | 17 +++++++++++++++++ .../components/TimelineChart/TimelineChart.tsx | 1 + .../app/core/components/TimelineChart/utils.ts | 3 --- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/public/app/core/components/GraphNG/GraphNG.tsx b/public/app/core/components/GraphNG/GraphNG.tsx index 673d7a348d3..8a8904f23ff 100644 --- a/public/app/core/components/GraphNG/GraphNG.tsx +++ b/public/app/core/components/GraphNG/GraphNG.tsx @@ -52,6 +52,14 @@ export interface GraphNGProps extends Themeable2 { dataLinkPostProcessor?: DataLinkPostProcessor; cursorSync?: DashboardCursorSync; + // Remove fields that are hidden from the visualization before rendering + // The fields will still be available for other things like data links + // this is a temporary hack that only works when: + // 1. renderLegend (above) does not render + // 2. does not have legend series toggle + // 3. passes through all fields required for link/action gen (including those with hideFrom.viz) + omitHideFromViz?: boolean; + /** * needed for propsToDiff to re-init the plot & config * this is a generic approach to plot re-init, without having to specify which panel-level options @@ -175,6 +183,15 @@ export class GraphNG extends Component { }; } + if (props.omitHideFromViz) { + const nonHiddenFields = alignedFrameFinal.fields.filter((field) => field.config.custom?.hideFrom?.viz !== true); + alignedFrameFinal = { + ...alignedFrameFinal, + fields: nonHiddenFields, + length: nonHiddenFields.length, + }; + } + let config = this.state?.config; if (withConfig) { diff --git a/public/app/core/components/TimelineChart/TimelineChart.tsx b/public/app/core/components/TimelineChart/TimelineChart.tsx index 1c1b4e8dad7..f4317a127b7 100644 --- a/public/app/core/components/TimelineChart/TimelineChart.tsx +++ b/public/app/core/components/TimelineChart/TimelineChart.tsx @@ -86,6 +86,7 @@ export class TimelineChart extends Component { prepConfig={this.prepConfig} propsToDiff={propsToDiff} renderLegend={this.renderLegend} + omitHideFromViz={true} /> ); } diff --git a/public/app/core/components/TimelineChart/utils.ts b/public/app/core/components/TimelineChart/utils.ts index 26f1227ebe0..0057b21331d 100644 --- a/public/app/core/components/TimelineChart/utils.ts +++ b/public/app/core/components/TimelineChart/utils.ts @@ -375,9 +375,6 @@ export function prepareTimelineFields( const fields: Field[] = []; for (let field of frame.fields) { - if (field.config.custom?.hideFrom?.viz) { - continue; - } switch (field.type) { case FieldType.time: isTimeseries = true;