@@ -102,71 +102,69 @@ export function MultiMetricsQueryParamsProvider({
102102
103103 function setQueryParamsForIndex ( i : number ) {
104104 return function ( newQueryParams : ReadableQueryParams ) {
105+ const newMetricQueries = metricQueries . map (
106+ ( metricQuery : BaseMetricQuery , j : number ) => {
107+ if ( i !== j ) {
108+ return metricQuery ;
109+ }
110+ return {
111+ metric : metricQuery . metric ,
112+ queryParams : newQueryParams ,
113+ label : metricQuery . label ,
114+ } ;
115+ }
116+ ) ;
105117 navigateToMetricQueries (
106- syncUpdatedMetricQueries (
107- metricQueries ,
108- metricQueries . map ( ( metricQuery : BaseMetricQuery , j : number ) => {
109- if ( i !== j ) {
110- return metricQuery ;
111- }
112- return {
113- metric : metricQuery . metric ,
114- queryParams : newQueryParams ,
115- label : metricQuery . label ,
116- } ;
117- } )
118- )
118+ syncUpdatedMetricQueries ( metricQueries , newMetricQueries )
119119 ) ;
120120 } ;
121121 }
122122
123123 function setTraceMetricForIndex ( i : number ) {
124124 return function ( newTraceMetric : TraceMetric ) {
125- navigateToMetricQueries (
126- syncUpdatedMetricQueries (
127- metricQueries ,
128- metricQueries . map ( ( metricQuery : BaseMetricQuery , j : number ) => {
129- if ( i !== j ) {
130- return metricQuery ;
131- }
132-
133- // when changing trace metrics, we need to look at the currently selected
134- // aggregation and make necessary adjustments
135- const visualize = metricQuery . queryParams . visualizes [ 0 ] ;
136- let aggregateFields = undefined ;
137- if ( visualize && isVisualizeFunction ( visualize ) ) {
138- const selectedAggregation = visualize . parsedFunction ?. name ;
139- const allowedAggregations = OPTIONS_BY_TYPE [ newTraceMetric . type ] ;
140-
141- if (
142- selectedAggregation &&
143- allowedAggregations ?. find (
144- option => option . value === selectedAggregation
145- )
146- ) {
147- // the currently selected aggregation changed types
148- aggregateFields = [
149- updateVisualizeYAxis ( visualize , selectedAggregation , newTraceMetric ) ,
150- ...metricQuery . queryParams . aggregateFields . filter ( isGroupBy ) ,
151- ] ;
152- } else {
153- // the currently selected aggregation isn't supported on the new metric
154- const defaultAggregation =
155- DEFAULT_YAXIS_BY_TYPE [ newTraceMetric . type ] || 'sum' ;
156- aggregateFields = [
157- updateVisualizeYAxis ( visualize , defaultAggregation , newTraceMetric ) ,
158- ...metricQuery . queryParams . aggregateFields . filter ( isGroupBy ) ,
159- ] ;
160- }
125+ const newMetricQueries = metricQueries . map (
126+ ( metricQuery : BaseMetricQuery , j : number ) => {
127+ if ( i !== j ) {
128+ return metricQuery ;
129+ }
130+
131+ // when changing trace metrics, we need to look at the currently selected
132+ // aggregation and make necessary adjustments
133+ const visualize = metricQuery . queryParams . visualizes [ 0 ] ;
134+ let aggregateFields = undefined ;
135+ if ( visualize && isVisualizeFunction ( visualize ) ) {
136+ const selectedAggregation = visualize . parsedFunction ?. name ;
137+ const allowedAggregations = OPTIONS_BY_TYPE [ newTraceMetric . type ] ;
138+
139+ if (
140+ selectedAggregation &&
141+ allowedAggregations ?. find ( option => option . value === selectedAggregation )
142+ ) {
143+ // the currently selected aggregation changed types
144+ aggregateFields = [
145+ updateVisualizeYAxis ( visualize , selectedAggregation , newTraceMetric ) ,
146+ ...metricQuery . queryParams . aggregateFields . filter ( isGroupBy ) ,
147+ ] ;
148+ } else {
149+ // the currently selected aggregation isn't supported on the new metric
150+ const defaultAggregation =
151+ DEFAULT_YAXIS_BY_TYPE [ newTraceMetric . type ] || 'sum' ;
152+ aggregateFields = [
153+ updateVisualizeYAxis ( visualize , defaultAggregation , newTraceMetric ) ,
154+ ...metricQuery . queryParams . aggregateFields . filter ( isGroupBy ) ,
155+ ] ;
161156 }
162-
163- return {
164- queryParams : metricQuery . queryParams . replace ( { aggregateFields} ) ,
165- metric : newTraceMetric ,
166- label : metricQuery . label ,
167- } ;
168- } )
169- )
157+ }
158+
159+ return {
160+ queryParams : metricQuery . queryParams . replace ( { aggregateFields} ) ,
161+ metric : newTraceMetric ,
162+ label : metricQuery . label ,
163+ } ;
164+ }
165+ ) ;
166+ navigateToMetricQueries (
167+ syncUpdatedMetricQueries ( metricQueries , newMetricQueries )
170168 ) ;
171169 } ;
172170 }
0 commit comments