Skip to content

Commit

Permalink
fix: handle the old variables by name instead of id
Browse files Browse the repository at this point in the history
  • Loading branch information
vikrantgupta25 committed Apr 19, 2024
1 parent a140bef commit 112c98b
Showing 1 changed file with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,37 @@ 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);

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,
},
},
};
Expand Down

0 comments on commit 112c98b

Please sign in to comment.