From b2031393560294f7d59f133a35b84c2288189504 Mon Sep 17 00:00:00 2001 From: "Junjie.M" <118170653@qq.com> Date: Wed, 23 Apr 2025 22:57:42 +0800 Subject: [PATCH] embedding in websites setting conversation_id requires hiding reset conversation button (#18623) --- web/app/components/base/chat/embedded-chatbot/context.tsx | 2 ++ .../components/base/chat/embedded-chatbot/header/index.tsx | 6 ++++-- web/app/components/base/chat/embedded-chatbot/hooks.tsx | 2 ++ web/app/components/base/chat/embedded-chatbot/index.tsx | 4 ++++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/web/app/components/base/chat/embedded-chatbot/context.tsx b/web/app/components/base/chat/embedded-chatbot/context.tsx index eb5e9d697f..fb00dbd64d 100644 --- a/web/app/components/base/chat/embedded-chatbot/context.tsx +++ b/web/app/components/base/chat/embedded-chatbot/context.tsx @@ -39,6 +39,7 @@ export type EmbeddedChatbotContextValue = { chatShouldReloadKey: string isMobile: boolean isInstalledApp: boolean + allowResetChat: boolean appId?: string handleFeedback: (messageId: string, feedback: Feedback) => void currentChatInstanceRef: RefObject<{ handleStop: () => void }> @@ -67,6 +68,7 @@ export const EmbeddedChatbotContext = createContext chatShouldReloadKey: '', isMobile: false, isInstalledApp: false, + allowResetChat: true, handleFeedback: noop, currentChatInstanceRef: { current: { handleStop: noop } }, clearChatList: false, diff --git a/web/app/components/base/chat/embedded-chatbot/header/index.tsx b/web/app/components/base/chat/embedded-chatbot/header/index.tsx index d05e7a650c..c38a4546dd 100644 --- a/web/app/components/base/chat/embedded-chatbot/header/index.tsx +++ b/web/app/components/base/chat/embedded-chatbot/header/index.tsx @@ -16,6 +16,7 @@ import cn from '@/utils/classnames' export type IHeaderProps = { isMobile?: boolean + allowResetChat?: boolean customerIcon?: React.ReactNode title: string theme?: Theme @@ -23,6 +24,7 @@ export type IHeaderProps = { } const Header: FC = ({ isMobile, + allowResetChat, customerIcon, title, theme, @@ -57,7 +59,7 @@ const Header: FC = ({ {currentConversationId && ( )} - {currentConversationId && ( + {currentConversationId && allowResetChat && ( @@ -89,7 +91,7 @@ const Header: FC = ({
- {currentConversationId && ( + {currentConversationId && allowResetChat && ( diff --git a/web/app/components/base/chat/embedded-chatbot/hooks.tsx b/web/app/components/base/chat/embedded-chatbot/hooks.tsx index cfd2acb17f..7efbc95dee 100644 --- a/web/app/components/base/chat/embedded-chatbot/hooks.tsx +++ b/web/app/components/base/chat/embedded-chatbot/hooks.tsx @@ -111,6 +111,7 @@ export const useEmbeddedChatbot = () => { const [conversationIdInfo, setConversationIdInfo] = useLocalStorageState>>(CONVERSATION_ID_INFO, { defaultValue: {}, }) + const allowResetChat = !conversationId const currentConversationId = useMemo(() => conversationIdInfo?.[appId || '']?.[userId || 'DEFAULT'] || conversationId || '', [appId, conversationIdInfo, userId, conversationId]) const handleConversationIdInfoChange = useCallback((changeConversationId: string) => { @@ -365,6 +366,7 @@ export const useEmbeddedChatbot = () => { appInfoError, appInfoLoading, isInstalledApp, + allowResetChat, appId, currentConversationId, currentConversationItem, diff --git a/web/app/components/base/chat/embedded-chatbot/index.tsx b/web/app/components/base/chat/embedded-chatbot/index.tsx index aaf59ca4e4..96dff67bf4 100644 --- a/web/app/components/base/chat/embedded-chatbot/index.tsx +++ b/web/app/components/base/chat/embedded-chatbot/index.tsx @@ -25,6 +25,7 @@ import cn from '@/utils/classnames' const Chatbot = () => { const { isMobile, + allowResetChat, appInfoError, appInfoLoading, appData, @@ -90,6 +91,7 @@ const Chatbot = () => { >
{ handleNewConversationCompleted, chatShouldReloadKey, isInstalledApp, + allowResetChat, appId, handleFeedback, currentChatInstanceRef, @@ -187,6 +190,7 @@ const EmbeddedChatbotWrapper = () => { chatShouldReloadKey, isMobile, isInstalledApp, + allowResetChat, appId, handleFeedback, currentChatInstanceRef,