From 16d591307d39b5a33c1e1e30d6a2d846cfb591fa Mon Sep 17 00:00:00 2001 From: burnettk Date: Sun, 22 Jan 2023 00:36:16 -0500 Subject: [PATCH] make sure that all new form field elements are not dropdowns --- spiffworkflow-frontend/src/interfaces.ts | 8 +-- .../src/routes/JsonSchemaFormBuilder.tsx | 63 ++++++++++++++++--- 2 files changed, 59 insertions(+), 12 deletions(-) diff --git a/spiffworkflow-frontend/src/interfaces.ts b/spiffworkflow-frontend/src/interfaces.ts index f3888f1de..f2d2d0a6a 100644 --- a/spiffworkflow-frontend/src/interfaces.ts +++ b/spiffworkflow-frontend/src/interfaces.ts @@ -225,11 +225,11 @@ export interface PermissionCheckResponseBody { export interface FormField { id: string; title: string; - required: boolean; + required?: boolean; type: string; - enum: string[]; - default: any; - pattern: string; + enum?: string[]; + default?: any; + pattern?: string; } export interface JsonSchemaForm { diff --git a/spiffworkflow-frontend/src/routes/JsonSchemaFormBuilder.tsx b/spiffworkflow-frontend/src/routes/JsonSchemaFormBuilder.tsx index b0f0d7c08..ba0866d53 100644 --- a/spiffworkflow-frontend/src/routes/JsonSchemaFormBuilder.tsx +++ b/spiffworkflow-frontend/src/routes/JsonSchemaFormBuilder.tsx @@ -1,8 +1,18 @@ import { useEffect, useState } from 'react'; // @ts-ignore -import { Button, Select, SelectItem, TextInput } from '@carbon/react'; import { useNavigate, useParams, useSearchParams } from 'react-router-dom'; +import { + Button, + Select, + SelectItem, + TextInput, + Grid, + Column, + // @ts-ignore +} from '@carbon/react'; +import validator from '@rjsf/validator-ajv8'; import { FormField, JsonSchemaForm } from '../interfaces'; +import Form from '../themes/carbon'; import { modifyProcessIdentifierForPathParam, slugifyString, @@ -147,15 +157,23 @@ export default function JsonSchemaFormBuilder() { setFormTitle(newFormTitle); }; + const getFormFieldType = (indicatedType: string) => { + if (indicatedType === 'checkbox') { + return 'boolean'; + } + // undefined or 'select' or 'textbox' + return 'string'; + }; + const addFormField = () => { const newFormField: FormField = { id: formFieldId, title: formFieldTitle, required: false, - type: formFieldType, - enum: formFieldSelectOptions.split(','), - pattern: '', - default: null, + type: getFormFieldType(formFieldType), + enum: showFormFieldSelectTextField + ? formFieldSelectOptions.split(',') + : undefined, }; setFormFieldIdHasBeenUpdatedByUser(false); @@ -333,9 +351,9 @@ export default function JsonSchemaFormBuilder() { ); }; + const processModelFileName = searchParams.get('file_name') || ''; - const jsonFormArea = () => { - const processModelFileName = searchParams.get('file_name') || ''; + const topOfPageElements = () => { return ( <> + + ); + }; + + const jsonFormArea = () => { + return ( + <> {formSubmitResultElement()} {jsonFormButton()} @@ -392,6 +417,28 @@ export default function JsonSchemaFormBuilder() { ); }; + const schemaString = renderFormJson(); + const uiSchemaString = renderFormUiJson(); + const schema = JSON.parse(schemaString); + const uiSchema = JSON.parse(uiSchemaString); - return <>{jsonFormArea()}; + return ( + <> + {topOfPageElements()} + + + {jsonFormArea()} + + +

Form Preview

+
+ + + + ); }