Skip to content

refactor: curry GetFormHelpers #1156

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

Merged
merged 1 commit into from
Apr 25, 2022
Merged

refactor: curry GetFormHelpers #1156

merged 1 commit into from
Apr 25, 2022

Conversation

presleyp
Copy link
Contributor

Changes getFormHelpers to take two arguments and return a function that takes one argument, so we don't have to repeat args as much. Also adds test coverage for using API errors in the form. In keeping with the existing code, I show the API error if we have both, but I don't have a strong opinion on it.

@presleyp presleyp requested a review from a team as a code owner April 25, 2022 19:31
@presleyp presleyp self-assigned this Apr 25, 2022
@codecov
Copy link

codecov bot commented Apr 25, 2022

Codecov Report

Merging #1156 (52bd3c8) into main (a2dd618) will increase coverage by 0.19%.
The diff coverage is 86.45%.

@@            Coverage Diff             @@
##             main    #1156      +/-   ##
==========================================
+ Coverage   66.24%   66.43%   +0.19%     
==========================================
  Files         255      263       +8     
  Lines       16120    16426     +306     
  Branches      156      156              
==========================================
+ Hits        10678    10912     +234     
- Misses       4335     4390      +55     
- Partials     1107     1124      +17     
Flag Coverage Δ
unittest-go-macos-latest 53.93% <86.41%> (?)
unittest-go-postgres- 65.84% <86.41%> (+0.20%) ⬆️
unittest-go-ubuntu-latest 56.39% <86.41%> (+0.04%) ⬆️
unittest-go-windows-2022 53.47% <86.41%> (?)
unittest-js 67.42% <86.66%> (+0.13%) ⬆️
Impacted Files Coverage Δ
coderd/audit/table.go 77.77% <77.77%> (ø)
site/src/util/formUtils.ts 88.88% <84.61%> (+3.17%) ⬆️
coderd/audit/diff.go 86.56% <86.56%> (ø)
cli/configssh.go 69.23% <100.00%> (+7.81%) ⬆️
coderd/coderd.go 97.48% <100.00%> (ø)
coderd/users.go 60.36% <100.00%> (ø)
.../PreferencesAccountForm/PreferencesAccountForm.tsx 100.00% <100.00%> (ø)
site/src/components/SignInForm/SignInForm.tsx 100.00% <100.00%> (ø)
provisionersdk/serve.go 35.13% <0.00%> (-8.11%) ⬇️
provisioner/echo/serve.go 54.40% <0.00%> (-2.40%) ⬇️
... and 14 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 6434888...52bd3c8. Read the comment docs.

@@ -49,29 +49,30 @@ export const AccountForm: React.FC<AccountFormProps> = ({
validationSchema,
onSubmit,
})
const getFieldHelpers = getFormHelpers<AccountFormValues>(form, formErrors)
Copy link
Contributor

Choose a reason for hiding this comment

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

praise: I love this solution, the curry is very clean and reminds me of an improvement upon the old wrappers!

// getIn is a util function from Formik that gets at any depth of nesting
// and is necessary for the types to work
const touched = getIn(form.touched, name)
const apiError = getIn(formErrors, name)
Copy link
Contributor

Choose a reason for hiding this comment

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

praise: improve var name

@presleyp presleyp merged commit bdc17f4 into main Apr 25, 2022
@presleyp presleyp deleted the form-helpers/presleyp branch April 25, 2022 19:45
@misskniss misskniss added this to the V2 Beta milestone May 15, 2022
kylecarbs pushed a commit that referenced this pull request Jun 10, 2022
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.

3 participants