Skip to content

Clone values to prevent infinite loop and fix edge case in QuayIntegrationForm#2996

Merged
pedrottimark merged 1 commit intomasterfrom
QuayIntegrationForm-clone-initialValues
Sep 7, 2022
Merged

Clone values to prevent infinite loop and fix edge case in QuayIntegrationForm#2996
pedrottimark merged 1 commit intomasterfrom
QuayIntegrationForm-clone-initialValues

Conversation

@pedrottimark
Copy link
Contributor

Description

  1. Nakul found that QuayIntegrationForm can get stuck in an infinite loop of rendering.
    Scenario: Change only oauthToken value.
    Hypothesis: if (initialValues) { … } within the component looks like a side-effect (with shallow spread instead of deep clone) which I probably changed from naughty to nasty in ROX-12450: Support robot accounts in Quay integration form #2974
    Solution:

    • Factor out pure computeInitialValues function and call it only one time (if needed) to initialize useIntegrationForm hook.
    • Replace { ...initialValues } with cloneDeep(initialValues) because updatePassword logic did not work correctly without the change. This strengthens my feeling that the additional imperative assignment statements changed the code from brittle to broken.
    • Therefore also call cloneDeep(defaultValues) to create a new integration.
  2. I found an edge case which needed improved frontend logic.
    Scenario: Edit an existing integration to clear Robot username and password causes registryRobotCredentials: {username: "", password: ""} to fail backend validation.
    Solution:

    • Add onChangeRobotUsername and onChangeRobotPassword to set registryRobotCredentials: null if both values are empty.

Residue

  1. Change from another type with robot account to Scanner has correct conditional rendering, but will fail backend validation. I will leave well enough alone for now.

Checklist

  • Investigated and inspected CI test results
  • Unit test and regression tests added

Testing Performed

  1. Create new integration with Scanner type and OAuth token value. Save it without page crash

  2. Create new integration with Registry + Scanner type and provide all credentials. Save it. Edit to clear Robot username field. Save it and see correct registryRobotCredentials: null instead of incorrect registryRobotCredentials: {username: "", password: ""} value.

Copy link
Contributor

@vjwilson vjwilson left a comment

Choose a reason for hiding this comment

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

Oy vey!

@ghost
Copy link

ghost commented Sep 7, 2022

Images are ready for the commit at 4bb65cc.

To use with deploy scripts, first export MAIN_IMAGE_TAG=3.71.x-510-g4bb65ccefd.

@openshift-ci
Copy link

openshift-ci bot commented Sep 7, 2022

@pedrottimark: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/gke-ui-e2e-tests 4bb65cc link false /test gke-ui-e2e-tests

Full PR test history. Your PR dashboard.

Details

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. I understand the commands that are listed here.

@pedrottimark pedrottimark merged commit 2b5983b into master Sep 7, 2022
@pedrottimark pedrottimark deleted the QuayIntegrationForm-clone-initialValues branch September 7, 2022 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants