Skip to content

Commit

Permalink
fix(chat): hide message templates in schema chats
Browse files Browse the repository at this point in the history
  • Loading branch information
Magomed-Elbi Dzhukalaev committed Jan 28, 2025
1 parent 0f860c2 commit c6cba0d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
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
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),
);

0 comments on commit c6cba0d

Please sign in to comment.