From e0a6aea82c052c54bb0321ae14bdf382a8147d01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Mon, 30 Aug 2021 11:45:42 +0200 Subject: [PATCH] fix up types and rebase MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- .changeset/hip-beers-attend.md | 7 +++++++ .../src/components/ImportStepper/defaults.tsx | 10 ++++----- .../PreparePullRequestForm.test.tsx | 4 ++-- .../PreparePullRequestForm.tsx | 21 +++++++------------ .../StepPrepareCreatePullRequest.tsx | 18 ++++++++++------ plugins/cloudbuild/package.json | 1 - plugins/shortcuts/package.json | 2 +- yarn.lock | 2 +- 8 files changed, 36 insertions(+), 29 deletions(-) create mode 100644 .changeset/hip-beers-attend.md diff --git a/.changeset/hip-beers-attend.md b/.changeset/hip-beers-attend.md new file mode 100644 index 0000000000..802bfe7397 --- /dev/null +++ b/.changeset/hip-beers-attend.md @@ -0,0 +1,7 @@ +--- +'@backstage/core-components': patch +'@backstage/plugin-catalog-import': patch +'@backstage/plugin-shortcuts': patch +--- + +Bumped `react-hook-form` to `^7.12.2` diff --git a/plugins/catalog-import/src/components/ImportStepper/defaults.tsx b/plugins/catalog-import/src/components/ImportStepper/defaults.tsx index a5ae352d5a..79d859ce32 100644 --- a/plugins/catalog-import/src/components/ImportStepper/defaults.tsx +++ b/plugins/catalog-import/src/components/ImportStepper/defaults.tsx @@ -188,7 +188,7 @@ export function defaultGenerateStepper( renderFormFields={({ values, setValue, - errors, + formState, groupsLoading, groups, register, @@ -209,7 +209,7 @@ export function defaultGenerateStepper( margin="normal" variant="outlined" fullWidth - error={Boolean(errors.title)} + error={Boolean(formState.errors.title)} required /> @@ -224,7 +224,7 @@ export function defaultGenerateStepper( margin="normal" variant="outlined" fullWidth - error={Boolean(errors.body)} + error={Boolean(formState.errors.body)} multiline required /> @@ -242,14 +242,14 @@ export function defaultGenerateStepper( margin="normal" variant="outlined" fullWidth - error={Boolean(errors.componentName)} + error={Boolean(formState.errors.componentName)} required /> {!values.useCodeowners && ( ', () => { const { queryByText, getByRole } = render( defaultValues={{}} - render={({ errors, register }) => ( + render={({ formState, register }) => ( <> - {errors.main && ( + {formState.errors.main && ( Error in required main field diff --git a/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/PreparePullRequestForm.tsx b/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/PreparePullRequestForm.tsx index 14cd21bae6..616e77518c 100644 --- a/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/PreparePullRequestForm.tsx +++ b/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/PreparePullRequestForm.tsx @@ -19,20 +19,20 @@ import { SubmitHandler, UnpackNestedValue, useForm, - UseFormMethods, - UseFormOptions, + UseFormProps, + UseFormReturn, } from 'react-hook-form'; type Props> = Pick< - UseFormOptions, + UseFormProps, 'defaultValues' > & { onSubmit: SubmitHandler; render: ( props: Pick< - UseFormMethods, - 'errors' | 'register' | 'control' + UseFormReturn, + 'formState' | 'register' | 'control' | 'setValue' > & { values: UnpackNestedValue; }, @@ -55,17 +55,12 @@ export const PreparePullRequestForm = < onSubmit, render, }: Props) => { - const { - handleSubmit, - watch, - control, - register, - formState: { errors }, - } = useForm({ mode: 'onTouched', defaultValues }); + const { handleSubmit, watch, control, register, formState, setValue } = + useForm({ mode: 'onTouched', defaultValues }); return (
- {render({ values: watch(), errors, register, control })} + {render({ values: watch(), formState, register, control, setValue })}
); }; diff --git a/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.tsx b/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.tsx index 0f298c7202..52afcdaf83 100644 --- a/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.tsx +++ b/plugins/catalog-import/src/components/StepPrepareCreatePullRequest/StepPrepareCreatePullRequest.tsx @@ -23,7 +23,7 @@ import { import { Box, FormHelperText, Grid, Typography } from '@material-ui/core'; import { makeStyles } from '@material-ui/core/styles'; import React, { useCallback, useState } from 'react'; -import { FieldErrors, UnpackNestedValue, UseFormReturn } from 'react-hook-form'; +import { UnpackNestedValue, UseFormReturn } from 'react-hook-form'; import { useAsync } from 'react-use'; import YAML from 'yaml'; import { AnalyzeResult, catalogImportApiRef } from '../../api'; @@ -63,8 +63,10 @@ type Props = { defaultBody: string; renderFormFields: ( - props: Pick, 'register' | 'setValue'> & { - errors: FieldErrors; + props: Pick< + UseFormReturn, + 'register' | 'setValue' | 'formState' + > & { values: UnpackNestedValue; groups: string[]; groupsLoading: boolean; @@ -193,11 +195,11 @@ export const StepPrepareCreatePullRequest = ({ analyzeResult.generatedEntities[0]?.metadata?.name || '', useCodeowners: false, }} - render={({ values, errors, register, setValue }) => ( + render={({ values, formState, register, setValue }) => ( <> {renderFormFields({ values, - errors, + formState, register, setValue, groups: groups ?? [], @@ -242,7 +244,11 @@ export const StepPrepareCreatePullRequest = ({ )} Create PR diff --git a/plugins/cloudbuild/package.json b/plugins/cloudbuild/package.json index 41feeee2da..633b5d6e20 100644 --- a/plugins/cloudbuild/package.json +++ b/plugins/cloudbuild/package.json @@ -42,7 +42,6 @@ "qs": "^6.9.4", "react": "^16.13.1", "react-dom": "^16.13.1", - "react-hook-form": "^7.12.2", "react-lazylog": "^4.5.3", "react-router": "6.0.0-beta.0", "react-router-dom": "6.0.0-beta.0", diff --git a/plugins/shortcuts/package.json b/plugins/shortcuts/package.json index f650ccdda8..45d2487070 100644 --- a/plugins/shortcuts/package.json +++ b/plugins/shortcuts/package.json @@ -29,7 +29,7 @@ "@types/zen-observable": "^0.8.2", "react": "^16.13.1", "react-dom": "^16.13.1", - "react-hook-form": "^7.1.1", + "react-hook-form": "^7.12.2", "react-router": "6.0.0-beta.0", "react-use": "^17.2.4", "uuid": "^8.3.2", diff --git a/yarn.lock b/yarn.lock index a8c6c68b87..e643ac9750 100644 --- a/yarn.lock +++ b/yarn.lock @@ -22376,7 +22376,7 @@ react-hook-form@^6.15.4: resolved "https://registry.npmjs.org/react-hook-form/-/react-hook-form-6.15.4.tgz#328003e1ccc096cd158899ffe7e3b33735a9b024" integrity sha512-K+Sw33DtTMengs8OdqFJI3glzNl1wBzSefD/ksQw/hJf9CnOHQAU6qy82eOrh0IRNt2G53sjr7qnnw1JDjvx1w== -react-hook-form@^7.1.1, react-hook-form@^7.12.2: +react-hook-form@^7.12.2: version "7.12.2" resolved "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.12.2.tgz#2660afbf03c4ef360a9314ebf46ce3d972296c77" integrity sha512-cpxocjrgpMAJCMJQR51BQhMoEx80/EQqePNihMTgoTYTqCRbd2GExi+N4GJIr+cFqrmbwNj9wxk5oLWYQsUefg==