From 587ee0d9d5b62e186ca02b302f641439c5a9acfe Mon Sep 17 00:00:00 2001 From: Hein Jeong Date: Thu, 22 Sep 2022 21:16:49 +0000 Subject: [PATCH] chore: differentiate reset for datastore update form --- ...studio-ui-codegen-react-forms.test.ts.snap | 397 +++++++++++------- .../lib/forms/form-renderer-helper.ts | 49 +-- .../codegen-ui-react/lib/forms/form-state.ts | 131 ++++-- .../lib/forms/react-form-renderer.ts | 46 +- .../helpers/map-cta.test.ts | 27 ++ .../generate-form-definition.ts | 2 +- .../helpers/defaults.ts | 14 - .../helpers/map-cta.ts | 64 ++- .../helpers/map-cta-buttons.ts | 69 ++- 9 files changed, 494 insertions(+), 305 deletions(-) create mode 100644 packages/codegen-ui/lib/__tests__/generate-form-definition/helpers/map-cta.test.ts diff --git a/packages/codegen-ui-react/lib/__tests__/__snapshots__/studio-ui-codegen-react-forms.test.ts.snap b/packages/codegen-ui-react/lib/__tests__/__snapshots__/studio-ui-codegen-react-forms.test.ts.snap index d3f4d8c3c..1489cca3d 100644 --- a/packages/codegen-ui-react/lib/__tests__/__snapshots__/studio-ui-codegen-react-forms.test.ts.snap +++ b/packages/codegen-ui-react/lib/__tests__/__snapshots__/studio-ui-codegen-react-forms.test.ts.snap @@ -18,18 +18,25 @@ import { export default function CustomDataForm(props) { const { onSubmit, onCancel, onValidate, onChange, overrides, ...rest } = props; - const [name, setName] = React.useState(undefined); - const [email, setEmail] = React.useState(undefined); - const [city, setCity] = React.useState(undefined); - const [category, setCategory] = React.useState(undefined); - const [pages, setPages] = React.useState(0); + const initialValues = { + name: undefined, + email: undefined, + city: undefined, + category: undefined, + pages: 0, + }; + const [name, setName] = React.useState(initialValues.name); + const [email, setEmail] = React.useState(initialValues.email); + const [city, setCity] = React.useState(initialValues.city); + const [category, setCategory] = React.useState(initialValues.category); + const [pages, setPages] = React.useState(initialValues.pages); const [errors, setErrors] = React.useState({}); const resetStateValues = () => { - setName(undefined); - setEmail(undefined); - setCity(undefined); - setCategory(undefined); - setPages(0); + setName(initialValues.name); + setEmail(initialValues.email); + setCity(initialValues.city); + setCategory(initialValues.category); + setPages(initialValues.pages); setErrors({}); }; const validations = { @@ -264,7 +271,7 @@ export default function CustomDataForm(props) { onClick={resetStateValues} {...getOverrideProps(overrides, \\"ClearButton\\")} > - + - + - + - + - + - + - + - + - + - + - + - + - +