mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-09-11 22:09:44 +00:00
feat: update style of canvas node (#1829)
This commit is contained in:
@@ -59,6 +59,7 @@ function GPTCard({
|
|||||||
return icon;
|
return icon;
|
||||||
}, [icon]);
|
}, [icon]);
|
||||||
|
|
||||||
|
// TODO: 算子资源标签
|
||||||
const tagNode = useMemo(() => {
|
const tagNode = useMemo(() => {
|
||||||
if (!tags || !tags.length) return null;
|
if (!tags || !tags.length) return null;
|
||||||
return (
|
return (
|
||||||
|
@@ -18,7 +18,7 @@ type CanvasNodeProps = {
|
|||||||
const ICON_PATH_PREFIX = '/icons/node/';
|
const ICON_PATH_PREFIX = '/icons/node/';
|
||||||
|
|
||||||
function TypeLabel({ label }: { label: string }) {
|
function TypeLabel({ label }: { label: string }) {
|
||||||
return <div className="w-full h-8 bg-stone-100 dark:bg-zinc-700 px-2 flex items-center justify-center">{label}</div>;
|
return <div className="w-full h-8 align-middle font-semibold">{label}</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const CanvasNode: React.FC<CanvasNodeProps> = ({ data }) => {
|
const CanvasNode: React.FC<CanvasNodeProps> = ({ data }) => {
|
||||||
@@ -26,7 +26,7 @@ const CanvasNode: React.FC<CanvasNodeProps> = ({ data }) => {
|
|||||||
const { inputs, outputs, parameters, flow_type: flowType } = node;
|
const { inputs, outputs, parameters, flow_type: flowType } = node;
|
||||||
const [isHovered, setIsHovered] = useState(false);
|
const [isHovered, setIsHovered] = useState(false);
|
||||||
const reactFlow = useReactFlow();
|
const reactFlow = useReactFlow();
|
||||||
|
|
||||||
function onHover() {
|
function onHover() {
|
||||||
setIsHovered(true);
|
setIsHovered(true);
|
||||||
}
|
}
|
||||||
@@ -74,20 +74,24 @@ const CanvasNode: React.FC<CanvasNodeProps> = ({ data }) => {
|
|||||||
function renderOutput(data: IFlowNode) {
|
function renderOutput(data: IFlowNode) {
|
||||||
if (flowType === 'operator' && outputs?.length > 0) {
|
if (flowType === 'operator' && outputs?.length > 0) {
|
||||||
return (
|
return (
|
||||||
<>
|
<div className="bg-zinc-100 rounded p-2">
|
||||||
<TypeLabel label="Outputs" />
|
<TypeLabel label="Outputs" />
|
||||||
{(outputs || []).map((output, index) => (
|
<div className="text-sm flex flex-col space-y-3">
|
||||||
<NodeHandler key={`${data.id}_input_${index}`} node={data} data={output} type="source" label="outputs" index={index} />
|
{outputs?.map((output, index) => (
|
||||||
))}
|
<NodeHandler key={`${data.id}_input_${index}`} node={data} data={output} type="source" label="outputs" index={index} />
|
||||||
</>
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
} else if (flowType === 'resource') {
|
} else if (flowType === 'resource') {
|
||||||
// resource nodes show output default
|
// resource nodes show output default
|
||||||
return (
|
return (
|
||||||
<>
|
<div className="bg-zinc-100 rounded p-2">
|
||||||
<TypeLabel label="Outputs" />
|
<TypeLabel label="Outputs" />
|
||||||
<NodeHandler key={`${data.id}_input_0`} node={data} data={data} type="source" label="outputs" index={0} />
|
<div className="text-sm">
|
||||||
</>
|
<NodeHandler key={`${data.id}_input_0`} node={data} data={data} type="source" label="outputs" index={0} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -105,7 +109,15 @@ const CanvasNode: React.FC<CanvasNodeProps> = ({ data }) => {
|
|||||||
<DeleteOutlined className="h-full text-lg cursor-pointer" onClick={deleteNode} />
|
<DeleteOutlined className="h-full text-lg cursor-pointer" onClick={deleteNode} />
|
||||||
</IconWrapper>
|
</IconWrapper>
|
||||||
<IconWrapper className="mt-2">
|
<IconWrapper className="mt-2">
|
||||||
<Tooltip title={<><p className="font-bold">{node.label}</p><p>{node.description}</p></>} placement="right">
|
<Tooltip
|
||||||
|
title={
|
||||||
|
<>
|
||||||
|
<p className="font-bold">{node.label}</p>
|
||||||
|
<p>{node.description}</p>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
placement="right"
|
||||||
|
>
|
||||||
<InfoCircleOutlined className="h-full text-lg cursor-pointer" />
|
<InfoCircleOutlined className="h-full text-lg cursor-pointer" />
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</IconWrapper>
|
</IconWrapper>
|
||||||
@@ -113,36 +125,46 @@ const CanvasNode: React.FC<CanvasNodeProps> = ({ data }) => {
|
|||||||
}
|
}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
className={classNames('w-72 h-auto rounded-xl shadow-md p-0 border bg-white dark:bg-zinc-800 cursor-grab', {
|
className={classNames(
|
||||||
'border-blue-500': node.selected || isHovered,
|
'w-72 h-auto rounded-xl shadow-md px-2 py-4 border bg-white dark:bg-zinc-800 cursor-grab flex flex-col space-y-2 text-sm',
|
||||||
'border-stone-400 dark:border-white': !node.selected && !isHovered,
|
{
|
||||||
'border-dashed': flowType !== 'operator',
|
'border-blue-500': node.selected || isHovered,
|
||||||
'border-red-600': node.invalid,
|
'border-stone-400 dark:border-white': !node.selected && !isHovered,
|
||||||
})}
|
'border-dashed': flowType !== 'operator',
|
||||||
|
'border-red-600': node.invalid,
|
||||||
|
},
|
||||||
|
)}
|
||||||
onMouseEnter={onHover}
|
onMouseEnter={onHover}
|
||||||
onMouseLeave={onLeave}
|
onMouseLeave={onLeave}
|
||||||
>
|
>
|
||||||
{/* icon and label */}
|
{/* icon and label */}
|
||||||
<div className="flex flex-row items-center p-2">
|
<div className="flex flex-row items-center">
|
||||||
<Image src={'/icons/node/vis.png'} width={24} height={24} alt="" />
|
<Image src={'/icons/node/vis.png'} width={24} height={24} alt="" />
|
||||||
<p className="ml-2 text-lg font-bold text-ellipsis overflow-hidden whitespace-nowrap">{node.label}</p>
|
<p className="ml-2 text-lg font-bold text-ellipsis overflow-hidden whitespace-nowrap">{node.label}</p>
|
||||||
</div>
|
</div>
|
||||||
{inputs && inputs.length > 0 && (
|
|
||||||
<>
|
{inputs?.length > 0 && (
|
||||||
|
<div className="bg-zinc-100 rounded p-2">
|
||||||
<TypeLabel label="Inputs" />
|
<TypeLabel label="Inputs" />
|
||||||
{(inputs || []).map((input, index) => (
|
<div className="text-sm flex flex-col space-y-2">
|
||||||
<NodeHandler key={`${node.id}_input_${index}`} node={node} data={input} type="target" label="inputs" index={index} />
|
{inputs?.map((input, index) => (
|
||||||
))}
|
<NodeHandler key={`${node.id}_input_${index}`} node={node} data={input} type="target" label="inputs" index={index} />
|
||||||
</>
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
{parameters && parameters.length > 0 && (
|
|
||||||
<>
|
{parameters?.length > 0 && (
|
||||||
|
<div className="bg-zinc-100 rounded p-2">
|
||||||
<TypeLabel label="Parameters" />
|
<TypeLabel label="Parameters" />
|
||||||
{(parameters || []).map((parameter, index) => (
|
<div className="text-sm flex flex-col space-y-3 text-neutral-500">
|
||||||
<NodeParamHandler key={`${node.id}_param_${index}`} node={node} data={parameter} label="parameters" index={index} />
|
{parameters?.map((parameter, index) => (
|
||||||
))}
|
<NodeParamHandler key={`${node.id}_param_${index}`} node={node} data={parameter} label="parameters" index={index} />
|
||||||
</>
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{renderOutput(node)}
|
{renderOutput(node)}
|
||||||
</div>
|
</div>
|
||||||
</Popover>
|
</Popover>
|
||||||
|
@@ -94,15 +94,15 @@ const NodeHandler: React.FC<NodeHandlerProps> = ({ node, data, type, label, inde
|
|||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<Handle
|
<Handle
|
||||||
className="w-2 h-2"
|
className={classNames('w-2 h-2', type === 'source' ? '-mr-4' : '-ml-4')}
|
||||||
type={type}
|
type={type}
|
||||||
position={type === 'source' ? Position.Right : Position.Left}
|
position={type === 'source' ? Position.Right : Position.Left}
|
||||||
id={`${node.id}|${label}|${index}`}
|
id={`${node.id}|${label}|${index}`}
|
||||||
isValidConnection={(connection) => isValidConnection(connection)}
|
isValidConnection={(connection) => isValidConnection(connection)}
|
||||||
/>
|
/>
|
||||||
<Typography
|
<Typography
|
||||||
className={classNames('p-2', {
|
className={classNames('bg-white w-full px-2 py-1 rounded text-neutral-500',{
|
||||||
'pr-4': label === 'outputs',
|
'text-right': label === 'outputs',
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<Popconfirm
|
<Popconfirm
|
||||||
|
@@ -39,7 +39,7 @@ const NodeParamHandler: React.FC<NodeParamHandlerProps> = ({ node, data, label,
|
|||||||
case 'int':
|
case 'int':
|
||||||
case 'float':
|
case 'float':
|
||||||
return (
|
return (
|
||||||
<div className="p-2 text-sm">
|
<div className="text-sm">
|
||||||
<p>
|
<p>
|
||||||
{data.label}:<RequiredIcon optional={data.optional} />
|
{data.label}:<RequiredIcon optional={data.optional} />
|
||||||
{data.description && (
|
{data.description && (
|
||||||
@@ -59,7 +59,7 @@ const NodeParamHandler: React.FC<NodeParamHandlerProps> = ({ node, data, label,
|
|||||||
);
|
);
|
||||||
case 'str':
|
case 'str':
|
||||||
return (
|
return (
|
||||||
<div className="p-2 text-sm">
|
<div className="text-sm">
|
||||||
<p>
|
<p>
|
||||||
{data.label}:<RequiredIcon optional={data.optional} />
|
{data.label}:<RequiredIcon optional={data.optional} />
|
||||||
{data.description && (
|
{data.description && (
|
||||||
@@ -86,11 +86,11 @@ const NodeParamHandler: React.FC<NodeParamHandlerProps> = ({ node, data, label,
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
case 'checkbox':
|
case 'bool':
|
||||||
defaultValue = defaultValue === 'False' ? false : defaultValue;
|
defaultValue = defaultValue === 'False' ? false : defaultValue;
|
||||||
defaultValue = defaultValue === 'True' ? true : defaultValue;
|
defaultValue = defaultValue === 'True' ? true : defaultValue;
|
||||||
return (
|
return (
|
||||||
<div className="p-2 text-sm">
|
<div className="text-sm">
|
||||||
<p>
|
<p>
|
||||||
{data.label}:<RequiredIcon optional={data.optional} />
|
{data.label}:<RequiredIcon optional={data.optional} />
|
||||||
{data.description && (
|
{data.description && (
|
||||||
|
@@ -13,15 +13,13 @@ export const RenderCascader = (params: Props) => {
|
|||||||
const attr = convertKeysToCamelCase(data.ui?.attr || {});
|
const attr = convertKeysToCamelCase(data.ui?.attr || {});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-2 text-sm">
|
<Cascader
|
||||||
<Cascader
|
{...attr}
|
||||||
{...attr}
|
options={data.options}
|
||||||
options={data.options}
|
defaultValue={defaultValue}
|
||||||
defaultValue={defaultValue}
|
placeholder="please select"
|
||||||
placeholder="please select"
|
className="w-full nodrag"
|
||||||
className="w-full nodrag"
|
onChange={onChange}
|
||||||
onChange={onChange}
|
/>
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@@ -14,7 +14,7 @@ export const RenderCheckbox = (params: Props) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
data.options?.length > 0 && (
|
data.options?.length > 0 && (
|
||||||
<div className="p-2 text-sm">
|
<div className="bg-white p-2 rounded">
|
||||||
<Checkbox.Group {...attr} options={data.options} defaultValue={defaultValue} onChange={onChange} />
|
<Checkbox.Group {...attr} options={data.options} defaultValue={defaultValue} onChange={onChange} />
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
@@ -17,9 +17,5 @@ export const RenderDatePicker = (params: Props) => {
|
|||||||
onChange(dateString);
|
onChange(dateString);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return <DatePicker {...attr} className="w-full" defaultValue={dayjs(defaultValue)} onChange={onChangeDate} />;
|
||||||
<div className="p-2 text-sm">
|
|
||||||
<DatePicker {...attr} className="w-full" defaultValue={dayjs(defaultValue)} onChange={onChangeDate} />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
@@ -13,16 +13,14 @@ export const RenderInput = (params: Props) => {
|
|||||||
const attr = convertKeysToCamelCase(data.ui?.attr || {});
|
const attr = convertKeysToCamelCase(data.ui?.attr || {});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-2 text-sm">
|
<Input
|
||||||
<Input
|
{...attr}
|
||||||
{...attr}
|
className="w-full"
|
||||||
className="w-full"
|
placeholder="please input"
|
||||||
placeholder="please input"
|
defaultValue={defaultValue}
|
||||||
defaultValue={defaultValue}
|
onChange={(e) => {
|
||||||
onChange={(e) => {
|
onChange(e.target.value);
|
||||||
onChange(e.target.value);
|
}}
|
||||||
}}
|
/>
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@@ -13,7 +13,7 @@ export const RenderRadio = (params: Props) => {
|
|||||||
const attr = convertKeysToCamelCase(data.ui?.attr || {});
|
const attr = convertKeysToCamelCase(data.ui?.attr || {});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-2 text-sm">
|
<div className="bg-white p-2 rounded">
|
||||||
<Radio.Group
|
<Radio.Group
|
||||||
{...attr}
|
{...attr}
|
||||||
options={data.options}
|
options={data.options}
|
||||||
|
@@ -13,15 +13,6 @@ export const RenderSelect = (params: Props) => {
|
|||||||
const attr = convertKeysToCamelCase(data.ui?.attr || {});
|
const attr = convertKeysToCamelCase(data.ui?.attr || {});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-2 text-sm">
|
<Select {...attr} className="w-full nodrag" placeholder="please select" defaultValue={defaultValue} options={data.options} onChange={onChange} />
|
||||||
<Select
|
|
||||||
{...attr}
|
|
||||||
className="w-full nodrag"
|
|
||||||
placeholder="please select"
|
|
||||||
defaultValue={defaultValue}
|
|
||||||
options={data.options}
|
|
||||||
onChange={onChange}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@@ -1,40 +0,0 @@
|
|||||||
import { IFlowNodeParameter } from '@/types/flow';
|
|
||||||
import { convertKeysToCamelCase } from '@/utils/flow';
|
|
||||||
import { Col, InputNumber, Row, Slider, Space } from 'antd';
|
|
||||||
import type { InputNumberProps } from 'antd';
|
|
||||||
import React, { useState } from 'react';
|
|
||||||
|
|
||||||
type TextAreaProps = {
|
|
||||||
data: IFlowNodeParameter;
|
|
||||||
defaultValue: any;
|
|
||||||
onChange: (value: any) => void;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const RenderSlider = (params: TextAreaProps) => {
|
|
||||||
const { data, defaultValue, onChange } = params;
|
|
||||||
const attr = convertKeysToCamelCase(data.ui?.attr || {});
|
|
||||||
const [inputValue, setInputValue] = useState(defaultValue);
|
|
||||||
|
|
||||||
const onChangeSlider: InputNumberProps['onChange'] = (newValue) => {
|
|
||||||
setInputValue(newValue as number);
|
|
||||||
onChange(newValue as number);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="p-2 text-sm">
|
|
||||||
{data?.ui?.show_input ? (
|
|
||||||
<Row>
|
|
||||||
<Col span={12}>
|
|
||||||
<Slider {...attr} onChange={onChangeSlider} value={typeof inputValue === 'number' ? inputValue : 0} />
|
|
||||||
</Col>
|
|
||||||
|
|
||||||
<Col span={4}>
|
|
||||||
<InputNumber {...attr} style={{ margin: '0 16px' }} value={inputValue} onChange={onChangeSlider} />
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
) : (
|
|
||||||
<Slider {...attr} onChange={onChangeSlider} value={typeof inputValue === 'number' ? inputValue : 0} />
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
@@ -21,7 +21,7 @@ export const RenderSlider = (params: TextAreaProps) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-2 text-sm">
|
<>
|
||||||
{data?.ui?.show_input ? (
|
{data?.ui?.show_input ? (
|
||||||
<Row>
|
<Row>
|
||||||
<Col span={12}>
|
<Col span={12}>
|
||||||
@@ -34,6 +34,6 @@ export const RenderSlider = (params: TextAreaProps) => {
|
|||||||
) : (
|
) : (
|
||||||
<Slider {...attr} onChange={onChangeSlider} value={typeof inputValue === 'number' ? inputValue : 0} />
|
<Slider {...attr} onChange={onChangeSlider} value={typeof inputValue === 'number' ? inputValue : 0} />
|
||||||
)}
|
)}
|
||||||
</div>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
import { IFlowNodeParameter } from '@/types/flow';
|
import { IFlowNodeParameter } from '@/types/flow';
|
||||||
import { Input } from 'antd';
|
import { Input } from 'antd';
|
||||||
import { convertKeysToCamelCase } from '@/utils/flow';
|
import { convertKeysToCamelCase } from '@/utils/flow';
|
||||||
|
import classNames from 'classnames';
|
||||||
|
|
||||||
const { TextArea } = Input;
|
const { TextArea } = Input;
|
||||||
|
|
||||||
@@ -12,11 +13,11 @@ type TextAreaProps = {
|
|||||||
|
|
||||||
export const RenderTextArea = (params: TextAreaProps) => {
|
export const RenderTextArea = (params: TextAreaProps) => {
|
||||||
const { data, defaultValue, onChange } = params;
|
const { data, defaultValue, onChange } = params;
|
||||||
convertKeysToCamelCase(data?.ui?.attr?.autosize || {});
|
const attr = convertKeysToCamelCase(data.ui?.attr || {});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-2 text-sm">
|
<div className={classNames({ 'mb-3': attr.showCount === true })}>
|
||||||
<TextArea {...data.ui.attr} defaultValue={defaultValue} onChange={(e) => onChange(e.target.value)} {...data.ui.attr.autosize} rows={4} />
|
<TextArea {...attr} defaultValue={defaultValue} onChange={onChange} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@@ -17,9 +17,5 @@ export const RenderTimePicker = (params: TextAreaProps) => {
|
|||||||
onChange(timeString);
|
onChange(timeString);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return <TimePicker {...attr} className="w-full" defaultValue={defaultValue} onChange={onChangeTime} />;
|
||||||
<div className="p-2 text-sm">
|
|
||||||
<TimePicker {...attr} className="w-full" defaultValue={defaultValue} onChange={onChangeTime} />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
@@ -79,18 +79,16 @@ export const RenderTreeSelect = (params: TextAreaProps) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="p-2 text-sm">
|
<TreeSelect
|
||||||
<TreeSelect
|
fieldNames={{ label: 'label', value: 'value', children: 'children' }}
|
||||||
fieldNames={{ label: 'label', value: 'value', children: 'children' }}
|
{...data.ui.attr}
|
||||||
{...data.ui.attr}
|
style={{ width: '100%' }}
|
||||||
style={{ width: '100%' }}
|
value={defaultValue}
|
||||||
value={defaultValue}
|
treeDefaultExpandAll
|
||||||
treeDefaultExpandAll
|
onChange={onChange}
|
||||||
onChange={onChange}
|
treeData={data.options}
|
||||||
treeData={data.options}
|
onDropdownVisibleChange={handleDropdownVisibleChange}
|
||||||
onDropdownVisibleChange={handleDropdownVisibleChange}
|
/>
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
// TODO: Implement the TreeSelect component
|
// TODO: Implement the TreeSelect component
|
||||||
// <TreeSelect
|
// <TreeSelect
|
||||||
|
Reference in New Issue
Block a user