From 932a29cbae886cab2bba15710cabb14e27559589 Mon Sep 17 00:00:00 2001 From: Hein Jeong Date: Wed, 12 Oct 2022 22:37:30 +0000 Subject: [PATCH] fix: allow float to have decimals --- .../__snapshots__/studio-ui-codegen-react-forms.test.ts.snap | 4 ++++ packages/codegen-ui-react/lib/forms/form-renderer-helper.ts | 3 ++- packages/codegen-ui/lib/types/form/form-metadata.ts | 1 + packages/codegen-ui/lib/utils/form-component-metadata.ts | 1 + 4 files changed, 8 insertions(+), 1 deletion(-) 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 b73b23138..4e8cad6f6 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 @@ -4310,6 +4310,7 @@ export default function InputGalleryCreateForm(props) { isRequired={false} isReadOnly={false} type=\\"number\\" + step=\\"any\\" onChange={(e) => { let value = parseInt(e.target.value); if (isNaN(value)) { @@ -4349,6 +4350,7 @@ export default function InputGalleryCreateForm(props) { isRequired={false} isReadOnly={false} type=\\"number\\" + step=\\"any\\" onChange={(e) => { let value = Number(e.target.value); if (isNaN(value)) { @@ -5062,6 +5064,7 @@ export default function InputGalleryUpdateForm(props) { isRequired={false} isReadOnly={false} type=\\"number\\" + step=\\"any\\" defaultValue={num} onChange={(e) => { let value = parseInt(e.target.value); @@ -5102,6 +5105,7 @@ export default function InputGalleryUpdateForm(props) { isRequired={false} isReadOnly={false} type=\\"number\\" + step=\\"any\\" defaultValue={rootbeer} onChange={(e) => { let value = Number(e.target.value); diff --git a/packages/codegen-ui-react/lib/forms/form-renderer-helper.ts b/packages/codegen-ui-react/lib/forms/form-renderer-helper.ts index b2af5c939..656dece66 100644 --- a/packages/codegen-ui-react/lib/forms/form-renderer-helper.ts +++ b/packages/codegen-ui-react/lib/forms/form-renderer-helper.ts @@ -175,7 +175,7 @@ export const addFormAttributes = (component: StudioComponent | StudioComponentCh ); attributes.push( ...buildComponentSpecificAttributes({ - componentType, + componentType: fieldConfig.studioFormComponentType ?? fieldConfig.componentType, componentName: renderedVariableName, currentValueIdentifier: fieldConfig.isArray ? getCurrentValueIdentifier(renderedVariableName) : undefined, }), @@ -497,6 +497,7 @@ export const buildComponentSpecificAttributes = ({ factory.createJsxExpression(undefined, valueIdentifier), ), ], + NumberField: [factory.createJsxAttribute(factory.createIdentifier('step'), factory.createStringLiteral('any'))], }; return componentToAttributesMap[componentType] ?? []; diff --git a/packages/codegen-ui/lib/types/form/form-metadata.ts b/packages/codegen-ui/lib/types/form/form-metadata.ts index b7d6d176b..21768b201 100644 --- a/packages/codegen-ui/lib/types/form/form-metadata.ts +++ b/packages/codegen-ui/lib/types/form/form-metadata.ts @@ -31,6 +31,7 @@ export type FieldConfigMetadata = { sanitizedFieldName?: string; isArray?: boolean; componentType: string; + studioFormComponentType?: string; }; export type FormMetadata = { diff --git a/packages/codegen-ui/lib/utils/form-component-metadata.ts b/packages/codegen-ui/lib/utils/form-component-metadata.ts index b78bd0369..58405238a 100644 --- a/packages/codegen-ui/lib/utils/form-component-metadata.ts +++ b/packages/codegen-ui/lib/utils/form-component-metadata.ts @@ -72,6 +72,7 @@ export const mapFormMetadata = (form: StudioForm, formDefinition: FormDefinition const metadata: FieldConfigMetadata = { validationRules: [], componentType: config.componentType, + studioFormComponentType: 'studioFormComponentType' in config ? config.studioFormComponentType : undefined, isArray: 'isArray' in config && config.isArray, }; if ('validations' in config && config.validations) {