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 23, 2020
1 parent 1db10a8 commit 5d584ae
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion ui/src/containers/CreateVolume.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,21 @@ 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?.volumes?.[i]?.name) {
setFieldValue(`volumes[${i}]name`, '');
}
if (!touched?.volumes?.[i]?.path) {
setFieldValue(`volumes[${i}]path`, '');
}
}
};

const addLabel = () => {
const labels = values.labels;
labels[labelName] = labelValue;
Expand Down Expand Up @@ -667,7 +682,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 5d584ae

Please sign in to comment.