import FieldComponent from '@/components/seal-form/field-component'; import SealSelect from '@/components/seal-form/seal-select'; import { useIntl } from '@umijs/max'; import { Form } from 'antd'; import _ from 'lodash'; import React, { forwardRef, memo, useCallback, useEffect, useId, useImperativeHandle, useMemo } from 'react'; import { ParamsSchema } from '../config/types'; type ParamsSettingsProps = { ref?: any; parametersTitle?: React.ReactNode; showModelSelector?: boolean; modelList?: Global.BaseOption[]; onValuesChange?: (changeValues: any, value: Record) => void; onModelChange?: (model: string) => void; paramsConfig?: ParamsSchema[]; initialValues?: Record; // for initial values when switch model, aviod update values from setParams extra?: React.ReactNode; watchFields?: string[]; formFields?: string; }; const ParamsSettings: React.FC = forwardRef( ( { onValuesChange, onModelChange, parametersTitle, initialValues, paramsConfig, modelList, watchFields, formFields, showModelSelector = true, extra }, ref ) => { const intl = useIntl(); const [form] = Form.useForm(); const formId = useId(); useImperativeHandle(ref, () => ({ form })); useEffect(() => { form.setFieldsValue({ ...initialValues }); }, [initialValues]); const handleOnFinish = (values: any) => { console.log('handleOnFinish', values); }; const handleOnFinishFailed = (errorInfo: any) => { console.log('handleOnFinishFailed', errorInfo); }; const handleOnModelChange = (model: string) => { onModelChange?.(model); }; const handleValuesChange = useCallback( (changedValues: any, allValues: any) => { const normalizedValues = Object.fromEntries( Object.entries(changedValues).map(([key, value]: [string, any]) => [ key, value?.target?.checked ?? value?.target?.value ?? value ]) ); form.setFieldsValue(normalizedValues); console.log('handleValuesChange', normalizedValues, allValues); onValuesChange?.(normalizedValues, { ...allValues, ...normalizedValues }); }, [onValuesChange] ); const renderDescription = useCallback( (description: any) => { let desc = description?.text; if (description?.isLocalized) { desc = intl.formatMessage({ id: description?.text }); } if (description?.html) { return
; } return desc; }, [intl] ); const renderFields = useMemo(() => { if (!paramsConfig?.length) { return null; } console.log('renderFields---------'); const formValues = form?.getFieldsValue(); return paramsConfig?.map((item: ParamsSchema) => { return ( ); }); }, [formFields, paramsConfig, intl, watchFields]); return (
{ <>

{parametersTitle || ( {intl.formatMessage({ id: 'playground.parameters' })} )}

{showModelSelector && ( )} } {renderFields} {extra}
); } ); export default memo(ParamsSettings);