### What problem does this PR solve? feat: add icon to graph nodes #918 ### Type of change - [x] New Feature (non-breaking change which adds functionality)tags/v0.8.0
| @@ -552,14 +552,12 @@ export const useSendMessage = ( | |||
| const { conversationId } = useGetChatSearchParams(); | |||
| const { handleInputChange, value, setValue } = useHandleMessageInputChange(); | |||
| const fetchConversation = useFetchConversation(); | |||
| const { handleClickConversation } = useClickConversationCard(); | |||
| const { send, answer, done } = useSendMessageWithSse(); | |||
| const sendMessage = useCallback( | |||
| async (message: string, id?: string) => { | |||
| const res: Response = await send({ | |||
| const res = await send({ | |||
| conversation_id: id ?? conversationId, | |||
| messages: [ | |||
| ...(conversation?.message ?? []).map((x: IMessage) => omit(x, 'id')), | |||
| @@ -570,7 +568,12 @@ export const useSendMessage = ( | |||
| ], | |||
| }); | |||
| if (res.status === 200) { | |||
| if (res && (res?.response.status !== 200 || res?.data?.retcode !== 0)) { | |||
| // cancel loading | |||
| setValue(message); | |||
| console.info('removeLatestMessage111'); | |||
| removeLatestMessage(); | |||
| } else { | |||
| if (id) { | |||
| console.info('111'); | |||
| // new conversation | |||
| @@ -579,15 +582,7 @@ export const useSendMessage = ( | |||
| console.info('222'); | |||
| // fetchConversation(conversationId); | |||
| } | |||
| } else { | |||
| console.info('333'); | |||
| // cancel loading | |||
| setValue(message); | |||
| console.info('removeLatestMessage111'); | |||
| removeLatestMessage(); | |||
| } | |||
| console.info('false'); | |||
| }, | |||
| [ | |||
| conversation?.message, | |||
| @@ -150,7 +150,7 @@ export const useSendSharedMessage = ( | |||
| const sendMessage = useCallback( | |||
| async (message: string, id?: string) => { | |||
| const res: Response = await send({ | |||
| const res = await send({ | |||
| conversation_id: id ?? conversationId, | |||
| quote: false, | |||
| messages: [ | |||
| @@ -162,12 +162,7 @@ export const useSendSharedMessage = ( | |||
| ], | |||
| }); | |||
| if (res?.status === 200) { | |||
| // const data = await fetchConversation(conversationId); | |||
| // if (data.retcode === 0) { | |||
| // setCurrentConversation(data.data); | |||
| // } | |||
| } else { | |||
| if (res && (res?.response.status !== 200 || res?.data?.retcode !== 0)) { | |||
| // cancel loading | |||
| setValue(message); | |||
| removeLatestMessage(); | |||
| @@ -1,6 +1,9 @@ | |||
| import classNames from 'classnames'; | |||
| import { Handle, NodeProps, Position } from 'reactflow'; | |||
| import { Space } from 'antd'; | |||
| import { Operator } from '../../constant'; | |||
| import OperatorIcon from '../../operator-icon'; | |||
| import styles from './index.less'; | |||
| export function TextUpdaterNode({ | |||
| @@ -9,7 +12,7 @@ export function TextUpdaterNode({ | |||
| selected, | |||
| }: NodeProps<{ label: string }>) { | |||
| return ( | |||
| <div | |||
| <section | |||
| className={classNames(styles.textUpdaterNode, { | |||
| [styles.selectedNode]: selected, | |||
| })} | |||
| @@ -30,7 +33,15 @@ export function TextUpdaterNode({ | |||
| > | |||
| {/* <PlusCircleOutlined style={{ fontSize: 10 }} /> */} | |||
| </Handle> | |||
| <div>{data.label}</div> | |||
| </div> | |||
| <div> | |||
| <Space> | |||
| <OperatorIcon | |||
| name={data.label as Operator} | |||
| fontSize={12} | |||
| ></OperatorIcon> | |||
| {data.label} | |||
| </Space> | |||
| </div> | |||
| </section> | |||
| ); | |||
| } | |||
| @@ -112,7 +112,7 @@ export const useSendMessage = ( | |||
| } | |||
| const res = await send(params); | |||
| if (res?.response.status !== 200 || res?.data?.retcode !== 0) { | |||
| if (res && (res?.response.status !== 200 || res?.data?.retcode !== 0)) { | |||
| antMessage.error(res?.data?.retmsg); | |||
| // cancel loading | |||
| @@ -2,6 +2,7 @@ import { | |||
| MergeCellsOutlined, | |||
| RocketOutlined, | |||
| SendOutlined, | |||
| SlidersOutlined, | |||
| } from '@ant-design/icons'; | |||
| export enum Operator { | |||
| @@ -11,10 +12,26 @@ export enum Operator { | |||
| Answer = 'Answer', | |||
| } | |||
| export const operatorIconMap = { | |||
| [Operator.Retrieval]: RocketOutlined, | |||
| [Operator.Generate]: MergeCellsOutlined, | |||
| [Operator.Answer]: SendOutlined, | |||
| [Operator.Begin]: SlidersOutlined, | |||
| }; | |||
| export const componentList = [ | |||
| { name: Operator.Retrieval, icon: <RocketOutlined />, description: '' }, | |||
| { name: Operator.Generate, icon: <MergeCellsOutlined />, description: '' }, | |||
| { name: Operator.Answer, icon: <SendOutlined />, description: '' }, | |||
| { | |||
| name: Operator.Retrieval, | |||
| description: '', | |||
| }, | |||
| { | |||
| name: Operator.Generate, | |||
| description: '', | |||
| }, | |||
| { | |||
| name: Operator.Answer, | |||
| description: '', | |||
| }, | |||
| ]; | |||
| export const initialRetrievalValues = { | |||
| @@ -1,8 +1,9 @@ | |||
| import { Avatar, Card, Flex, Layout, Space } from 'antd'; | |||
| import { Card, Flex, Layout, Space } from 'antd'; | |||
| import classNames from 'classnames'; | |||
| import { componentList } from '../constant'; | |||
| import { useHandleDrag } from '../hooks'; | |||
| import OperatorIcon from '../operator-icon'; | |||
| import styles from './index.less'; | |||
| const { Sider } = Layout; | |||
| @@ -24,25 +25,31 @@ const FlowSide = ({ setCollapsed, collapsed }: IProps) => { | |||
| onCollapse={(value) => setCollapsed(value)} | |||
| > | |||
| <Flex vertical gap={10} className={styles.siderContent}> | |||
| {componentList.map((x) => ( | |||
| <Card | |||
| key={x.name} | |||
| hoverable | |||
| draggable | |||
| className={classNames(styles.operatorCard)} | |||
| onDragStart={handleDragStart(x.name)} | |||
| > | |||
| <Flex justify="space-between" align="center"> | |||
| <Space size={15}> | |||
| <Avatar icon={x.icon} shape={'square'} /> | |||
| <section> | |||
| <b>{x.name}</b> | |||
| <div>{x.description}</div> | |||
| </section> | |||
| </Space> | |||
| </Flex> | |||
| </Card> | |||
| ))} | |||
| {componentList.map((x) => { | |||
| return ( | |||
| <Card | |||
| key={x.name} | |||
| hoverable | |||
| draggable | |||
| className={classNames(styles.operatorCard)} | |||
| onDragStart={handleDragStart(x.name)} | |||
| > | |||
| <Flex justify="space-between" align="center"> | |||
| <Space size={15}> | |||
| <OperatorIcon name={x.name}></OperatorIcon> | |||
| {/* <Avatar | |||
| icon={<OperatorIcon name={x.name}></OperatorIcon>} | |||
| shape={'square'} | |||
| /> */} | |||
| <section> | |||
| <b>{x.name}</b> | |||
| <div>{x.description}</div> | |||
| </section> | |||
| </Space> | |||
| </Flex> | |||
| </Card> | |||
| ); | |||
| })} | |||
| </Flex> | |||
| </Sider> | |||
| ); | |||
| @@ -0,0 +1,4 @@ | |||
| .icon { | |||
| color: rgb(59, 118, 244); | |||
| font-size: 24px; | |||
| } | |||
| @@ -0,0 +1,16 @@ | |||
| import React from 'react'; | |||
| import { Operator, operatorIconMap } from '../constant'; | |||
| import styles from './index.less'; | |||
| interface IProps { | |||
| name: Operator; | |||
| fontSize?: number; | |||
| } | |||
| const OperatorIcon = ({ name, fontSize }: IProps) => { | |||
| const Icon = operatorIconMap[name] || React.Fragment; | |||
| return <Icon className={styles.icon} style={{ fontSize }}></Icon>; | |||
| }; | |||
| export default OperatorIcon; | |||