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

Refactor form validation #2704

Merged
merged 6 commits into from
Feb 8, 2021
Merged

Refactor form validation #2704

merged 6 commits into from
Feb 8, 2021

Conversation

bjoernricks
Copy link
Contributor

@bjoernricks bjoernricks commented Feb 5, 2021

What:

Refactor the form validation.

Why:

After looking at the rows per page user setting for a bugfix I had a quick look at the useFormValidation hook. The original version had a major downside by tying to synchronize states. This should always be avoided. State should be handled at one place only.

How:

Added new tests and run all other unit tests.

Checklist:

This hook might replace all StateDialog state handling in future. It
stores an object, has a function to update the state with value and name
and only re-renders if the state is changed.
Remove the synchronization of state. This is always a problem and should
be avoided. The whole state must be handled outside of
useFormValidation.

Validation functions now get the new value and the state (all other
values) as a second parameter. The function must either return a string
as an error message to display a errornous validation or undefined to
indicate that the validation was successful. Alternatively an exception
may be thrown to indicate an error.

Only return on object that has three properties:
1. hasError to indicate that an error during the validation
2. errors an object of error messages
3. validate a function to check validate the form as a whole (sets
   hasError)
Update the functions to the new expected return values. Also always use
arrow functions.
Adjust current forms that are using the useFormValidation hook to use
the new contract.
@bjoernricks bjoernricks requested a review from saberlynx February 5, 2021 11:40
@bjoernricks bjoernricks marked this pull request as ready for review February 5, 2021 11:41
@bjoernricks bjoernricks requested a review from a team February 5, 2021 11:41
@codecov
Copy link

codecov bot commented Feb 5, 2021

Codecov Report

Merging #2704 (ec12e07) into gsa-21.04 (34466a4) will increase coverage by 0.12%.
The diff coverage is 100.00%.

Impacted file tree graph

@@              Coverage Diff              @@
##           gsa-21.04    #2704      +/-   ##
=============================================
+ Coverage      53.71%   53.84%   +0.12%     
=============================================
  Files           1072     1074       +2     
  Lines          26223    26206      -17     
  Branches        7474     7471       -3     
=============================================
+ Hits           14086    14110      +24     
+ Misses         11019    10980      -39     
+ Partials        1118     1116       -2     
Impacted Files Coverage Δ
gsa/src/gmp/cancel.js 100.00% <ø> (ø)
gsa/src/gmp/capabilities/capabilities.js 100.00% <ø> (ø)
gsa/src/gmp/capabilities/everything.js 100.00% <ø> (ø)
gsa/src/gmp/collection/collectioncounts.js 82.60% <ø> (ø)
gsa/src/gmp/collection/parser.js 61.70% <ø> (ø)
gsa/src/gmp/command.js 100.00% <ø> (ø)
gsa/src/gmp/commands/alerts.js 14.28% <ø> (ø)
gsa/src/gmp/commands/audits.js 52.45% <ø> (ø)
gsa/src/gmp/commands/auth.js 100.00% <ø> (ø)
gsa/src/gmp/commands/certbund.js 63.63% <ø> (ø)
... and 261 more

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 fa04ee4...e8e1795. Read the comment docs.

@bjoernricks bjoernricks enabled auto-merge February 5, 2021 11:56
Copy link
Contributor

@saberlynx saberlynx left a comment

Choose a reason for hiding this comment

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

This looks awesome!

@bjoernricks bjoernricks merged commit ca875cf into greenbone:gsa-21.04 Feb 8, 2021
@bjoernricks bjoernricks deleted the refactor-form-validation branch February 8, 2021 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants