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

feat: update style of canvas node #1829

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions web/components/common/gpt-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function GPTCard({
return icon;
}, [icon]);

// TODO: 算子资源标签
const tagNode = useMemo(() => {
if (!tags || !tags.length) return null;
return (
Expand Down
82 changes: 52 additions & 30 deletions web/components/flow/canvas-node.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ type CanvasNodeProps = {
const ICON_PATH_PREFIX = '/icons/node/';

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 node = data;
const { inputs, outputs, parameters, flow_type: flowType } = node;
const [isHovered, setIsHovered] = useState(false);
const reactFlow = useReactFlow();

function onHover() {
setIsHovered(true);
}
Expand Down Expand Up @@ -74,20 +74,24 @@ const CanvasNode: React.FC<CanvasNodeProps> = ({ data }) => {
function renderOutput(data: IFlowNode) {
if (flowType === 'operator' && outputs?.length > 0) {
return (
<>
<div className="bg-zinc-100 rounded p-2">
<TypeLabel label="Outputs" />
{(outputs || []).map((output, index) => (
<NodeHandler key={`${data.id}_input_${index}`} node={data} data={output} type="source" label="outputs" index={index} />
))}
</>
<div className="text-sm flex flex-col space-y-3">
{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') {
// resource nodes show output default
return (
<>
<div className="bg-zinc-100 rounded p-2">
<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>
);
}
}
Expand All @@ -105,44 +109,62 @@ const CanvasNode: React.FC<CanvasNodeProps> = ({ data }) => {
<DeleteOutlined className="h-full text-lg cursor-pointer" onClick={deleteNode} />
</IconWrapper>
<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" />
</Tooltip>
</IconWrapper>
</>
}
>
<div
className={classNames('w-72 h-auto rounded-xl shadow-md p-0 border bg-white dark:bg-zinc-800 cursor-grab', {
'border-blue-500': node.selected || isHovered,
'border-stone-400 dark:border-white': !node.selected && !isHovered,
'border-dashed': flowType !== 'operator',
'border-red-600': node.invalid,
})}
className={classNames(
'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-blue-500': node.selected || isHovered,
'border-stone-400 dark:border-white': !node.selected && !isHovered,
'border-dashed': flowType !== 'operator',
'border-red-600': node.invalid,
},
)}
onMouseEnter={onHover}
onMouseLeave={onLeave}
>
{/* 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="" />
<p className="ml-2 text-lg font-bold text-ellipsis overflow-hidden whitespace-nowrap">{node.label}</p>
</div>
{inputs && inputs.length > 0 && (
<>

{inputs?.length > 0 && (
<div className="bg-zinc-100 rounded p-2">
<TypeLabel label="Inputs" />
{(inputs || []).map((input, index) => (
<NodeHandler key={`${node.id}_input_${index}`} node={node} data={input} type="target" label="inputs" index={index} />
))}
</>
<div className="text-sm flex flex-col space-y-2">
{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" />
{(parameters || []).map((parameter, index) => (
<NodeParamHandler key={`${node.id}_param_${index}`} node={node} data={parameter} label="parameters" index={index} />
))}
</>
<div className="text-sm flex flex-col space-y-3 text-neutral-500">
{parameters?.map((parameter, index) => (
<NodeParamHandler key={`${node.id}_param_${index}`} node={node} data={parameter} label="parameters" index={index} />
))}
</div>
</div>
)}

{renderOutput(node)}
</div>
</Popover>
Expand Down
6 changes: 3 additions & 3 deletions web/components/flow/node-handler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ const NodeHandler: React.FC<NodeHandlerProps> = ({ node, data, type, label, inde
})}
>
<Handle
className="w-2 h-2"
className={classNames('w-2 h-2', type === 'source' ? '-mr-4' : '-ml-4')}
type={type}
position={type === 'source' ? Position.Right : Position.Left}
id={`${node.id}|${label}|${index}`}
isValidConnection={(connection) => isValidConnection(connection)}
/>
<Typography
className={classNames('p-2', {
'pr-4': label === 'outputs',
className={classNames('bg-white w-full px-2 py-1 rounded text-neutral-500',{
'text-right': label === 'outputs',
})}
>
<Popconfirm
Expand Down
8 changes: 4 additions & 4 deletions web/components/flow/node-param-handler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const NodeParamHandler: React.FC<NodeParamHandlerProps> = ({ node, data, label,
case 'int':
case 'float':
return (
<div className="p-2 text-sm">
<div className="text-sm">
<p>
{data.label}:<RequiredIcon optional={data.optional} />
{data.description && (
Expand All @@ -59,7 +59,7 @@ const NodeParamHandler: React.FC<NodeParamHandlerProps> = ({ node, data, label,
);
case 'str':
return (
<div className="p-2 text-sm">
<div className="text-sm">
<p>
{data.label}:<RequiredIcon optional={data.optional} />
{data.description && (
Expand All @@ -86,11 +86,11 @@ const NodeParamHandler: React.FC<NodeParamHandlerProps> = ({ node, data, label,
)}
</div>
);
case 'checkbox':
case 'bool':
defaultValue = defaultValue === 'False' ? false : defaultValue;
defaultValue = defaultValue === 'True' ? true : defaultValue;
return (
<div className="p-2 text-sm">
<div className="text-sm">
<p>
{data.label}:<RequiredIcon optional={data.optional} />
{data.description && (
Expand Down
18 changes: 8 additions & 10 deletions web/components/flow/node-renderer/cascader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ export const RenderCascader = (params: Props) => {
const attr = convertKeysToCamelCase(data.ui?.attr || {});

return (
<div className="p-2 text-sm">
<Cascader
{...attr}
options={data.options}
defaultValue={defaultValue}
placeholder="please select"
className="w-full nodrag"
onChange={onChange}
/>
</div>
<Cascader
{...attr}
options={data.options}
defaultValue={defaultValue}
placeholder="please select"
className="w-full nodrag"
onChange={onChange}
/>
);
};
2 changes: 1 addition & 1 deletion web/components/flow/node-renderer/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const RenderCheckbox = (params: Props) => {

return (
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} />
</div>
)
Expand Down
6 changes: 1 addition & 5 deletions web/components/flow/node-renderer/date-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,5 @@ export const RenderDatePicker = (params: Props) => {
onChange(dateString);
};

return (
<div className="p-2 text-sm">
<DatePicker {...attr} className="w-full" defaultValue={dayjs(defaultValue)} onChange={onChangeDate} />
</div>
);
return <DatePicker {...attr} className="w-full" defaultValue={dayjs(defaultValue)} onChange={onChangeDate} />;
};
20 changes: 9 additions & 11 deletions web/components/flow/node-renderer/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@ export const RenderInput = (params: Props) => {
const attr = convertKeysToCamelCase(data.ui?.attr || {});

return (
<div className="p-2 text-sm">
<Input
{...attr}
className="w-full"
placeholder="please input"
defaultValue={defaultValue}
onChange={(e) => {
onChange(e.target.value);
}}
/>
</div>
<Input
{...attr}
className="w-full"
placeholder="please input"
defaultValue={defaultValue}
onChange={(e) => {
onChange(e.target.value);
}}
/>
);
};
2 changes: 1 addition & 1 deletion web/components/flow/node-renderer/radio.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const RenderRadio = (params: Props) => {
const attr = convertKeysToCamelCase(data.ui?.attr || {});

return (
<div className="p-2 text-sm">
<div className="bg-white p-2 rounded">
<Radio.Group
{...attr}
options={data.options}
Expand Down
11 changes: 1 addition & 10 deletions web/components/flow/node-renderer/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ export const RenderSelect = (params: Props) => {
const attr = convertKeysToCamelCase(data.ui?.attr || {});

return (
<div className="p-2 text-sm">
<Select
{...attr}
className="w-full nodrag"
placeholder="please select"
defaultValue={defaultValue}
options={data.options}
onChange={onChange}
/>
</div>
<Select {...attr} className="w-full nodrag" placeholder="please select" defaultValue={defaultValue} options={data.options} onChange={onChange} />
);
};
40 changes: 0 additions & 40 deletions web/components/flow/node-renderer/slider-list.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions web/components/flow/node-renderer/slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const RenderSlider = (params: TextAreaProps) => {
};

return (
<div className="p-2 text-sm">
<>
{data?.ui?.show_input ? (
<Row>
<Col span={12}>
Expand All @@ -34,6 +34,6 @@ export const RenderSlider = (params: TextAreaProps) => {
) : (
<Slider {...attr} onChange={onChangeSlider} value={typeof inputValue === 'number' ? inputValue : 0} />
)}
</div>
</>
);
};
7 changes: 4 additions & 3 deletions web/components/flow/node-renderer/textarea.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IFlowNodeParameter } from '@/types/flow';
import { Input } from 'antd';
import { convertKeysToCamelCase } from '@/utils/flow';
import classNames from 'classnames';

const { TextArea } = Input;

Expand All @@ -12,11 +13,11 @@ type TextAreaProps = {

export const RenderTextArea = (params: TextAreaProps) => {
const { data, defaultValue, onChange } = params;
convertKeysToCamelCase(data?.ui?.attr?.autosize || {});
const attr = convertKeysToCamelCase(data.ui?.attr || {});

return (
<div className="p-2 text-sm">
<TextArea {...data.ui.attr} defaultValue={defaultValue} onChange={(e) => onChange(e.target.value)} {...data.ui.attr.autosize} rows={4} />
<div className={classNames({ 'mb-3': attr.showCount === true })}>
<TextArea {...attr} defaultValue={defaultValue} onChange={onChange} />
</div>
);
};
6 changes: 1 addition & 5 deletions web/components/flow/node-renderer/time-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,5 @@ export const RenderTimePicker = (params: TextAreaProps) => {
onChange(timeString);
};

return (
<div className="p-2 text-sm">
<TimePicker {...attr} className="w-full" defaultValue={defaultValue} onChange={onChangeTime} />
</div>
);
return <TimePicker {...attr} className="w-full" defaultValue={defaultValue} onChange={onChangeTime} />;
};
Loading
Loading