Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add label of component #1847

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 41 additions & 40 deletions web/components/flow/node-param-handler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ const NodeParamHandler: React.FC<NodeParamHandlerProps> = ({ node, data, label,
data.value = value;
}

function renderLabelWithTooltip(data: IFlowNodeParameter) {
return (
<div>
{data.label}:<RequiredIcon optional={data.optional} />
{data.description && (
<Tooltip title={data.description}>
<InfoCircleOutlined className="ml-2 cursor-pointer" />
</Tooltip>
)}
</div>
);
}

// render node parameters based on AWEL1.0
function renderNodeWithoutUiParam(data: IFlowNodeParameter) {
let defaultValue = data.value ?? data.default;
Expand All @@ -43,14 +56,7 @@ const NodeParamHandler: React.FC<NodeParamHandlerProps> = ({ node, data, label,
case 'float':
return (
<div className="text-sm">
<p>
{data.label}:<RequiredIcon optional={data.optional} />
{data.description && (
<Tooltip title={data.description}>
<InfoCircleOutlined className="ml-2 cursor-pointer" />
</Tooltip>
)}
</p>
{renderLabelWithTooltip(data)}
<InputNumber
className="w-full"
defaultValue={defaultValue}
Expand All @@ -63,14 +69,7 @@ const NodeParamHandler: React.FC<NodeParamHandlerProps> = ({ node, data, label,
case 'str':
return (
<div className="text-sm">
<p>
{data.label}:<RequiredIcon optional={data.optional} />
{data.description && (
<Tooltip title={data.description}>
<InfoCircleOutlined className="ml-2 cursor-pointer" />
</Tooltip>
)}
</p>
{renderLabelWithTooltip(data)}
{data.options?.length > 0 ? (
<Select
className="w-full nodrag"
Expand All @@ -94,32 +93,21 @@ const NodeParamHandler: React.FC<NodeParamHandlerProps> = ({ node, data, label,
defaultValue = defaultValue === 'True' ? true : defaultValue;
return (
<div className="text-sm">
<p>
{data.label}:<RequiredIcon optional={data.optional} />
{data.description && (
<Tooltip title={data.description}>
<InfoCircleOutlined className="ml-2 cursor-pointer" />
</Tooltip>
)}
<Checkbox
className="ml-2"
defaultChecked={defaultValue}
onChange={(e) => {
onChange(e.target.checked);
}}
/>
</p>
{renderLabelWithTooltip(data)}
<Checkbox
className="ml-2"
defaultChecked={defaultValue}
onChange={(e) => {
onChange(e.target.checked);
}}
/>
</div>
);
}
}

// render node parameters based on AWEL2.0
function renderNodeWithUiParam(data: IFlowNodeParameter) {
let defaultValue = data.value ?? data.default;
const props = { data, defaultValue, onChange };

switch (data?.ui?.ui_type) {
function renderComponentByType(type: string, props?: any) {
switch (type) {
case 'select':
return <RenderSelect {...props} />;
case 'cascader':
Expand All @@ -144,20 +132,33 @@ const NodeParamHandler: React.FC<NodeParamHandlerProps> = ({ node, data, label,
return <RenderPassword {...props} />;
case 'upload':
return <RenderUpload {...props} />;
case 'variables':
return <RenderVariables {...props} />;
case 'variables':
return <RenderVariables {...props} />;
case 'code_editor':
return <RenderCodeEditor {...props} />;
default:
return null;
}
}

// render node parameters based on AWEL2.0
function renderNodeWithUiParam(data: IFlowNodeParameter) {
let defaultValue = data.value ?? data.default;
const props = { data, defaultValue, onChange };

return (
<div>
{renderLabelWithTooltip(data)}
{renderComponentByType(data?.ui?.ui_type, props)}
</div>
);
}

if (data.category === 'resource') {
return <NodeHandler node={node} data={data} type="target" label={label} index={index} />;
} else if (data.category === 'common') {
return data?.ui ? renderNodeWithUiParam(data) : renderNodeWithoutUiParam(data);
}
};

export default NodeParamHandler;
export default NodeParamHandler;
Loading