From 6bc21ee876bacbb1cf70f5bf8ad998fd8a08e78e Mon Sep 17 00:00:00 2001 From: bill Date: Thu, 29 Aug 2024 19:04:31 +0800 Subject: [PATCH] feat: Hide the delete button on the agent page #2088 --- .../components/message-item/group-button.tsx | 32 ++++++++++++------- web/src/components/message-item/hooks.ts | 4 +-- web/src/components/message-item/index.tsx | 5 ++- web/src/pages/flow/chat/box.tsx | 2 ++ 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/web/src/components/message-item/group-button.tsx b/web/src/components/message-item/group-button.tsx index cea7cfaa212..f99136c5bb4 100644 --- a/web/src/components/message-item/group-button.tsx +++ b/web/src/components/message-item/group-button.tsx @@ -20,12 +20,14 @@ interface IProps { messageId: string; content: string; prompt?: string; + showLikeButton: boolean; } export const AssistantGroupButton = ({ messageId, content, prompt, + showLikeButton, }: IProps) => { const { visible, hideModal, showModal, onFeedbackOk, loading } = useSendFeedback(messageId); @@ -51,12 +53,16 @@ export const AssistantGroupButton = ({ - - - - - - + {showLikeButton && ( + <> + + + + + + + + )} {prompt && ( @@ -82,7 +88,7 @@ export const AssistantGroupButton = ({ ); }; -interface UserGroupButtonProps extends IRemoveMessageById { +interface UserGroupButtonProps extends Partial { messageId: string; content: string; regenerateMessage(): void; @@ -116,11 +122,13 @@ export const UserGroupButton = ({ - - - - - + {removeMessageById && ( + + + + + + )} ); }; diff --git a/web/src/components/message-item/hooks.ts b/web/src/components/message-item/hooks.ts index 7009225701a..9e9a70f5cb7 100644 --- a/web/src/components/message-item/hooks.ts +++ b/web/src/components/message-item/hooks.ts @@ -34,7 +34,7 @@ export const useSendFeedback = (messageId: string) => { export const useRemoveMessage = ( messageId: string, - removeMessageById: IRemoveMessageById['removeMessageById'], + removeMessageById?: IRemoveMessageById['removeMessageById'], ) => { const { deleteMessage, loading } = useDeleteMessage(); @@ -43,7 +43,7 @@ export const useRemoveMessage = ( if (pureId) { const retcode = await deleteMessage(pureId); if (retcode === 0) { - removeMessageById(messageId); + removeMessageById?.(messageId); } } }, [deleteMessage, messageId, removeMessageById]); diff --git a/web/src/components/message-item/index.tsx b/web/src/components/message-item/index.tsx index 510dd84b285..b66b7874cb9 100644 --- a/web/src/components/message-item/index.tsx +++ b/web/src/components/message-item/index.tsx @@ -24,7 +24,7 @@ import styles from './index.less'; const { Text } = Typography; -interface IProps extends IRemoveMessageById, IRegenerateMessage { +interface IProps extends Partial, IRegenerateMessage { item: IMessage; reference: IReference; loading?: boolean; @@ -33,6 +33,7 @@ interface IProps extends IRemoveMessageById, IRegenerateMessage { avatar?: string; clickDocumentButton?: (documentId: string, chunk: IChunk) => void; index: number; + showLikeButton?: boolean; } const MessageItem = ({ @@ -45,6 +46,7 @@ const MessageItem = ({ index, removeMessageById, regenerateMessage, + showLikeButton = true, }: IProps) => { const isAssistant = item.role === MessageType.Assistant; const isUser = item.role === MessageType.User; @@ -128,6 +130,7 @@ const MessageItem = ({ messageId={item.id} content={item.content} prompt={item.prompt} + showLikeButton={showLikeButton} > ) ) : ( diff --git a/web/src/pages/flow/chat/box.tsx b/web/src/pages/flow/chat/box.tsx index a88e3774a26..5a0372f8568 100644 --- a/web/src/pages/flow/chat/box.tsx +++ b/web/src/pages/flow/chat/box.tsx @@ -58,6 +58,8 @@ const FlowChatBox = () => { )} clickDocumentButton={clickDocumentButton} index={i} + regenerateMessage={() => {}} + showLikeButton={false} > ); })}