From 38d2833931f5d27d4e4fe8deb0e31400074dba3e Mon Sep 17 00:00:00 2001 From: Vikrant Gupta Date: Sat, 20 Apr 2024 17:54:29 +0530 Subject: [PATCH] fix: handle the old variables by name instead of id (#4890) --- .../DashboardVariableSelection.tsx | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/frontend/src/container/NewDashboard/DashboardVariablesSelection/DashboardVariableSelection.tsx b/frontend/src/container/NewDashboard/DashboardVariablesSelection/DashboardVariableSelection.tsx index 5f770e26d0..1eed8f351f 100644 --- a/frontend/src/container/NewDashboard/DashboardVariablesSelection/DashboardVariableSelection.tsx +++ b/frontend/src/container/NewDashboard/DashboardVariablesSelection/DashboardVariableSelection.tsx @@ -72,6 +72,7 @@ function DashboardVariableSelection(): JSX.Element | null { id: string, value: IDashboardVariable['selectedValue'], allSelected: boolean, + // eslint-disable-next-line sonarjs/cognitive-complexity ): void => { if (id) { updateLocalStorageDashboardVariables(name, value, allSelected); @@ -79,17 +80,29 @@ function DashboardVariableSelection(): JSX.Element | null { if (selectedDashboard) { setSelectedDashboard((prev) => { if (prev) { + const oldVariables = prev?.data.variables; + // this is added to handle case where we have two different + // schemas for variable response + if (oldVariables[id]) { + oldVariables[id] = { + ...oldVariables[id], + selectedValue: value, + allSelected, + }; + } + if (oldVariables[name]) { + oldVariables[name] = { + ...oldVariables[name], + selectedValue: value, + allSelected, + }; + } return { ...prev, data: { ...prev?.data, variables: { - ...prev?.data.variables, - [id]: { - ...prev.data.variables[id], - selectedValue: value, - allSelected, - }, + ...oldVariables, }, }, };