Skip to content

Commit

Permalink
ui/volumes: When re-check the box only update the untouched fields
Browse files Browse the repository at this point in the history
In order to keep the user customization, edit the global value
(name/path) should not affect the defaults pre-fill of the touched
field.

Unless the users uncheck the box of multi-volume creation and re-check
again, we only update the untouched field with the new global value.

Refs: #2964
  • Loading branch information
ChengYanJin committed Dec 22, 2020
1 parent 7002295 commit 4c3cbe3
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion ui/src/containers/CreateVolume.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,33 @@ const CreateVolume = (props) => {
return items.find((item) => item.value === selectedValue);
};

//if re-check the box again, we should only update/pre-fill the defaults for unchanged field.
// to make sure to keep the user customization.
const handleCheckboxChange = (field) => (selectedObj) => {
setFieldValue(field, selectedObj.target.checked);
// Clear the untouched field to get the update from the global value
for (let i = 0; i < values.numberOfVolumes; i++) {
if (
touched &&
touched.volumes &&
touched?.volumes[i]?.name === true
) {
continue;
} else {
setFieldValue(`volumes[${i}]name`, '');
}
if (
touched &&
touched.volumes &&
touched?.volumes[i]?.path === true
) {
continue;
} else {
setFieldValue(`volumes[${i}]path`, '');
}
}
};

const addLabel = () => {
const labels = values.labels;
labels[labelName] = labelValue;
Expand Down Expand Up @@ -667,7 +694,7 @@ const CreateVolume = (props) => {
label={intl.translate('create_multiple_volumes')}
checked={values.multiVolumeCreation}
value={values.multiVolumeCreation}
onChange={handleChange('multiVolumeCreation')}
onChange={handleCheckboxChange('multiVolumeCreation')}
onBlur={handleOnBlur}
/>
</CheckboxContainer>
Expand Down

0 comments on commit 4c3cbe3

Please sign in to comment.