|
@@ -1,16 +1,13 @@
|
|
|
-import {
|
|
|
|
|
- Field,
|
|
|
|
|
- FieldRenderProps,
|
|
|
|
|
- FormRenderProps,
|
|
|
|
|
- FormMeta,
|
|
|
|
|
- ValidateTrigger,
|
|
|
|
|
-} from '@flowgram.ai/fixed-layout-editor';
|
|
|
|
|
|
|
+import { mapValues } from 'lodash-es';
|
|
|
|
|
+import { IFlowValue } from '@flowgram.ai/form-materials';
|
|
|
|
|
+import { Field, FieldRenderProps, FormMeta } from '@flowgram.ai/fixed-layout-editor';
|
|
|
|
|
|
|
|
-import { FlowNodeJSON, JsonSchema } from '../../typings';
|
|
|
|
|
|
|
+import { defaultFormMeta } from '../default-form-meta';
|
|
|
|
|
+import { JsonSchema } from '../../typings';
|
|
|
import { useIsSidebar } from '../../hooks';
|
|
import { useIsSidebar } from '../../hooks';
|
|
|
import { FormHeader, FormContent, FormOutputs, PropertiesEdit } from '../../form-components';
|
|
import { FormHeader, FormContent, FormOutputs, PropertiesEdit } from '../../form-components';
|
|
|
|
|
|
|
|
-export const renderForm = ({ form }: FormRenderProps<FlowNodeJSON['data']>) => {
|
|
|
|
|
|
|
+export const renderForm = () => {
|
|
|
const isSidebar = useIsSidebar();
|
|
const isSidebar = useIsSidebar();
|
|
|
if (isSidebar) {
|
|
if (isSidebar) {
|
|
|
return (
|
|
return (
|
|
@@ -20,12 +17,30 @@ export const renderForm = ({ form }: FormRenderProps<FlowNodeJSON['data']>) => {
|
|
|
<Field
|
|
<Field
|
|
|
name="outputs.properties"
|
|
name="outputs.properties"
|
|
|
render={({
|
|
render={({
|
|
|
- field: { value, onChange },
|
|
|
|
|
- fieldState,
|
|
|
|
|
|
|
+ field: { value: propertiesSchemaValue, onChange: propertiesSchemaChange },
|
|
|
}: FieldRenderProps<Record<string, JsonSchema>>) => (
|
|
}: FieldRenderProps<Record<string, JsonSchema>>) => (
|
|
|
- <>
|
|
|
|
|
- <PropertiesEdit value={value} onChange={onChange} useFx={true} />
|
|
|
|
|
- </>
|
|
|
|
|
|
|
+ <Field<Record<string, IFlowValue>> name="inputsValues">
|
|
|
|
|
+ {({ field: { value: propertiesValue, onChange: propertiesValueChange } }) => {
|
|
|
|
|
+ const onChange = (newProperties: Record<string, JsonSchema>) => {
|
|
|
|
|
+ const newPropertiesValue = mapValues(newProperties, (v) => v.default);
|
|
|
|
|
+ const newPropetiesSchema = mapValues(newProperties, (v) => {
|
|
|
|
|
+ delete v.default;
|
|
|
|
|
+ return v;
|
|
|
|
|
+ });
|
|
|
|
|
+ propertiesValueChange(newPropertiesValue);
|
|
|
|
|
+ propertiesSchemaChange(newPropetiesSchema);
|
|
|
|
|
+ };
|
|
|
|
|
+ const value = mapValues(propertiesSchemaValue, (v, key) => ({
|
|
|
|
|
+ ...v,
|
|
|
|
|
+ default: propertiesValue?.[key],
|
|
|
|
|
+ }));
|
|
|
|
|
+ return (
|
|
|
|
|
+ <>
|
|
|
|
|
+ <PropertiesEdit value={value} onChange={onChange} useFx={true} />
|
|
|
|
|
+ </>
|
|
|
|
|
+ );
|
|
|
|
|
+ }}
|
|
|
|
|
+ </Field>
|
|
|
)}
|
|
)}
|
|
|
/>
|
|
/>
|
|
|
<FormOutputs />
|
|
<FormOutputs />
|
|
@@ -43,10 +58,7 @@ export const renderForm = ({ form }: FormRenderProps<FlowNodeJSON['data']>) => {
|
|
|
);
|
|
);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
-export const formMeta: FormMeta<FlowNodeJSON['data']> = {
|
|
|
|
|
|
|
+export const formMeta: FormMeta = {
|
|
|
|
|
+ ...defaultFormMeta,
|
|
|
render: renderForm,
|
|
render: renderForm,
|
|
|
- validateTrigger: ValidateTrigger.onChange,
|
|
|
|
|
- validate: {
|
|
|
|
|
- title: ({ value }: { value: string }) => (value ? undefined : 'Title is required'),
|
|
|
|
|
- },
|
|
|
|
|
};
|
|
};
|