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

pods: Fix PodCreateModal validation issues #1884

Merged
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
26 changes: 17 additions & 9 deletions src/PodCreateModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ export const PodCreateModal = ({ user, systemServiceAvailable, userServiceAvaila
*/
const dynamicListOnValidationChange = (key, value) => {
setValidationFailed(prevState => {
prevState[key] = value;
if (prevState[key].every(a => a === undefined))
delete prevState[key];
return prevState;
const newState = Object.assign({}, prevState, { [key]: value });
if (newState[key].every(a => a === undefined))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think this code never triggers, and wouldn't make any difference if it did.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This added line is not executed by any test.

delete newState[key];
return newState;
});
};

Expand All @@ -101,12 +101,20 @@ export const PodCreateModal = ({ user, systemServiceAvailable, userServiceAvaila
};

const isFormInvalid = validationFailed => {
const groupHasError = row => row && Object.values(row)
.filter(val => val) // Filter out empty/undefined properties
.length > 0; // If one field has error, the whole group (dynamicList) is invalid
function publishGroupHasError(row, idx) {
// We always ignore errors for empty slots in
// publish. Errors for these slots might show up when the
// debounced validation runs after a row has been removed.
if (!row || !publish[idx])
return false;

return Object.values(row)
.filter(val => val) // Filter out empty/undefined properties
.length > 0; // If one field has error, the whole group (dynamicList) is invalid
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might also need to be fixed in CreateContainerModal.


// If at least one group is invalid, then the whole form is invalid
return validationFailed.publish?.some(groupHasError) ||
return validationFailed.publish?.some(publishGroupHasError) ||
!!validationFailed.podName;
};

Expand All @@ -129,7 +137,7 @@ export const PodCreateModal = ({ user, systemServiceAvailable, userServiceAvaila
};
});
if (publishValidation.some(entry => entry && Object.keys(entry).length > 0))
newValidationFailed.publish = publishValidation.filter(entry => entry !== undefined);
newValidationFailed.publish = publishValidation;

const podNameValidation = validatePodName(podName);

Expand Down
4 changes: 0 additions & 4 deletions test/check-application
Original file line number Diff line number Diff line change
Expand Up @@ -2942,13 +2942,9 @@ class TestApplication(testlib.MachineCase):
b.wait_visible(container_1_sel + " .ct-badge-toolbox:contains('toolbox')")
b.wait_visible(container_2_sel + " .ct-badge-distrobox:contains('distrobox')")

# this isn't *really* a Firefox bug, but the different timing just triggers this a lot
# https://github.com/cockpit-project/cockpit-podman/issues/1836
@testlib.skipBrowser("pod dialog state management is broken", "firefox")
def testCreatePodSystem(self):
self._createPod(True)

@testlib.skipBrowser("pod dialog state management is broken", "firefox")
def testCreatePodUser(self):
self._createPod(False)

Expand Down