Skip to content
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 1879875: Fix that the Start Pipeline form is not always validated correctly #6673

Merged
merged 1 commit into from Sep 29, 2020

Conversation

jerolimov
Copy link
Member

Fixes:
https://issues.redhat.com/browse/ODC-4364
https://bugzilla.redhat.com/show_bug.cgi?id=1879875

Analysis / Root cause:
When switching between different volume types in start pipeline modal and switching back to a valid volume type the "start" button is still disabled. This happen because Formik does not remove the errors when the user switches from "Empty Directory" to "Secret" and "Empty Directory" again.

The error was set to an invalidate state because the form was validated multiple times with the old and the new form fields.

To check how often and in which order the schema validation was called, you can add a console.warn (for example) output to volumeTypeSchema in frontend/packages/dev-console/src/components/pipelines/modals/common/validation-utils.ts. Like this one:

const volumeTypeSchema = yup
  .object()
  .when('type', {
-    is: (type) => VolumeTypes[type] === VolumeTypes.Secret,
+    is: (type) => {
+      console.warn('Validate pipeline form', type);
+      return VolumeTypes[type] === VolumeTypes.Secret,
+    }
    then: yup.object().shape({

Solution Description:
The problem is based on the order of changes to the form. The Workspace type dropdown uses the DropdownField onChange prop to clear the workspace.data. But the DropdownField itself sets the type field after this change. Both method calls automatically triggers a form validation.

See DropdownField onChange:

onChange={(value: string) => {
props.onChange && props.onChange(value);
setFieldValue(props.name, value);
setFieldTouched(props.name, true);
}}

The form was also additional changed each time when the value of a DropdownField changes:

All these calls triggers an asynchronous form validation with old and new data which confuses the form error state.

As solution I added an 3rd parameter to the setFieldValue and setFieldTouched calls to disable that the fields are marked as "needs revalidation". The revalidation was now only triggered by the already used useFormikValidationFix hook.

⚠️ Component compatibility and alternatives

Alternative 1
Component tree:

  StartPipelineTree
    ..
    PipelineWorkspacesSection
      console-shared/formik-fields/components/DropdownField (to select the workspace type)
        console/internal/components/Dropdown
      MultipleResourceKeySelector (if workspace type = ConfigMap or Secret)

Also if this is a really small code change this affects the widely used DropdownField component.

As alternative its also possible to change just the PiplelineWorkspacesSection component instead. Instead of using the DropdownField this component could directly use the Dropdown to keep the same UI, but handle the formik state (calling setFieldValue in onChange) itself.

@divyanshiGupta WDYT?

Alternative 2
When starting with the analyse of this issue, I expected that the problem cause is that the data was removed and the errors for removed data wasn't re-validated. My initial idea was then to not save the sub-data (config / secretMap) in one data field and use different sub-keys instead.

This also fixes that the entered data was removed when the user switches between the types. I expected that this is also a (small) issue because we have different issues like ODC-2443 which says that form fields shouldn't be cleared when switching such a type selection.

But after implementing this I noticed that the original issue (could not submit form with Empty Directory after selecting ConfigMap) still exists. This also requires this code change I proposed with this PR here, or the Alternative 1.

The much bigger change looks like this: master...jerolimov:odc-4364-fix-datadrop

@divyanshiGupta WDYT? Should we change this here as well or should we change / fix this after we start 4.7?

Screen shots / Gifs for design review:
odc-4364 webm

Unit test coverage report:
Unchanged

Test setup:
Unchanged

Browser conformance:

  • Chrome
  • Firefox
  • Safari
  • Edge

@openshift-ci-robot openshift-ci-robot added the bugzilla/severity-low Referenced Bugzilla bug's severity is low for the branch this PR is targeting. label Sep 18, 2020
@openshift-ci-robot
Copy link
Contributor

@jerolimov: This pull request references Bugzilla bug 1879875, 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.

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

In response to this:

Bug 1879875: Fix that the Start Pipeline form is not always validated correctly

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-ci-robot openshift-ci-robot added 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 labels Sep 18, 2020
@openshift-ci-robot openshift-ci-robot added the component/shared Related to console-shared label Sep 18, 2020
@jerolimov
Copy link
Member Author

/assign @divyanshiGupta

@jerolimov
Copy link
Member Author

/kind bug

@openshift-ci-robot openshift-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Sep 18, 2020
@divyanshiGupta
Copy link
Contributor

@jerolimov I think explicitly setting the revalidation prop to false in DropdownField setFieldValue and setFieldTouched should be fine since we are already doing the validation using useFormikValidationFix hook or either we keep it as true and remove the hook, anyways the validation should happen only once when the field value changes.

I have tested these changes against a few usecases including this one and it seemed to work fine without breaking anything. I will also recommend you to test it against other usecases just to be sure.

@rohitkrai03 wdyt?

Copy link
Contributor

@andrewballantyne andrewballantyne left a comment

Choose a reason for hiding this comment

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

I also investigated this, and I agree with what Christoph as come up with.

I'll wait until EOD Monday before giving this a LGTM. @rohitkrai03 please carve out a moment on Monday to think about this; we need to start closing PRs for the coming Code Freeze so this cannot stay open much longer.

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 25, 2020
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.

/lgtm

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andrewballantyne, jerolimov, rohitkrai03

The full list of commands accepted by this bot can be found here.

The pull request process is described here

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

@openshift-merge-robot openshift-merge-robot merged commit fd087cc into openshift:master Sep 29, 2020
@openshift-ci-robot
Copy link
Contributor

@jerolimov: All pull requests linked via external trackers have merged:

Bugzilla bug 1879875 has been moved to the MODIFIED state.

In response to this:

Bug 1879875: Fix that the Start Pipeline form is not always validated correctly

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.6 milestone Sep 30, 2020
@jerolimov
Copy link
Member Author

/cherry-pick release-4.5

@openshift-cherrypick-robot

@jerolimov: new pull request created: #6853

In response to this:

/cherry-pick release-4.5

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.

@jerolimov jerolimov deleted the odc-4364 branch August 7, 2023 11:20
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/severity-low Referenced Bugzilla bug's severity is low for the branch this PR is targeting. 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 component/shared Related to console-shared kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants