From fa5695c25050ab4a7cb804d3e13112be12df4efb Mon Sep 17 00:00:00 2001 From: balibabu Date: Thu, 27 Jun 2024 09:20:19 +0800 Subject: [PATCH] feat: add CategorizeHandle #918 (#1282) ### What problem does this PR solve? feat: add CategorizeHandle #918 ### Type of change - [x] New Feature (non-breaking change which adds functionality) --- .../flow/canvas/node/categorize-handle.tsx | 39 +++++++ web/src/pages/flow/canvas/node/index.less | 6 + web/src/pages/flow/canvas/node/index.tsx | 37 +++--- .../categorize-form/dynamic-categorize.tsx | 108 +++++++++++------- web/src/pages/flow/categorize-form/hooks.ts | 38 +++++- web/src/pages/flow/categorize-form/index.tsx | 2 +- web/src/pages/flow/constant.tsx | 15 +++ web/src/pages/flow/store.ts | 18 +++ 8 files changed, 198 insertions(+), 65 deletions(-) create mode 100644 web/src/pages/flow/canvas/node/categorize-handle.tsx diff --git a/web/src/pages/flow/canvas/node/categorize-handle.tsx b/web/src/pages/flow/canvas/node/categorize-handle.tsx new file mode 100644 index 000000000..2d4329734 --- /dev/null +++ b/web/src/pages/flow/canvas/node/categorize-handle.tsx @@ -0,0 +1,39 @@ +import { Handle, Position } from 'reactflow'; +// import { v4 as uuid } from 'uuid'; + +import styles from './index.less'; + +const DEFAULT_HANDLE_STYLE = { + width: 6, + height: 6, + bottom: -5, + fontSize: 8, +}; + +interface IProps { + top: number; + right: number; + text: string; + idx: number; +} + +const CategorizeHandle = ({ top, right, text, idx }: IProps) => { + return ( + + {text} + + ); +}; + +export default CategorizeHandle; diff --git a/web/src/pages/flow/canvas/node/index.less b/web/src/pages/flow/canvas/node/index.less index bd42fd3ad..ffba5c07f 100644 --- a/web/src/pages/flow/canvas/node/index.less +++ b/web/src/pages/flow/canvas/node/index.less @@ -37,6 +37,12 @@ -3px 0 6px -4px rgba(0, 0, 0, 0.12), -6px 0 16px 6px rgba(0, 0, 0, 0.05); } + .categorizeAnchorPointText { + position: absolute; + top: -4px; + left: 8px; + white-space: nowrap; + } } .selectedNode { border: 1px solid rgb(59, 118, 244); diff --git a/web/src/pages/flow/canvas/node/index.tsx b/web/src/pages/flow/canvas/node/index.tsx index 41d121166..5d0fc1bda 100644 --- a/web/src/pages/flow/canvas/node/index.tsx +++ b/web/src/pages/flow/canvas/node/index.tsx @@ -4,12 +4,14 @@ import { Handle, NodeProps, Position } from 'reactflow'; import OperateDropdown from '@/components/operate-dropdown'; import { CopyOutlined } from '@ant-design/icons'; import { Flex, MenuProps, Space } from 'antd'; +import get from 'lodash/get'; import { useCallback } from 'react'; import { useTranslation } from 'react-i18next'; -import { Operator, operatorMap } from '../../constant'; +import { CategorizeAnchorPointPositions, Operator } from '../../constant'; import { NodeData } from '../../interface'; import OperatorIcon from '../../operator-icon'; import useGraphStore from '../../store'; +import CategorizeHandle from './categorize-handle'; import styles from './index.less'; export function RagNode({ @@ -30,7 +32,8 @@ export function RagNode({ duplicateNodeById(id); }, [id, duplicateNodeById]); - const description = operatorMap[data.label as Operator].description; + const isCategorize = data.label === Operator.Categorize; + const categoryData = get(data, 'form.category_description') ?? {}; const items: MenuProps['items'] = [ { @@ -57,9 +60,7 @@ export function RagNode({ position={Position.Left} isConnectable={isConnectable} className={styles.handle} - > - {/* */} - + > - {/* */} - + > + {isCategorize && + Object.keys(categoryData).map((x, idx) => ( + + ))} - {/* {data.label} */} - {/*
{id}
*/}
- {/*
- - {description} - -
*/} +
{id}
diff --git a/web/src/pages/flow/categorize-form/dynamic-categorize.tsx b/web/src/pages/flow/categorize-form/dynamic-categorize.tsx index 3bba4f41f..d02a0bce8 100644 --- a/web/src/pages/flow/categorize-form/dynamic-categorize.tsx +++ b/web/src/pages/flow/categorize-form/dynamic-categorize.tsx @@ -1,58 +1,78 @@ import { CloseOutlined } from '@ant-design/icons'; import { Button, Card, Form, Input, Select, Typography } from 'antd'; -import { useBuildCategorizeToOptions } from './hooks'; +import { useBuildCategorizeToOptions, useHandleToSelectChange } from './hooks'; -const DynamicCategorize = () => { +interface IProps { + nodeId?: string; +} + +const DynamicCategorize = ({ nodeId }: IProps) => { const form = Form.useFormInstance(); const options = useBuildCategorizeToOptions(); + const { handleSelectChange } = useHandleToSelectChange( + options.map((x) => x.value), + nodeId, + ); return ( <> - {(fields, { add, remove }) => ( -
- {fields.map((field) => ( - { - remove(field.name); - }} - /> - } - > - { + const handleAdd = () => { + const idx = fields.length; + add({ name: `Categorize ${idx + 1}` }); + }; + return ( +
+ {fields.map((field) => ( + { + remove(field.name); + }} + /> + } > - - - - - - - - - - + + + + + + + + +