| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- import { FormRenderProps, FlowNodeJSON, Field } from '@flowgram.ai/free-layout-editor';
- import { SubCanvasRender } from '@flowgram.ai/free-container-plugin';
- import { BatchVariableSelector, IFlowRefValue } from '@flowgram.ai/form-materials';
- import { useIsSidebar, useNodeRenderContext } from '../../hooks';
- import { FormHeader, FormContent, FormOutputs, FormItem, Feedback } from '../../form-components';
- interface LoopNodeJSON extends FlowNodeJSON {
- data: {
- batchFor: IFlowRefValue;
- };
- }
- export const LoopFormRender = ({ form }: FormRenderProps<LoopNodeJSON>) => {
- const isSidebar = useIsSidebar();
- const { readonly } = useNodeRenderContext();
- const formHeight = 85;
- const batchFor = (
- <Field<IFlowRefValue> name={`batchFor`}>
- {({ field, fieldState }) => (
- <FormItem name={'batchFor'} type={'array'} required>
- <BatchVariableSelector
- style={{ width: '100%' }}
- value={field.value?.content}
- onChange={(val) => field.onChange({ type: 'ref', content: val })}
- readonly={readonly}
- hasError={Object.keys(fieldState?.errors || {}).length > 0}
- />
- <Feedback errors={fieldState?.errors} />
- </FormItem>
- )}
- </Field>
- );
- if (isSidebar) {
- return (
- <>
- <FormHeader />
- <FormContent>
- {batchFor}
- <FormOutputs />
- </FormContent>
- </>
- );
- }
- return (
- <>
- <FormHeader />
- <FormContent>
- {batchFor}
- <SubCanvasRender offsetY={-formHeight} />
- <FormOutputs />
- </FormContent>
- </>
- );
- };
|