From ea26dd8fb7d6d8c5a4638e98731811d12b862c4a Mon Sep 17 00:00:00 2001 From: Hein Jeong Date: Mon, 8 Aug 2022 23:31:33 +0000 Subject: [PATCH] chore: move form-to-component util --- .../lib/generate-form-definition/index.ts | 1 - .../form-to-component/index.ts} | 19 +------------------ .../map-form-definition-to-component.ts} | 14 +++++--------- packages/codegen-ui/lib/utils/index.ts | 1 + 4 files changed, 7 insertions(+), 28 deletions(-) rename packages/codegen-ui/lib/{__tests__/generate-form-definition/form-to-component.test.ts => utils/form-to-component/index.ts} (56%) rename packages/codegen-ui/lib/{generate-form-definition/form-to-component.ts => utils/form-to-component/map-form-definition-to-component.ts} (92%) diff --git a/packages/codegen-ui/lib/generate-form-definition/index.ts b/packages/codegen-ui/lib/generate-form-definition/index.ts index 469a5c54b..29d0758aa 100644 --- a/packages/codegen-ui/lib/generate-form-definition/index.ts +++ b/packages/codegen-ui/lib/generate-form-definition/index.ts @@ -21,4 +21,3 @@ export { getFieldConfigFromModelField, } from './helpers'; export { generateFormDefinition } from './generate-form-definition'; -export { mapFormDefinitionToComponent } from './form-to-component'; diff --git a/packages/codegen-ui/lib/__tests__/generate-form-definition/form-to-component.test.ts b/packages/codegen-ui/lib/utils/form-to-component/index.ts similarity index 56% rename from packages/codegen-ui/lib/__tests__/generate-form-definition/form-to-component.test.ts rename to packages/codegen-ui/lib/utils/form-to-component/index.ts index 6b96ad435..a1a3c1993 100644 --- a/packages/codegen-ui/lib/__tests__/generate-form-definition/form-to-component.test.ts +++ b/packages/codegen-ui/lib/utils/form-to-component/index.ts @@ -13,21 +13,4 @@ See the License for the specific language governing permissions and limitations under the License. */ -// import { postSchema } from '../__utils__/mock-schemas'; -import { StudioForm } from '../../types'; - -describe('formToComponent', () => { - it('should map datastore model fields', () => { - const myForm: StudioForm = { - id: '123', - name: 'mySampleForm', - formActionType: 'create', - dataType: { dataSourceType: 'DataStore', dataTypeName: 'Post' }, - fields: {}, - sectionalElements: {}, - style: {}, - }; - - expect(myForm).toBeDefined(); - }); -}); +export { mapFormDefinitionToComponent } from './map-form-definition-to-component'; diff --git a/packages/codegen-ui/lib/generate-form-definition/form-to-component.ts b/packages/codegen-ui/lib/utils/form-to-component/map-form-definition-to-component.ts similarity index 92% rename from packages/codegen-ui/lib/generate-form-definition/form-to-component.ts rename to packages/codegen-ui/lib/utils/form-to-component/map-form-definition-to-component.ts index 9da13e211..96771bd1c 100644 --- a/packages/codegen-ui/lib/generate-form-definition/form-to-component.ts +++ b/packages/codegen-ui/lib/utils/form-to-component/map-form-definition-to-component.ts @@ -21,13 +21,13 @@ import { FormStyleConfig, StudioComponentProperties, StudioFormStyle, -} from '../types'; +} from '../../types'; const getStyleResolvedValue = (config?: FormStyleConfig): string | undefined => { return config?.value ?? config?.tokenReference; }; -export const resolveStyles = ( +const resolveStyles = ( style: StudioFormStyle, ): Record, string | undefined> => { return { @@ -37,11 +37,7 @@ export const resolveStyles = ( }; }; -export const parentGrid = ( - name: string, - style: StudioFormStyle, - children: StudioComponentChild[], -): StudioComponentChild => { +const parentGrid = (name: string, style: StudioFormStyle, children: StudioComponentChild[]): StudioComponentChild => { const { verticalGap, horizontalGap } = resolveStyles(style); return { name, @@ -62,7 +58,7 @@ const mapFieldElementProps = (element: FormDefinitionElement) => { return props; }; -export const fieldComponentMapper = (name: string, formDefinition: FormDefinition): StudioComponentChild => { +const fieldComponentMapper = (name: string, formDefinition: FormDefinition): StudioComponentChild => { // will accept a field matrix from a defnition and map const fieldChildren = formDefinition.elementMatrix.map((row: string[], rowIdx: number) => { return { @@ -88,7 +84,7 @@ export const fieldComponentMapper = (name: string, formDefinition: FormDefinitio return parentGrid(`${name}Grid`, formDefinition.form.layoutStyle, fieldChildren); }; -export const ctaButtonConfig = (): StudioComponentChild => { +const ctaButtonConfig = (): StudioComponentChild => { return { name: 'CTAFlex', componentType: 'Flex', diff --git a/packages/codegen-ui/lib/utils/index.ts b/packages/codegen-ui/lib/utils/index.ts index 57c771257..abbf5f9ed 100644 --- a/packages/codegen-ui/lib/utils/index.ts +++ b/packages/codegen-ui/lib/utils/index.ts @@ -18,3 +18,4 @@ export * from './component-tree'; export * from './state-reference-metadata'; export * from './string-formatter'; export * from './form-component-metadata'; +export * from './form-to-component';