-
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
pods: Fix PodCreateModal validation issues #1884
Conversation
We need to construct a new one. Otherwise React will assume that the state hasn't actually changed. This might have worked by accident in the past, but React is clear that you should not mutate old state objects.
The "publish" and "validationFailed.publish" arrays must always be aligned. The "validateForm" function was erronously filtering out undefined entries in validationFailed.publish. Those undefined entries correspond to empty slots in the "publish" array and are left behind by the DynamicListForm component when removing rows in the UI. It does that for its own convenience and we must respect that. The observable result of filtering out these entries was that validation errors would shift to unrelated publish entries. If that unrelated entry was a empty slot, it would thereafter never be updated and keep its validation error forever, which would keep the "Create" button disabled forever.
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 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.
Here is a step-by-step play-through of the bug re keeping publish and validationFailed aligned. The value shown come from JSON.stringify, so "undefined" and "empty slot" show as "null".
|
Since the tests don't actually remove ports in the dialog, I think all the flakiness was caused by the bug in |
0b5f3c7
to
45a0fe4
Compare
Oh, they do, sorry. |
The failures on TF were cause by its relative slowness, I think: Validation functions run after 500ms, and when they deliver their result for a row that has since been removed, isFormInvalid will still look at them and disable the button. My theory is that in our own CI we are done with the whole dialog in less than 500ms, but TF is so slow that it gets hit with that bug. |
45a0fe4
to
2b00fee
Compare
They might show up when the port row is removed before the debounced validation has actually run.
That should work now.
2b00fee
to
0f7cccb
Compare
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 comment
The reason will be displayed to describe this comment to others. Learn more.
This added line is not executed by any test.
I guess I look at the TestApplication.testCreateContainerInPodUser flakes next. |
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 comment
The reason will be displayed to describe this comment to others. Learn more.
This might also need to be fixed in CreateContainerModal.
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.
Awesome, thanks! Even if there are still other races left, these are all good and important fixes, so let's get them in.
I have found four issues:
<TextInput type="number" />
does not usefully distinguish between empty strings and strings that are not numbers, and it sends fewer change notifications than expected. For example, starting to type random letters into a previously empty field will produce no change events and we get no opportunity to run our validation code.