fix: dashboard variable getting deleted on edit instances (#1561)

This commit is contained in:
Pranshu Chittora 2022-09-12 23:24:45 +05:30 committed by GitHub
parent eaadc3bb95
commit c43dabdb0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 5 deletions

View File

@ -33,7 +33,7 @@ const { Option } = Select;
interface VariableItemProps {
variableData: IDashboardVariable;
onCancel: () => void;
onSave: (name: string, arg0: IDashboardVariable) => void;
onSave: (name: string, arg0: IDashboardVariable, arg1: string) => void;
validateName: (arg0: string) => boolean;
variableViewMode: TVariableViewMode;
}
@ -118,8 +118,11 @@ function VariableItem({
modificationUUID: v4(),
};
onSave(
(variableViewMode === 'EDIT' ? variableData.name : variableName) as string,
variableName,
newVariableData,
(variableViewMode === 'EDIT' && variableName !== variableData.name
? variableData.name
: '') as string,
);
onCancel();
};
@ -162,7 +165,9 @@ function VariableItem({
value={variableName}
onChange={(e): void => {
setVariableName(e.target.value);
setErrorName(!validateName(e.target.value));
setErrorName(
!validateName(e.target.value) && e.target.value !== variableData.name,
);
}}
/>
<div>

View File

@ -62,13 +62,19 @@ function VariablesSetting({
const onVariableSaveHandler = (
name: string,
variableData: IDashboardVariable,
oldName: string,
): void => {
if (!variableData.name) {
return;
}
const newVariables = { ...variables };
newVariables[variableData.name] = variableData;
if (variableViewMode === 'EDIT') delete newVariables[name];
newVariables[name] = variableData;
if (oldName) {
delete newVariables[oldName];
}
updateDashboardVariables(newVariables);
onDoneVariableViewMode();
};