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

View File

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