From f8c786e223fd31c90222639b25a0ed68eb2dadca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A8=E6=AC=A3?= Date: Wed, 14 Aug 2024 23:54:47 +0800 Subject: [PATCH] feat: update style of canvas node --- web/components/common/gpt-card.tsx | 1 + web/components/flow/canvas-node.tsx | 82 ++++++++++++------- web/components/flow/node-handler.tsx | 6 +- web/components/flow/node-param-handler.tsx | 8 +- .../flow/node-renderer/cascader.tsx | 18 ++-- .../flow/node-renderer/checkbox.tsx | 2 +- .../flow/node-renderer/date-picker.tsx | 6 +- web/components/flow/node-renderer/input.tsx | 20 ++--- web/components/flow/node-renderer/radio.tsx | 2 +- web/components/flow/node-renderer/select.tsx | 11 +-- .../flow/node-renderer/slider-list.tsx | 40 --------- web/components/flow/node-renderer/slider.tsx | 4 +- .../flow/node-renderer/textarea.tsx | 7 +- .../flow/node-renderer/time-picker.tsx | 6 +- .../flow/node-renderer/tree-select.tsx | 22 +++-- 15 files changed, 98 insertions(+), 137 deletions(-) delete mode 100644 web/components/flow/node-renderer/slider-list.tsx diff --git a/web/components/common/gpt-card.tsx b/web/components/common/gpt-card.tsx index 730d459d9..8ab7e0ccc 100644 --- a/web/components/common/gpt-card.tsx +++ b/web/components/common/gpt-card.tsx @@ -59,6 +59,7 @@ function GPTCard({ return icon; }, [icon]); + // TODO: 算子资源标签 const tagNode = useMemo(() => { if (!tags || !tags.length) return null; return ( diff --git a/web/components/flow/canvas-node.tsx b/web/components/flow/canvas-node.tsx index ebc1c20a5..de33a0e7b 100644 --- a/web/components/flow/canvas-node.tsx +++ b/web/components/flow/canvas-node.tsx @@ -18,7 +18,7 @@ type CanvasNodeProps = { const ICON_PATH_PREFIX = '/icons/node/'; function TypeLabel({ label }: { label: string }) { - return
{label}
; + return
{label}
; } const CanvasNode: React.FC = ({ data }) => { @@ -26,7 +26,7 @@ const CanvasNode: React.FC = ({ data }) => { const { inputs, outputs, parameters, flow_type: flowType } = node; const [isHovered, setIsHovered] = useState(false); const reactFlow = useReactFlow(); - + function onHover() { setIsHovered(true); } @@ -74,20 +74,24 @@ const CanvasNode: React.FC = ({ data }) => { function renderOutput(data: IFlowNode) { if (flowType === 'operator' && outputs?.length > 0) { return ( - <> +
- {(outputs || []).map((output, index) => ( - - ))} - +
+ {outputs?.map((output, index) => ( + + ))} +
+
); } else if (flowType === 'resource') { // resource nodes show output default return ( - <> +
- - +
+ +
+
); } } @@ -105,7 +109,15 @@ const CanvasNode: React.FC = ({ data }) => { -

{node.label}

{node.description}

} placement="right"> + +

{node.label}

+

{node.description}

+ + } + placement="right" + >
@@ -113,36 +125,46 @@ const CanvasNode: React.FC = ({ data }) => { } >
{/* icon and label */} -
+

{node.label}

- {inputs && inputs.length > 0 && ( - <> + + {inputs?.length > 0 && ( +
- {(inputs || []).map((input, index) => ( - - ))} - +
+ {inputs?.map((input, index) => ( + + ))} +
+
)} - {parameters && parameters.length > 0 && ( - <> + + {parameters?.length > 0 && ( +
- {(parameters || []).map((parameter, index) => ( - - ))} - +
+ {parameters?.map((parameter, index) => ( + + ))} +
+
)} + {renderOutput(node)}
diff --git a/web/components/flow/node-handler.tsx b/web/components/flow/node-handler.tsx index 0db0599e8..9b7682291 100644 --- a/web/components/flow/node-handler.tsx +++ b/web/components/flow/node-handler.tsx @@ -94,15 +94,15 @@ const NodeHandler: React.FC = ({ node, data, type, label, inde })} > isValidConnection(connection)} /> = ({ node, data, label, case 'int': case 'float': return ( -
+

{data.label}: {data.description && ( @@ -59,7 +59,7 @@ const NodeParamHandler: React.FC = ({ node, data, label, ); case 'str': return ( -

+

{data.label}: {data.description && ( @@ -86,11 +86,11 @@ const NodeParamHandler: React.FC = ({ node, data, label, )}

); - case 'checkbox': + case 'bool': defaultValue = defaultValue === 'False' ? false : defaultValue; defaultValue = defaultValue === 'True' ? true : defaultValue; return ( -
+

{data.label}: {data.description && ( diff --git a/web/components/flow/node-renderer/cascader.tsx b/web/components/flow/node-renderer/cascader.tsx index 4c9d69ac8..118c3ac40 100644 --- a/web/components/flow/node-renderer/cascader.tsx +++ b/web/components/flow/node-renderer/cascader.tsx @@ -13,15 +13,13 @@ export const RenderCascader = (params: Props) => { const attr = convertKeysToCamelCase(data.ui?.attr || {}); return ( -

- -
+ ); }; diff --git a/web/components/flow/node-renderer/checkbox.tsx b/web/components/flow/node-renderer/checkbox.tsx index 34b8ac657..0500d3498 100644 --- a/web/components/flow/node-renderer/checkbox.tsx +++ b/web/components/flow/node-renderer/checkbox.tsx @@ -14,7 +14,7 @@ export const RenderCheckbox = (params: Props) => { return ( data.options?.length > 0 && ( -
+
) diff --git a/web/components/flow/node-renderer/date-picker.tsx b/web/components/flow/node-renderer/date-picker.tsx index d69538a61..25ddd33cc 100644 --- a/web/components/flow/node-renderer/date-picker.tsx +++ b/web/components/flow/node-renderer/date-picker.tsx @@ -17,9 +17,5 @@ export const RenderDatePicker = (params: Props) => { onChange(dateString); }; - return ( -
- -
- ); + return ; }; diff --git a/web/components/flow/node-renderer/input.tsx b/web/components/flow/node-renderer/input.tsx index 8a47d3d2f..538d14081 100644 --- a/web/components/flow/node-renderer/input.tsx +++ b/web/components/flow/node-renderer/input.tsx @@ -13,16 +13,14 @@ export const RenderInput = (params: Props) => { const attr = convertKeysToCamelCase(data.ui?.attr || {}); return ( -
- { - onChange(e.target.value); - }} - /> -
+ { + onChange(e.target.value); + }} + /> ); }; diff --git a/web/components/flow/node-renderer/radio.tsx b/web/components/flow/node-renderer/radio.tsx index 1bc1763a6..056681ef4 100644 --- a/web/components/flow/node-renderer/radio.tsx +++ b/web/components/flow/node-renderer/radio.tsx @@ -13,7 +13,7 @@ export const RenderRadio = (params: Props) => { const attr = convertKeysToCamelCase(data.ui?.attr || {}); return ( -
+
{ const attr = convertKeysToCamelCase(data.ui?.attr || {}); return ( -
- ); }; diff --git a/web/components/flow/node-renderer/slider-list.tsx b/web/components/flow/node-renderer/slider-list.tsx deleted file mode 100644 index a1e3553f4..000000000 --- a/web/components/flow/node-renderer/slider-list.tsx +++ /dev/null @@ -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 ( -
- {data?.ui?.show_input ? ( - - - - - - - - - - ) : ( - - )} -
- ); -}; diff --git a/web/components/flow/node-renderer/slider.tsx b/web/components/flow/node-renderer/slider.tsx index bb8456adb..1017e20bb 100644 --- a/web/components/flow/node-renderer/slider.tsx +++ b/web/components/flow/node-renderer/slider.tsx @@ -21,7 +21,7 @@ export const RenderSlider = (params: TextAreaProps) => { }; return ( -
+ <> {data?.ui?.show_input ? ( @@ -34,6 +34,6 @@ export const RenderSlider = (params: TextAreaProps) => { ) : ( )} -
+ ); }; diff --git a/web/components/flow/node-renderer/textarea.tsx b/web/components/flow/node-renderer/textarea.tsx index 5f8c55ac0..4a2c40f20 100644 --- a/web/components/flow/node-renderer/textarea.tsx +++ b/web/components/flow/node-renderer/textarea.tsx @@ -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; @@ -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 ( -
-