feat: Add helper function to render control component in AddFlowVariableModal (#1974)

This commit is contained in:
Dreammy23 2024-09-04 23:59:20 +08:00 committed by GitHub
commit 19b8d45db2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -126,6 +126,37 @@ export const AddFlowVariableModal: React.FC<Props> = ({ flowInfo }) => {
} }
}; };
// Helper function to render the appropriate control component
const renderVariableValue = (type: string, index: number) => {
switch (type) {
case 'ref':
return (
<Cascader
placeholder='Select Value'
options={refVariableOptions}
loadData={loadData}
onChange={(value, selectedOptions) => onRefTypeValueChange(value, selectedOptions, index)}
changeOnSelect
/>
);
case 'str':
return <Input placeholder='Parameter Value' />;
case 'int':
return <Input type='number' placeholder='Parameter Value' />;
case 'float':
return <Input type='number' step='0.01' placeholder='Parameter Value' />;
case 'bool':
return (
<Select placeholder='Select Value'>
<Option value='true'>True</Option>
<Option value='false'>False</Option>
</Select>
);
default:
return <Input placeholder='Parameter Value' />;
}
};
return ( return (
<> <>
<Button <Button
@ -215,19 +246,7 @@ export const AddFlowVariableModal: React.FC<Props> = ({ flowInfo }) => {
style={{ width: 320 }} style={{ width: 320 }}
rules={[{ required: true, message: 'Missing parameter value' }]} rules={[{ required: true, message: 'Missing parameter value' }]}
> >
{controlTypes[index] === 'ref' ? ( {renderVariableValue(controlTypes[index], index)}
<Cascader
placeholder='Select Value'
options={refVariableOptions}
loadData={loadData}
onChange={(value, selectedOptions) => onRefTypeValueChange(value, selectedOptions, index)}
// displayRender={displayRender}
// dropdownRender={dropdownRender}
changeOnSelect
/>
) : (
<Input placeholder='Parameter Value' />
)}
</Form.Item> </Form.Item>
<Form.Item {...restField} name={[name, 'description']} label='描述' style={{ width: 170 }}> <Form.Item {...restField} name={[name, 'description']} label='描述' style={{ width: 170 }}>