-
Notifications
You must be signed in to change notification settings - Fork 90
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
martinpitt
merged 4 commits into
cockpit-project:main
from
mvollmer:fix-pod-create-dialog-validation
Oct 18, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
41ddefd
pods: Don't mutate the state object in PodCreateModal
mvollmer 4817217
pods: Keep ports aligned with their errors in PodCreateModal
mvollmer 8f541dd
pods: Always ignore validation errors for empty slots in PodCreateModal
mvollmer 0f7cccb
test: Run pod creation tests also on Firefox
mvollmer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
}); | ||
}; | ||
|
||
|
@@ -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 | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
}; | ||
|
||
|
@@ -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); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.