Skip to content

Commit

Permalink
webui: set form validity also at the initial load of the mount point …
Browse files Browse the repository at this point in the history
…mapping

Resolves: rhbz#2242086
  • Loading branch information
KKoukiou committed Oct 6, 2023
1 parent 5b9a374 commit 2a06c0e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
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

0 comments on commit 2a06c0e

Please sign in to comment.