Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webui: set form validity also at the initial load of the mount point mapping #5228

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 28 additions & 17 deletions ui/webui/src/components/storage/MountPointMapping.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,30 @@ const getInitialRequests = (requests, requiredMountPoints) => {
return [...requiredRequests, ...extraRequests];
};

/* Check validity of the requests array
* @param {Array} requests - partitioning requests
* @deviceData {Object} deviceData - device data
* @returns {boolean}
*/
const getRequestsValid = (requests, deviceData) => {
const checkValidRequest = r => {
return (
r["mount-point"] &&
r["device-spec"] &&
!isReformatInvalid(deviceData, r, requests)[0]
);
};

/* When requests change check for duplicate mount point or device assignments and update form validity */
const isFormValid = (
!hasDuplicateFields(requests, "mount-point") &&
!hasDuplicateFields(requests, "device-spec") &&
requests.every(checkValidRequest)
);

return isFormValid;
};

const isReformatInvalid = (deviceData, request, requests) => {
const device = request["device-spec"];

Expand Down Expand Up @@ -477,7 +501,9 @@ const RequestsTable = ({

const initialRequests = getInitialRequests(requests, requiredMountPoints);
setUnappliedRequests(initialRequests);
}, [partitioningDataPath, requests, requiredMountPoints]);

setIsFormValid(getRequestsValid(initialRequests, deviceData));
}, [deviceData, setIsFormValid, partitioningDataPath, requests, requiredMountPoints]);

const handleRequestChange = useCallback(({ mountPoint, deviceSpec, requestIndex, reformat, remove }) => {
const newRequests = [...unappliedRequests];
Expand All @@ -499,22 +525,7 @@ const RequestsTable = ({
}
}

const checkValidRequest = r => {
return (
r["mount-point"] &&
r["device-spec"] &&
!isReformatInvalid(deviceData, r, newRequests)[0]
);
};

/* When requests change check for duplicate mount point or device assignments and update form validity */
const isFormValid = (
!hasDuplicateFields(newRequests, "mount-point") &&
!hasDuplicateFields(newRequests, "device-spec") &&
newRequests.every(checkValidRequest)
);

setIsFormValid(isFormValid);
setIsFormValid(getRequestsValid(newRequests, deviceData));

/* Sync newRequests to the backend */
updatePartitioningRequests({
Expand Down
6 changes: 5 additions & 1 deletion ui/webui/test/check-storage
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,13 @@ class TestStorageMountPoints(anacondalib.VirtInstallMachineCase, StorageHelpers)
new_applied_partitioning = s.dbus_get_applied_partitioning()
self.assertNotEqual(new_applied_partitioning, applied_partitioning)

# When going back and forward 'Next' button should not be disabled
# https://bugzilla.redhat.com/show_bug.cgi?id=2242086
i.back(previous_page=i.steps.CUSTOM_MOUNT_POINT)
i.check_next_disabled(False)

# Swap partitions should not be selectable for the required mount point rows
# https://bugzilla.redhat.com/show_bug.cgi?id=2239836
i.back(previous_page=i.steps.CUSTOM_MOUNT_POINT)
i.back()

m.execute(f"mkswap {disk}5")
Expand Down