diff --git a/client/src/components/Chat/ChatBody/AllCoversations/index.tsx b/client/src/components/Chat/ChatBody/AllCoversations/index.tsx index 4924683d49..552d5da691 100644 --- a/client/src/components/Chat/ChatBody/AllCoversations/index.tsx +++ b/client/src/components/Chat/ChatBody/AllCoversations/index.tsx @@ -21,7 +21,10 @@ import { OpenChatHistoryItem, } from '../../../../types/general'; import { conversationsCache } from '../../../../services/cache'; -import { mapLoadingSteps } from '../../../../mappers/conversation'; +import { + mapLoadingSteps, + mapUserQuery, +} from '../../../../mappers/conversation'; import { LocaleContext } from '../../../../context/localeContext'; import { getDateFnsLocale } from '../../../../utils'; import ConversationListItem from './ConversationListItem'; @@ -63,9 +66,11 @@ const AllConversations = ({ resp.forEach((m) => { // @ts-ignore const userQuery = m.search_steps.find((s) => s.type === 'QUERY'); + const parsedQuery = mapUserQuery(m); conv.push({ author: ChatMessageAuthor.User, - text: m.query?.target?.Plain || userQuery?.content?.query || '', + text: m.query.raw_query || userQuery?.content?.query || '', + parsedQuery, isFromHistory: true, }); conv.push({ diff --git a/client/src/components/Chat/ChatBody/Conversation.tsx b/client/src/components/Chat/ChatBody/Conversation.tsx index 6346ab00b3..314d43f795 100644 --- a/client/src/components/Chat/ChatBody/Conversation.tsx +++ b/client/src/components/Chat/ChatBody/Conversation.tsx @@ -59,6 +59,9 @@ const Conversation = ({ isHistory={isHistory} author={m.author} message={m.text} + parsedQuery={ + m.author === ChatMessageAuthor.Server ? undefined : m.parsedQuery + } error={m.author === ChatMessageAuthor.Server ? m.error : ''} showInlineFeedback={ m.author === ChatMessageAuthor.Server && diff --git a/client/src/components/Chat/ChatBody/ConversationMessage/UserParsedQuery/LangChip.tsx b/client/src/components/Chat/ChatBody/ConversationMessage/UserParsedQuery/LangChip.tsx new file mode 100644 index 0000000000..025cf9b229 --- /dev/null +++ b/client/src/components/Chat/ChatBody/ConversationMessage/UserParsedQuery/LangChip.tsx @@ -0,0 +1,22 @@ +import FileIcon from '../../../../FileIcon'; +import { getFileExtensionForLang } from '../../../../../utils'; + +type Props = { + lang: string; +}; + +const LangChip = ({ lang }: Props) => { + return ( + + + + {lang} + + + ); +}; + +export default LangChip; diff --git a/client/src/components/Chat/ChatBody/ConversationMessage/UserParsedQuery/PathChip.tsx b/client/src/components/Chat/ChatBody/ConversationMessage/UserParsedQuery/PathChip.tsx new file mode 100644 index 0000000000..a20f299c07 --- /dev/null +++ b/client/src/components/Chat/ChatBody/ConversationMessage/UserParsedQuery/PathChip.tsx @@ -0,0 +1,31 @@ +import { useMemo } from 'react'; +import { FolderClosed, ArrowOut } from '../../../../../icons'; +import FileIcon from '../../../../FileIcon'; +import { splitPath } from '../../../../../utils'; + +type Props = { + path: string; +}; + +const PathChip = ({ path }: Props) => { + const isFolder = useMemo(() => path.endsWith('/'), [path]); + return ( + + + {isFolder ? ( + + ) : ( + + )} + + {isFolder ? path.replace(/\/$/, '') : splitPath(path).pop()} + + + + ); +}; + +export default PathChip; diff --git a/client/src/components/Chat/ChatBody/ConversationMessage/UserParsedQuery/index.tsx b/client/src/components/Chat/ChatBody/ConversationMessage/UserParsedQuery/index.tsx new file mode 100644 index 0000000000..17a671b16d --- /dev/null +++ b/client/src/components/Chat/ChatBody/ConversationMessage/UserParsedQuery/index.tsx @@ -0,0 +1,32 @@ +import { memo } from 'react'; +import { + ParsedQueryType, + ParsedQueryTypeEnum, +} from '../../../../../types/general'; +import PathChip from './PathChip'; +import LangChip from './LangChip'; + +type Props = { + textQuery: string; + parsedQuery?: ParsedQueryType[]; +}; + +const UserParsedQuery = ({ textQuery, parsedQuery }: Props) => { + return ( +
+ {parsedQuery + ? parsedQuery.map((p, i) => + p.type === ParsedQueryTypeEnum.TEXT ? ( + p.text + ) : p.type === ParsedQueryTypeEnum.PATH ? ( + + ) : p.type === ParsedQueryTypeEnum.LANG ? ( + + ) : null, + ) + : textQuery} +
+ ); +}; + +export default memo(UserParsedQuery); diff --git a/client/src/components/Chat/ChatBody/ConversationMessage/index.tsx b/client/src/components/Chat/ChatBody/ConversationMessage/index.tsx index af21e0a507..eb34863e50 100644 --- a/client/src/components/Chat/ChatBody/ConversationMessage/index.tsx +++ b/client/src/components/Chat/ChatBody/ConversationMessage/index.tsx @@ -10,7 +10,11 @@ import { WrenchAndScrewdriver, } from '../../../../icons'; import { DeviceContext } from '../../../../context/deviceContext'; -import { ChatLoadingStep, ChatMessageAuthor } from '../../../../types/general'; +import { + ChatLoadingStep, + ChatMessageAuthor, + ParsedQueryType, +} from '../../../../types/general'; import { ChatContext } from '../../../../context/chatContext'; import Button from '../../../Button'; import { LocaleContext } from '../../../../context/localeContext'; @@ -24,10 +28,12 @@ import { } from '../../../../services/storage'; import MessageFeedback from './MessageFeedback'; import FileChip from './FileChip'; +import UserParsedQuery from './UserParsedQuery'; type Props = { author: ChatMessageAuthor; message?: string; + parsedQuery?: ParsedQueryType[]; error?: string; threadId: string; queryId: string; @@ -61,6 +67,7 @@ const ConversationMessage = ({ onMessageEdit, responseTimestamp, singleFileExplanation, + parsedQuery, }: Props) => { const { t } = useTranslation(); const [isLoadingStepsShown, setLoadingStepsShown] = useState( @@ -172,7 +179,7 @@ const ConversationMessage = ({ )} - {message && ( + {!!message && (
{author === ChatMessageAuthor.Server ? ( ) : ( <> -
{message}
+ {!isHistory && !!queryId && (