From 0f860c221e68fd7dc8c042c4b7f5fe8795e79e05 Mon Sep 17 00:00:00 2001 From: Magomed-Elbi Dzhukalaev Date: Tue, 28 Jan 2025 14:26:32 +0300 Subject: [PATCH 1/2] fix(chat): modify playback mode to support custom buttons --- apps/chat/src/components/Chat/Chat.tsx | 2 +- .../chat/src/components/Chat/ChatStarters.tsx | 4 ++ .../Chat/Playback/PlaybackControls.tsx | 38 ++++++++++++++++--- 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/apps/chat/src/components/Chat/Chat.tsx b/apps/chat/src/components/Chat/Chat.tsx index a2e197c1c4..f0dfc3d26f 100644 --- a/apps/chat/src/components/Chat/Chat.tsx +++ b/apps/chat/src/components/Chat/Chat.tsx @@ -755,7 +755,7 @@ export const ChatView = memo(() => { /> )} - {!isPlayback && } + {!isPlayback && ( { const dispatch = useAppDispatch(); const formValue = useAppSelector(ChatSelectors.selectChatFormValue); + const isPlayback = useAppSelector( + ConversationsSelectors.selectIsPlaybackSelectedConversations, + ); const handleChange = useCallback( (property: string, value: MessageFormValueType, submit?: boolean) => { @@ -56,6 +59,7 @@ const ChatStartersView = ({ schema }: ChatStartersViewProps) => { buttonsWrapperClassName="md:justify-center flex-nowrap overflow-x-auto overflow-y-hidden px-2" buttonClassName="shrink-0" propertyWrapperClassName="items-center" + disabled={isPlayback} /> ); }; diff --git a/apps/chat/src/components/Chat/Playback/PlaybackControls.tsx b/apps/chat/src/components/Chat/Playback/PlaybackControls.tsx index 59762260c2..db3632252c 100644 --- a/apps/chat/src/components/Chat/Playback/PlaybackControls.tsx +++ b/apps/chat/src/components/Chat/Playback/PlaybackControls.tsx @@ -12,8 +12,13 @@ import { useTranslation } from 'next-i18next'; import classNames from 'classnames'; +import { + getConfigurationValue, + getMessageFormValue, +} from '@/src/utils/app/form-schema'; import { hasParentWithFloatingOverlay } from '@/src/utils/app/modals'; +import { ChatActions } from '@/src/store/chat/chat.reducer'; import { ConversationsActions, ConversationsSelectors, @@ -26,6 +31,8 @@ import { ScrollDownButton } from '@/src/components/Common/ScrollDownButton'; import { ChatInputFooter } from '../ChatInput/ChatInputFooter'; import { PlaybackAttachments } from './PlaybackAttachments'; +import { Attachment } from '@epam/ai-dial-shared'; + interface Props { showScrollDownButton: boolean; onScrollDownClick: () => void; @@ -105,17 +112,21 @@ export const PlaybackControls = ({ currentMessage && currentMessage?.custom_content?.attachments?.length ? currentMessage.custom_content.attachments : []; + const form_value = + getMessageFormValue(currentMessage) ?? + getConfigurationValue(currentMessage); const message = attachments.length - ? { content, custom_content: { attachments } } - : { content }; + ? { content, custom_content: { attachments, form_value } } + : { content, custom_content: { form_value } }; return message; }, [activeIndex, isActiveIndex, isNextMessageInStack, selectedConversations]); - const hasAttachments = + const hasAttachments = !!( activeMessage && activeMessage.custom_content && activeMessage.custom_content.attachments && - activeMessage.custom_content.attachments.length; + activeMessage.custom_content.attachments.length + ); const handlePlayNextMessage = useCallback(() => { if (isMessageStreaming || !isNextMessageInStack) { @@ -209,6 +220,21 @@ export const PlaybackControls = ({ }; }, [controlsContainerRef, onResize]); + useEffect(() => { + if ( + phase === PlaybackPhases.MESSAGE && + activeMessage?.custom_content?.form_value + ) { + Object.entries(activeMessage.custom_content.form_value).forEach( + ([property, value]) => { + dispatch(ChatActions.setFormValue({ property, value })); + }, + ); + } else if (phase === PlaybackPhases.EMPTY) { + dispatch(ChatActions.resetFormValue()); + } + }, [activeMessage?.custom_content?.form_value, dispatch, phase]); + return (
)}