feat: add icon to graph nodes #918 (#1117)

### 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)
This commit is contained in:
balibabu 2024-06-11 18:01:19 +08:00 committed by GitHub
parent 8902d92d0e
commit ff5ea266d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 91 additions and 46 deletions

View File

@ -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,

View File

@ -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();

View File

@ -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>
);
}

View File

@ -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

View File

@ -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 = {

View File

@ -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>
);

View File

@ -0,0 +1,4 @@
.icon {
color: rgb(59, 118, 244);
font-size: 24px;
}

View File

@ -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;