-
Notifications
You must be signed in to change notification settings - Fork 670
Bug 1798404: Set target-port as the first port when route target-port is empty in edit forms #4123
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
Bug 1798404: Set target-port as the first port when route target-port is empty in edit forms #4123
Conversation
|
/kind bug |
|
@divyanshiGupta: This pull request references Bugzilla bug 1798404, which is valid. The bug has been moved to the POST state. The bug has been updated to refer to the pull request using the external bug tracker. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
frontend/packages/dev-console/src/components/import/image-search/ImageSearch.tsx
Outdated
Show resolved
Hide resolved
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.
You've got 2 form fields now resetting the value of initialValues.route.targetPort creating a race condition.
My suggestion would be to track first load vs subsequent loads. The value can be stored in a ref:
const canUpdateTargetPort = React.useRef(!initialValues.route.targetPort)
You'd need to do this in each form field that uses this value.
Then once first load is complete do canUpdateTargetPort.current = true.
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.
So in this file initialValues.route.targetPort is getting re-initialized only once in line 97 whenever we have a new searchTerm. No other field resets its value, everywhere else values.route.targetPort is set and that does not affect initialValues.route.targetPort. Did you find any use case where you saw the race condition? I might be missing something.
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.
My mistake. I mistook the other file as being in the same flow. But it's for the 2nd radio option so it wouldn't be an issue.
Changing the initial value just seems a bit odd to me even though it's working.
Did you consider just checking if the target port is found in the set of ports? And only if it isn't use the first available port? Would there be an issue with doing this? That way we don't have to mutate the initial value.
The side effect here is if they change the target port for one image search, then search again and that same target port is available, but not first in the list; it would keep that selection. Not sure if that's ok though.
Another thought is to check if the field is touched or not and if not use the initial value. Immediately after checking you can force set the field touched so that we don't use the initial value ever again.
Lastly if clearing the initial value as you are doing is the only thing that works. You can probably do this immediately after assigning the target port and not in a useEffect to simplify things.
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.
So I went through a few examples where it was needed to change the initial values and hence we have enableReinitialize which when set to true lets us change the initial values. Anyways I'll go through the other approaches you suggested.
Another thought is to check if the field is touched or not and if not use the initial value. Immediately after checking you can force set the field touched so that we don't use the initial value ever again.
Will try this one and see if it works.
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.
@divyanshiGupta This combined with my suggestion above should work as a workaround here -
React.useEffect(() => {
if (touched.searchTerm && initialValues.searchTerm !== values.searchTerm) {
const targetPort: ContainerPort = _.head(values.isi.ports);
targetPort && setFieldValue('route.targetPort', makePortName(targetPort));
}
}, [
touched.searchTerm,
setFieldValue,
values.isi.ports,
initialValues.searchTerm,
values.searchTerm,
]);The only issue I found with this approach was that if a user starts to update the searchTerm after searching for an image before, the target port resets to head. I can't think of a scenario where this would cause any real problems for user though. If a user is changing the searchTerm, he intents to update the container image which should reset the ports.
|
/assign |
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.
| const targetPort = !initialValues.route.targetPort && _.head(ports); | |
| const targetPort = (!initialValues.route.targetPort || touched.searchTerm) && _.head(ports); |
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.
@divyanshiGupta This combined with my suggestion above should work as a workaround here -
React.useEffect(() => {
if (touched.searchTerm && initialValues.searchTerm !== values.searchTerm) {
const targetPort: ContainerPort = _.head(values.isi.ports);
targetPort && setFieldValue('route.targetPort', makePortName(targetPort));
}
}, [
touched.searchTerm,
setFieldValue,
values.isi.ports,
initialValues.searchTerm,
values.searchTerm,
]);The only issue I found with this approach was that if a user starts to update the searchTerm after searching for an image before, the target port resets to head. I can't think of a scenario where this would cause any real problems for user though. If a user is changing the searchTerm, he intents to update the container image which should reset the ports.
|
/bugzilla refresh |
|
@spadgett: This pull request references Bugzilla bug 1798404, which is invalid:
Comment DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
@divyanshiGupta This PR - #4187 replaced onBlur={() => {
handleSearch();
setFieldTouched('searchTerm', true);
}} |
|
Everything works as expected after applying the above fix for external image registry edit flow. |
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.
While changing the imagestream if there are more than one ports and user changes target port explicitly in the route advanced options, the target port is reset to the first port in the list of available ports.
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.
Maybe add another check for targetPort not being touched by user. Then only it should update the value.
|
/bugzilla refresh |
|
@divyanshiGupta: This pull request references Bugzilla bug 1798404, which is valid. 3 validation(s) were run on this bug
DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
rohitkrai03
left a comment
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.
/approve
|
verified locally, works fine |
|
/retest |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: divyanshiGupta, karthikjeeyar, rohitkrai03 The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/cherry-pick release-4.4 |
|
@divyanshiGupta: once the present PR merges, I will cherry-pick it on top of release-4.4 in a new PR and assign it to you. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
/retest Please review the full test history for this PR and help us cut down flakes. |
1 similar comment
|
/retest Please review the full test history for this PR and help us cut down flakes. |
|
@divyanshiGupta: All pull requests linked via external trackers have merged. Bugzilla bug 1798404 has been moved to the MODIFIED state. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
@divyanshiGupta: new pull request created: #4561 DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Jira Issue - https://issues.redhat.com/browse/ODC-2905
Fix-

Edit flows are currently broken because of this issue - https://issues.redhat.com/browse/ODC-2853
PR for the fix - #4087
For testing this PR locally the above PR is needed.