From 38ff1ae0c752767cd7dd634491096c5b80a884ff Mon Sep 17 00:00:00 2001 From: Nawaz Dhandala Date: Mon, 30 Mar 2026 13:56:02 +0100 Subject: [PATCH] feat: prefill legend and unit in MetricGraphConfig on metric change --- .../Components/Metrics/MetricQueryConfig.tsx | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/App/FeatureSet/Dashboard/src/Components/Metrics/MetricQueryConfig.tsx b/App/FeatureSet/Dashboard/src/Components/Metrics/MetricQueryConfig.tsx index e8b2c9011a..27a4102dfd 100644 --- a/App/FeatureSet/Dashboard/src/Components/Metrics/MetricQueryConfig.tsx +++ b/App/FeatureSet/Dashboard/src/Components/Metrics/MetricQueryConfig.tsx @@ -64,6 +64,43 @@ const MetricGraphConfig: FunctionComponent = ( props.onBlur?.(); props.onFocus?.(); if (props.onChange) { + const selectedMetricName: string | undefined = + data.filterData?.metricName?.toString(); + const previousMetricName: string | undefined = + props.data?.metricQueryData?.filterData?.metricName?.toString(); + + // If metric changed, prefill legend and unit from MetricType + if ( + selectedMetricName && + selectedMetricName !== previousMetricName + ) { + const metricType: MetricType | undefined = + props.metricTypes.find((m: MetricType) => { + return m.name === selectedMetricName; + }); + + if (metricType) { + const currentAlias: MetricAliasData = + props.data.metricAliasData || defaultAliasData; + + props.onChange({ + ...props.data, + metricQueryData: data, + metricAliasData: { + ...currentAlias, + legend: currentAlias.legend || metricType.name || "", + legendUnit: + currentAlias.legendUnit || metricType.unit || "", + description: + currentAlias.description || + metricType.description || + "", + }, + }); + return; + } + } + props.onChange({ ...props.data, metricQueryData: data }); } }}