Skip to content

Commit 2a06c0e

Browse files
committed
webui: set form validity also at the initial load of the mount point mapping
Resolves: rhbz#2242086
1 parent 5b9a374 commit 2a06c0e

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

ui/webui/src/components/storage/MountPointMapping.jsx

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,30 @@ const getInitialRequests = (requests, requiredMountPoints) => {
8686
return [...requiredRequests, ...extraRequests];
8787
};
8888

89+
/* Check validity of the requests array
90+
* @param {Array} requests - partitioning requests
91+
* @deviceData {Object} deviceData - device data
92+
* @returns {boolean}
93+
*/
94+
const getRequestsValid = (requests, deviceData) => {
95+
const checkValidRequest = r => {
96+
return (
97+
r["mount-point"] &&
98+
r["device-spec"] &&
99+
!isReformatInvalid(deviceData, r, requests)[0]
100+
);
101+
};
102+
103+
/* When requests change check for duplicate mount point or device assignments and update form validity */
104+
const isFormValid = (
105+
!hasDuplicateFields(requests, "mount-point") &&
106+
!hasDuplicateFields(requests, "device-spec") &&
107+
requests.every(checkValidRequest)
108+
);
109+
110+
return isFormValid;
111+
};
112+
89113
const isReformatInvalid = (deviceData, request, requests) => {
90114
const device = request["device-spec"];
91115

@@ -477,7 +501,9 @@ const RequestsTable = ({
477501

478502
const initialRequests = getInitialRequests(requests, requiredMountPoints);
479503
setUnappliedRequests(initialRequests);
480-
}, [partitioningDataPath, requests, requiredMountPoints]);
504+
505+
setIsFormValid(getRequestsValid(initialRequests, deviceData));
506+
}, [deviceData, setIsFormValid, partitioningDataPath, requests, requiredMountPoints]);
481507

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

502-
const checkValidRequest = r => {
503-
return (
504-
r["mount-point"] &&
505-
r["device-spec"] &&
506-
!isReformatInvalid(deviceData, r, newRequests)[0]
507-
);
508-
};
509-
510-
/* When requests change check for duplicate mount point or device assignments and update form validity */
511-
const isFormValid = (
512-
!hasDuplicateFields(newRequests, "mount-point") &&
513-
!hasDuplicateFields(newRequests, "device-spec") &&
514-
newRequests.every(checkValidRequest)
515-
);
516-
517-
setIsFormValid(isFormValid);
528+
setIsFormValid(getRequestsValid(newRequests, deviceData));
518529

519530
/* Sync newRequests to the backend */
520531
updatePartitioningRequests({

ui/webui/test/check-storage

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,13 @@ class TestStorageMountPoints(anacondalib.VirtInstallMachineCase, StorageHelpers)
442442
new_applied_partitioning = s.dbus_get_applied_partitioning()
443443
self.assertNotEqual(new_applied_partitioning, applied_partitioning)
444444

445+
# When going back and forward 'Next' button should not be disabled
446+
# https://bugzilla.redhat.com/show_bug.cgi?id=2242086
447+
i.back(previous_page=i.steps.CUSTOM_MOUNT_POINT)
448+
i.check_next_disabled(False)
449+
445450
# Swap partitions should not be selectable for the required mount point rows
446451
# https://bugzilla.redhat.com/show_bug.cgi?id=2239836
447-
i.back(previous_page=i.steps.CUSTOM_MOUNT_POINT)
448452
i.back()
449453

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

0 commit comments

Comments
 (0)