Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(chat): fix custom buttons in playback mode, hide templates in schema chats (Issue #3002, #3013) #3035

Merged
merged 4 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/chat/src/components/Chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ export const ChatView = memo(() => {
/>
)}

{!isPlayback && <ChatStarters />}
<ChatStarters />

{!isPlayback && (
<ChatInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export const UserMessage = memo(function UserMessage({
SettingsSelectors.isFeatureEnabled(state, Feature.MessageTemplates),
);
const isChatFullWidth = useAppSelector(UISelectors.selectIsChatFullWidth);

const isMobileOrOverlay = isSmallScreen() || isOverlay;
const isInputDisabled = isMessageInputDisabled(messageIndex, allMessages);

Expand Down
12 changes: 10 additions & 2 deletions apps/chat/src/components/Chat/ChatMessage/MessageButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { getMessageCustomContent } from '@/src/utils/server/chat';

import { Translation } from '@/src/types/translation';

import { ConversationsSelectors } from '@/src/store/conversations/conversations.reducers';
import { useAppSelector } from '@/src/store/hooks';
import { SettingsSelectors } from '@/src/store/settings/settings.reducers';

Expand Down Expand Up @@ -68,6 +69,9 @@ export const MessageUserButtons = ({
const { t } = useTranslation(Translation.Chat);

const isOverlay = useAppSelector(SettingsSelectors.selectIsOverlay);
const isConversationsWithSchema = useAppSelector(
ConversationsSelectors.selectIsSelectedConversationsWithSchema,
);

return (
<div
Expand All @@ -78,7 +82,7 @@ export const MessageUserButtons = ({
>
{!isMessageStreaming && (
<>
{isEditTemplatesAvailable && (
{isEditTemplatesAvailable && !isConversationsWithSchema && (
<Tooltip
placement="top"
isTriggerClickable
Expand Down Expand Up @@ -274,6 +278,10 @@ export const MessageMobileButtons = ({
}: MessageMobileButtonsProps) => {
const { t } = useTranslation(Translation.Chat);

const isConversationsWithSchema = useAppSelector(
ConversationsSelectors.selectIsSelectedConversationsWithSchema,
);

const isAssistant = message.role === Role.Assistant;

if (isAssistant) {
Expand Down Expand Up @@ -389,7 +397,7 @@ export const MessageMobileButtons = ({
!isMessageStreaming &&
!isConversationInvalid && (
<>
{isEditTemplatesAvailable && (
{isEditTemplatesAvailable && !isConversationsWithSchema && (
<MenuItem
className="hover:bg-accent-primary-alpha focus:visible disabled:cursor-not-allowed group-hover:visible"
onClick={() => onToggleTemplatesEditing()}
Expand Down
4 changes: 4 additions & 0 deletions apps/chat/src/components/Chat/ChatStarters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const ChatStartersView = ({ schema }: ChatStartersViewProps) => {
const dispatch = useAppDispatch();

const formValue = useAppSelector(ChatSelectors.selectChatFormValue);
const isPlayback = useAppSelector(
ConversationsSelectors.selectIsPlaybackSelectedConversations,
);

const handleChange = useCallback(
(property: string, value: MessageFormValueType, submit?: boolean) => {
Expand Down Expand Up @@ -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}
/>
);
};
Expand Down
38 changes: 33 additions & 5 deletions apps/chat/src/components/Chat/Playback/PlaybackControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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 = !!(
Gimir marked this conversation as resolved.
Show resolved Hide resolved
activeMessage &&
activeMessage.custom_content &&
activeMessage.custom_content.attachments &&
activeMessage.custom_content.attachments.length;
activeMessage.custom_content.attachments.length
);

const handlePlayNextMessage = useCallback(() => {
if (isMessageStreaming || !isNextMessageInStack) {
Expand Down Expand Up @@ -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 (
<div ref={controlsContainerRef} className="w-full pt-3 md:pt-5">
<div
Expand Down Expand Up @@ -254,7 +280,9 @@ export const PlaybackControls = ({

{phase === PlaybackPhases.MESSAGE && hasAttachments && (
<PlaybackAttachments
attachments={activeMessage.custom_content.attachments}
attachments={
activeMessage.custom_content.attachments as Attachment[]
}
/>
)}
<button
Expand Down
10 changes: 9 additions & 1 deletion apps/chat/src/store/conversations/conversations.selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ import {
sortByName,
splitEntityId,
} from '@/src/utils/app/folders';
import { isMessageInputDisabled } from '@/src/utils/app/form-schema';
import {
isConversationWithFormSchema,
isMessageInputDisabled,
} from '@/src/utils/app/form-schema';
import {
getConversationRootId,
isEntityIdExternal,
Expand Down Expand Up @@ -852,3 +855,8 @@ export const selectIsSelectedConversationBlocksInput = createSelector(
),
),
);

export const selectIsSelectedConversationsWithSchema = createSelector(
[selectSelectedConversations],
(conversations) => conversations.some(isConversationWithFormSchema),
);