diff --git a/src/components/FunctionForm.tsx b/src/components/FunctionForm.tsx index 57b4a03536dcee3b7fd37ca24cdeccb106d61f9b..f8d2ce75f9c3e03d25b46b3599ad65cf668666f4 100644 --- a/src/components/FunctionForm.tsx +++ b/src/components/FunctionForm.tsx @@ -16,6 +16,8 @@ import validator from '@rjsf/validator-ajv8'; import React from 'react'; import { FormEvent } from 'react'; +import CustomSchemaField from './SchemaField'; + const log = (type: string) => console.log.bind(console, type); function FunctionForm({ @@ -38,13 +40,20 @@ function FunctionForm({ if (typeof uiSchema === 'undefined') { uiSchema = {}; } + if (schema.uiSchema) { + uiSchema = { ...uiSchema, ...schema.uiSchema }; + } + + // @ts-expect-error:next-line uiSchema.func_name = { 'ui:widget': 'hidden' }; Object.entries(schema.properties).forEach(([prop, attrs]) => { // @ts-expect-error:next-line if (attrs.is_reporter) { + // @ts-expect-error:next-line uiSchema[prop] = { 'ui:widget': 'hidden' }; } }); + return ( <> <Form @@ -53,7 +62,7 @@ function FunctionForm({ validator={validator} onSubmit={typeof onSubmit !== 'undefined' ? onSubmit : log('submitted')} onError={typeof onError !== 'undefined' ? onError : log('errors')} - fields={fields} + fields={{ SchemaField: CustomSchemaField, ...(fields ? fields : {}) }} widgets={widgets} onChange={onChange} /> diff --git a/src/components/SchemaField.tsx b/src/components/SchemaField.tsx new file mode 100644 index 0000000000000000000000000000000000000000..65b4e7978fc41561c4f9fa4219e5e6da6adb5b23 --- /dev/null +++ b/src/components/SchemaField.tsx @@ -0,0 +1,25 @@ +// SPDX-FileCopyrightText: 2025 Helmholtz-Zentrum hereon GmbH +// +// SPDX-License-Identifier: Apache-2.0 + +// @ts-expect-error: importing React is necessary for react@18.2.0 +import React from 'react'; +import { FieldProps } from '@rjsf/utils'; +import { getDefaultRegistry } from '@rjsf/core'; + +const { + fields: { SchemaField }, +} = getDefaultRegistry(); + +const CustomSchemaField = (props: FieldProps) => { + if (props.schema.uiSchema) { + const uiSchema = { + ...(props.uiSchema ? props.uiSchema : {}), + ...props.schema.uiSchema, + }; + return <SchemaField {...props} uiSchema={uiSchema} />; + } + return <SchemaField {...props} />; +}; + +export default CustomSchemaField;