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

Run validation with updated resource values #139

Merged
merged 1 commit into from
Jul 19, 2022

Conversation

rottencandy
Copy link
Contributor

Fixes

https://issues.redhat.com/browse/HAC-1286

Description

Bug in formik causes validation to happen on the previous value instead of the updated value when setFieldTouched is used.

I tried all workarounds from jaredpalmer/formik#2083 but this is the only one that worked.

Type of change

  • Feature
  • Bugfix
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

Screen shots / Gifs for design review

recording-1657203827.mp4

How to test or reproduce?

Try to add negative values in resource limit field.

Browser conformance:

  • Chrome
  • Firefox
  • Safari
  • Edge

@openshift-ci openshift-ci bot requested review from invincibleJai and jrichter1 July 7, 2022 14:34
@codecov
Copy link

codecov bot commented Jul 7, 2022

Codecov Report

Merging #139 (67427c6) into main (da444ef) will increase coverage by 1.60%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #139      +/-   ##
==========================================
+ Coverage   59.27%   60.88%   +1.60%     
==========================================
  Files         236      239       +3     
  Lines        4533     4704     +171     
  Branches     1079     1125      +46     
==========================================
+ Hits         2687     2864     +177     
+ Misses       1753     1747       -6     
  Partials       93       93              
Impacted Files Coverage Δ
...ed/components/formik-fields/ResourceLimitField.tsx 81.81% <0.00%> (ø)
src/pages/ApplicationsPage.tsx 0.00% <0.00%> (ø)
src/hacbs/components/topology/topology-utils.ts 88.63% <0.00%> (ø)
...components/topology/__data__/pipeline-test-data.ts 100.00% <0.00%> (ø)
src/hacbs/components/topology/dag.ts 94.93% <0.00%> (ø)
src/shared/components/timestamp/datetime.ts 43.02% <0.00%> (+10.46%) ⬆️
src/shared/components/pipeline-run-logs/utils.ts 48.30% <0.00%> (+11.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update da444ef...67427c6. Read the comment docs.

@rottencandy
Copy link
Contributor Author

/retest

@rottencandy
Copy link
Contributor Author

/cc @sahil143 @rohitkrai03

@openshift-ci openshift-ci bot requested review from rohitkrai03 and sahil143 July 7, 2022 15:07
@rottencandy
Copy link
Contributor Author

/retest

@@ -34,6 +35,8 @@ const ResourceLimitField: React.FC<ResourceLimitFieldProps> = ({
setFieldValue(props.name, val.value);
setFieldTouched(props.name, true);
setFieldValue(unitName, val.unit);
// run validation manually so that formik uses the latest value
validateForm(set(values, props.name, val.value));
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe just validate the field with validateField?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tried validateField, it's still using the old value.

@rottencandy
Copy link
Contributor Author

/retest

@rottencandy rottencandy force-pushed the fix/late-validation branch from dafbc09 to 878caa3 Compare July 14, 2022 07:26
@rohitkrai03
Copy link
Contributor

/retest

@rottencandy rottencandy force-pushed the fix/late-validation branch 3 times, most recently from 44429f2 to 73c69ba Compare July 15, 2022 09:44
@rottencandy
Copy link
Contributor Author

/retest

@rottencandy rottencandy force-pushed the fix/late-validation branch from 73c69ba to 2b6e9cc Compare July 18, 2022 11:59
@rottencandy
Copy link
Contributor Author

/retest

@rottencandy rottencandy force-pushed the fix/late-validation branch from 2b6e9cc to cafd9ce Compare July 18, 2022 16:46
@@ -31,6 +32,8 @@ const ResourceLimitField: React.FC<ResourceLimitFieldProps> = ({
<RequestSizeInput
{...props}
onChange={(val) => {
// run validation manually so that formik uses the latest value
validateForm(set(values, props.name, val.value));
setFieldValue(props.name, val.value);
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you tried this workaround? I tried it and it works for me.

Suggested change
setFieldValue(props.name, val.value);
setTimeout(() => setFieldValue(props.name, val.value));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Updated

@rottencandy rottencandy force-pushed the fix/late-validation branch from cafd9ce to 67427c6 Compare July 19, 2022 06:41
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 19, 2022

@rottencandy: all tests passed!

Full PR test history. Your PR dashboard.

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.

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
/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jul 19, 2022
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 19, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rohitkrai03, rottencandy

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-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 19, 2022
@rohitkrai03 rohitkrai03 merged commit 32f3e20 into openshift:main Jul 19, 2022
@rottencandy rottencandy deleted the fix/late-validation branch August 30, 2022 16:14
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. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants