From ff7e0b98588f817702a173b58d17682959abbcbc Mon Sep 17 00:00:00 2001 From: "Dusan Mijatovic (PC2022)" Date: Tue, 20 Feb 2024 12:11:19 +0100 Subject: [PATCH] WIP: upgrade rsjf form to v5 --- apps/haddock3-download/src/App.css | 13 +- packages/core/package.json | 4 +- packages/core/src/CatalogPanel.tsx | 2 +- packages/core/src/ErrorBoundary.tsx | 8 +- packages/core/src/FormProps.ts | 6 +- packages/core/src/GlobalForm.tsx | 25 +- packages/core/src/NodeForm.tsx | 25 +- packages/core/src/NodePanel.tsx | 5 + packages/core/src/catalog.ts | 10 +- packages/core/src/grouper.test.ts | 2 +- packages/core/src/grouper.ts | 2 +- .../molecule/addMoleculeValidation.test.ts | 2 +- .../src/molecule/addMoleculeValidation.ts | 4 +- packages/core/src/resolveMaxItemsFrom.ts | 52 +-- packages/core/src/store.ts | 2 +- packages/core/src/types.ts | 2 +- packages/core/src/validate.ts | 300 ++++++++-------- packages/core/src/workflow.ts | 12 +- packages/form/package.json | 9 +- .../form/src/ArrayFieldTemplate.stories.tsx | 3 + packages/form/src/ArrayFieldTemplate.tsx | 23 +- .../form/src/CollapsibleField.stories.tsx | 4 +- packages/form/src/CollapsibleField.tsx | 13 +- packages/form/src/Form.stories.tsx | 3 +- packages/form/src/Form.test.tsx | 7 +- packages/form/src/Form.tsx | 64 +++- .../src/IvresseCheckboxWidget.stories.tsx | 2 + packages/form/src/IvresseCheckboxWidget.tsx | 28 +- packages/form/src/IvresseDescriptionField.tsx | 13 +- packages/form/src/molecule/formats.ts | 4 +- .../form/src/table/TableField.stories.tsx | 4 +- packages/form/src/table/TableField.test.tsx | 5 +- packages/form/src/table/TableField.tsx | 22 +- .../form/src/table/TableFieldTemplate.tsx | 7 +- packages/form/src/useIndexable.ts | 4 +- yarn.lock | 325 +++++++++++++++--- 36 files changed, 676 insertions(+), 340 deletions(-) diff --git a/apps/haddock3-download/src/App.css b/apps/haddock3-download/src/App.css index ebf40ea4..d4eb9483 100644 --- a/apps/haddock3-download/src/App.css +++ b/apps/haddock3-download/src/App.css @@ -6,15 +6,20 @@ grid-template-areas: "head head head" "catalog workflow node" "catalog workflow-actions node-actions"; - grid-template-columns: 1fr 1fr 2fr; + grid-template-columns: min-content 26rem 1fr; grid-template-rows: auto 1fr auto; - column-gap: 0.5rem; + column-gap: 1rem; } -.page > div { +/* .page > div { overflow: auto; -} +} */ .action-row { padding: 0.25rem } + + +.btn-toolbar > .btn { + margin: 0.25rem; +} \ No newline at end of file diff --git a/packages/core/package.json b/packages/core/package.json index c3543b62..bc761956 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -69,14 +69,12 @@ "@i-vresse/wb-form": "workspace:^", "@ltd/j-toml": "^1.24.0", "@zip.js/zip.js": "^2.3.23", - "ajv": "^8.9.0", - "ajv-formats": "^2.1.1", "bootstrap": "^4", "file-saver": "^2.0.5", "js-yaml": "^4.1.0", "nanoid": "^4.0.0", "papaparse": "^5.3.2", - "react-bootstrap": "^1", + "react-bootstrap": "^2", "react-dnd-html5-backend": "^14.1.0", "react-icons": "^3.10.0", "react-syntax-highlighter": "^15.4.5", diff --git a/packages/core/src/CatalogPanel.tsx b/packages/core/src/CatalogPanel.tsx index 8517d7ac..395eeb70 100644 --- a/packages/core/src/CatalogPanel.tsx +++ b/packages/core/src/CatalogPanel.tsx @@ -14,7 +14,7 @@ import { useCatalog } from './store' export const CatalogPanel = ({ children }: PropsWithChildren<{}>): JSX.Element => { const catalog = useCatalog() return ( -
+
Catalog Loading catalog...}> {children} diff --git a/packages/core/src/ErrorBoundary.tsx b/packages/core/src/ErrorBoundary.tsx index 20102310..34854e65 100644 --- a/packages/core/src/ErrorBoundary.tsx +++ b/packages/core/src/ErrorBoundary.tsx @@ -1,5 +1,5 @@ import React from 'react' -import { ValidationError } from './validate' +// import { ValidationError } from './validate' interface State { error: Error | null @@ -16,9 +16,9 @@ export class ErrorBoundary extends React.Component<{}, State> { render (): React.ReactNode { if (this.state.error !== null) { - if (this.state.error instanceof ValidationError) { - console.error(this.state.error.errors) - } + // if (this.state.error instanceof ValidationError) { + // console.error(this.state.error.errors) + // } return (

Something went terribly wrong.

diff --git a/packages/core/src/FormProps.ts b/packages/core/src/FormProps.ts index 2a08f376..f7942eea 100644 --- a/packages/core/src/FormProps.ts +++ b/packages/core/src/FormProps.ts @@ -1,14 +1,14 @@ -import { Field, Widget } from '@rjsf/core' +import { FieldProps, WidgetProps } from '@rjsf/utils' export interface FormProps { /** * Custom fields for React JSON schema form. * See https://react-jsonschema-form.readthedocs.io/en/latest/advanced-customization/custom-widgets-fields */ - fields?: { [name: string]: Field } + fields?: { [name: string]: FieldProps } /** * Custom widgets for React JSON schema form. * See https://react-jsonschema-form.readthedocs.io/en/latest/advanced-customization/custom-widgets-fields */ - widgets?: { [name: string]: Widget } + widgets?: { [name: string]: WidgetProps } } diff --git a/packages/core/src/GlobalForm.tsx b/packages/core/src/GlobalForm.tsx index ce8a6f79..5753bfb5 100644 --- a/packages/core/src/GlobalForm.tsx +++ b/packages/core/src/GlobalForm.tsx @@ -1,16 +1,25 @@ import React from 'react' import { Form } from '@i-vresse/wb-form' +import validator from '@rjsf/validator-ajv8' -import { FormProps } from './FormProps' +// import { FormProps } from './FormProps' import { useCatalog, useGlobalFormData, useSetActiveSubmitButton } from './store' import '@i-vresse/wb-form/dist/index.css' -export const GlobalForm = ({ fields, widgets }: FormProps): JSX.Element => { +export const GlobalForm = ({ fields, widgets }: any): JSX.Element => { const { global: globalSchemas } = useCatalog() const [formData, setFormData] = useGlobalFormData() const submitFormRefSetter = useSetActiveSubmitButton() const uiSchema = globalSchemas.formUiSchema + + console.group('GlobalForm') + console.log('fields...', fields) + console.log('widgets...', widgets) + console.log('globalSchemas...', globalSchemas) + console.log('uiSchema...', uiSchema) + console.groupEnd() + return (
{ onSubmit={({ formData }) => setFormData(formData)} fields={fields} widgets={widgets} + validator={validator} + liveValidate={false} + showErrorList={false} + // onChange={(props) => { + // const { errors, formData } = props + // if (errors?.length === 0) { + // setFormData(formData) + // } + // }} + onBlur={(...props) => { + console.log('NodeForm.onBlur...', props) + }} >