From 45a7a215835f749e51e43e00d33812c013e4f9bd Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Tue, 3 Mar 2020 16:40:18 +0300 Subject: [PATCH] Refactor updateAxisTitle --- .../public/components/options/metrics_axes/index.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/index.tsx b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/index.tsx index 40c43225db131..32c21008c2a3a 100644 --- a/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/index.tsx +++ b/src/legacy/core_plugins/vis_type_vislib/public/components/options/metrics_axes/index.tsx @@ -92,14 +92,14 @@ function MetricsAxisOptions(props: ValidationVisOptionsProps) const updateAxisTitle = useCallback( (seriesParams?: SeriesParam[]) => { const series = seriesParams || stateParams.seriesParams; - const axes = cloneDeep(stateParams.valueAxes); let isAxesChanged = false; let lastValuesChanged = false; const lastLabels = { ...lastCustomLabels }; const lastMatchingSeriesAgg = { ...lastSeriesAgg }; - stateParams.valueAxes.forEach((axis, axisNumber) => { + const axes = stateParams.valueAxes.map((axis, axisNumber) => { let newCustomLabel = ''; + let updatedAxis; const matchingSeries: IAggConfig[] = []; series.forEach((serie, seriesIndex) => { @@ -135,16 +135,19 @@ function MetricsAxisOptions(props: ValidationVisOptionsProps) (aggTypeIsChanged || aggFieldIsChanged || axis.title.text === '' || - lastCustomLabels[axis.id] === axis.title.text) + lastCustomLabels[axis.id] === axis.title.text) && + newCustomLabel !== axis.title.text ) { // Override axis title with new custom label - axes[axisNumber] = { + updatedAxis = { ...axis, title: { ...axis.title, text: newCustomLabel }, }; isAxesChanged = true; } } + + return updatedAxis || axis; }); if (isAxesChanged) {