Skip to content

Conversation

@divyanshiGupta
Copy link
Contributor

Jira Issue - https://issues.redhat.com/browse/ODC-2905

Fix-
route-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.

@openshift-ci-robot openshift-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jan 30, 2020
@divyanshiGupta
Copy link
Contributor Author

/kind bug

@openshift-ci-robot openshift-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Jan 30, 2020
@openshift-ci-robot openshift-ci-robot added the component/dev-console Related to dev-console label Jan 30, 2020
@divyanshiGupta divyanshiGupta changed the title Set target-port as the first port when route target-port is empty Bug 1798404: Set target-port as the first port when route target-port is empty Feb 5, 2020
@openshift-ci-robot openshift-ci-robot added the bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. label Feb 5, 2020
@openshift-ci-robot
Copy link
Contributor

@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.

Details

In response to this:

Bug 1798404: Set target-port as the first port when route target-port is empty

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 divyanshiGupta changed the title Bug 1798404: Set target-port as the first port when route target-port is empty Bug 1798404: Set target-port as the first port when route target-port is empty in edit forms Feb 6, 2020
@divyanshiGupta divyanshiGupta changed the title Bug 1798404: Set target-port as the first port when route target-port is empty in edit forms [WIP]Bug 1798404: Set target-port as the first port when route target-port is empty in edit forms Feb 10, 2020
@openshift-ci-robot openshift-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Feb 10, 2020
@divyanshiGupta divyanshiGupta changed the title [WIP]Bug 1798404: Set target-port as the first port when route target-port is empty in edit forms Bug 1798404: Set target-port as the first port when route target-port is empty in edit forms Feb 12, 2020
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 12, 2020
Comment on lines 95 to 99
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@christianvogt christianvogt Feb 14, 2020

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@rohitkrai03
Copy link
Contributor

/assign

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const targetPort = !initialValues.route.targetPort && _.head(ports);
const targetPort = (!initialValues.route.targetPort || touched.searchTerm) && _.head(ports);

Comment on lines 95 to 99
Copy link
Contributor

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.

@spadgett
Copy link
Member

/bugzilla refresh

@openshift-ci-robot openshift-ci-robot added bugzilla/invalid-bug Indicates that a referenced Bugzilla bug is invalid for the branch this PR is targeting. and removed bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. labels Feb 20, 2020
@openshift-ci-robot
Copy link
Contributor

@spadgett: This pull request references Bugzilla bug 1798404, which is invalid:

  • expected the bug to target the "4.5.0" release, but it targets "4.4.0" instead

Comment /bugzilla refresh to re-evaluate validity if changes to the Bugzilla bug are made, or edit the title of this pull request to link to a different bug.

Details

In response to this:

/bugzilla refresh

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
Copy link
Contributor

rohitkrai03 commented Feb 26, 2020

@divyanshiGupta This PR - #4187 replaced InputSearchField with InputField. In that process it lost the ability to update touched.searchTerm since it's handling the onBlur itself. So, now the logic of relying on the touched.searchTerm is broken unless we fix the issue mentioned above. You can fix it by calling setFieldTouched in the onBlur handler but that would mean that even when the form loads for the first time it will set touched to true. So my suggestion is to change the passing of handleSearch to onBlur like this -

onBlur={() => {
  handleSearch();
  setFieldTouched('searchTerm', true);
}}

@rohitkrai03
Copy link
Contributor

Everything works as expected after applying the above fix for external image registry edit flow.

Copy link
Contributor

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.

Copy link
Contributor

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.

@divyanshiGupta
Copy link
Contributor Author

/bugzilla refresh

@openshift-ci-robot openshift-ci-robot added bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. and removed bugzilla/invalid-bug Indicates that a referenced Bugzilla bug is invalid for the branch this PR is targeting. labels Feb 28, 2020
@openshift-ci-robot
Copy link
Contributor

@divyanshiGupta: This pull request references Bugzilla bug 1798404, which is valid.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target release (4.5.0) matches configured target release for branch (4.5.0)
  • bug is in the state POST, which is one of the valid states (NEW, ASSIGNED, ON_DEV, POST, POST)
Details

In response to this:

/bugzilla refresh

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.

Copy link
Contributor

@rohitkrai03 rohitkrai03 left a comment

Choose a reason for hiding this comment

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

/approve

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 28, 2020
@karthikjeeyar
Copy link
Contributor

verified locally, works fine
/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Feb 28, 2020
@karthikjeeyar
Copy link
Contributor

/retest

@openshift-ci-robot
Copy link
Contributor

[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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@divyanshiGupta
Copy link
Contributor Author

/cherry-pick release-4.4

@openshift-cherrypick-robot

@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.

Details

In response to this:

/cherry-pick release-4.4

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.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

1 similar comment
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-merge-robot openshift-merge-robot merged commit 7c0eb9c into openshift:master Feb 28, 2020
@openshift-ci-robot
Copy link
Contributor

@divyanshiGupta: All pull requests linked via external trackers have merged. Bugzilla bug 1798404 has been moved to the MODIFIED state.

Details

In response to this:

Bug 1798404: Set target-port as the first port when route target-port is empty in edit forms

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.

@openshift-cherrypick-robot

@divyanshiGupta: new pull request created: #4561

Details

In response to this:

/cherry-pick release-4.4

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.

@spadgett spadgett added this to the v4.5 milestone Mar 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. component/dev-console Related to dev-console kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants