Skip to content

Commit

Permalink
feat(chat): add export and import with content(issue 568) (epam#630)
Browse files Browse the repository at this point in the history
Co-authored-by: Irina_Kartun <[email protected]>
Co-authored-by: Mikita Butsko <[email protected]>
  • Loading branch information
3 people authored Feb 6, 2024
1 parent c943a03 commit 8e138fd
Show file tree
Hide file tree
Showing 54 changed files with 1,367 additions and 172 deletions.
2 changes: 2 additions & 0 deletions .ort.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ license_choices:
repository_license_choices:
- given: 'GPL-2.0-only OR MIT'
choice: 'MIT'
- given: 'GPL-3.0-or-later OR MIT'
choice: 'MIT'
resolutions:
rule_violations:
- message: "No license information is available for dependency \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Conversation } from '@/chat/types/chat';
import { LatestExportFormat } from '@/chat/types/export';
import { LatestExportFormat } from '@/chat/types/importExport';
import { FolderConversation } from '@/src/testData';
import { UploadDownloadData } from '@/src/ui/pages';
import { FileUtil } from '@/src/utils/fileUtil';
Expand Down
6 changes: 4 additions & 2 deletions apps/chat-e2e/src/testData/expectedConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export enum MenuOptions {
replay = 'Replay',
playback = 'Playback',
export = 'Export',
withAttachments = 'With attachments',
withoutAttachments = 'Without attachments',
moveTo = 'Move to',
share = 'Share',
publish = 'Publish',
Expand Down Expand Up @@ -111,8 +113,8 @@ export const Import = {
oldVersionAppFolderName: 'Version 1.x',
oldVersionAppFolderChatName: '3-5 GPT math',
v14AppBisonChatName: 'bison chat king',
v14AppImportedFilename: 'chatbot_ui_history_1-4_version.json',
v19AppImportedFilename: 'chatbot_ui_history_1-9_version.json',
v14AppImportedFilename: 'ai_dial_chat_history_1-4_version.json',
v19AppImportedFilename: 'ai_dial_chat_history_1-9_version.json',
v14AppFolderPromptName: 'Version 1.4 A*B',
oldVersionAppGpt35Message: '11 * 12 =',
};
Expand Down
19 changes: 15 additions & 4 deletions apps/chat-e2e/src/tests/chatExportImport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,11 @@ test(
conversationInFolder.folders.name,
conversationInFolder.conversations[0].name,
);
await conversationDropdownMenu.selectMenuOption(MenuOptions.export);
exportedData = await dialHomePage.downloadData(() =>
conversationDropdownMenu.selectMenuOption(MenuOptions.export),
conversationDropdownMenu.selectMenuOption(
MenuOptions.withoutAttachments,
),
);
});

Expand Down Expand Up @@ -526,8 +529,11 @@ test(
nestedFolders[levelsCount].name,
nestedConversations[levelsCount].name,
);
await conversationDropdownMenu.selectMenuOption(MenuOptions.export);
exportedData = await dialHomePage.downloadData(() =>
conversationDropdownMenu.selectMenuOption(MenuOptions.export),
conversationDropdownMenu.selectMenuOption(
MenuOptions.withoutAttachments,
),
);
});

Expand Down Expand Up @@ -644,8 +650,12 @@ test('Import a chat in nested folder', async ({
nestedFolders[i].name,
nestedConversations[i].name,
);
await conversationDropdownMenu.selectMenuOption(MenuOptions.export);
const exportedData = await dialHomePage.downloadData(
() => conversationDropdownMenu.selectMenuOption(MenuOptions.export),
() =>
conversationDropdownMenu.selectMenuOption(
MenuOptions.withoutAttachments,
),
`${i}.json`,
);
exportedConversations.push(exportedData);
Expand Down Expand Up @@ -750,8 +760,9 @@ test('Import a chat from nested folder which was moved to another place', async
nestedFolders[levelsCount].name,
thirdLevelFolderConversation.name,
);
await conversationDropdownMenu.selectMenuOption(MenuOptions.export);
exportedData = await dialHomePage.downloadData(() =>
conversationDropdownMenu.selectMenuOption(MenuOptions.export),
conversationDropdownMenu.selectMenuOption(MenuOptions.withoutAttachments),
);
});

Expand Down
11 changes: 9 additions & 2 deletions apps/chat/public/images/icons/loader.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion apps/chat/src/components/Chat/Addons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Translation } from '@/src/types/translation';
import { AddonsSelectors } from '@/src/store/addons/addons.reducers';
import { useAppSelector } from '@/src/store/hooks';

import { ModelIcon } from '../Chatbar/components/ModelIcon';
import { ModelIcon } from '../Chatbar/ModelIcon';

import { EntityMarkdownDescription } from '../Common/MarkdownDescription';
import Tooltip from '../Common/Tooltip';
Expand Down
3 changes: 1 addition & 2 deletions apps/chat/src/components/Chat/AddonsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import { Translation } from '@/src/types/translation';
import { AddonsSelectors } from '@/src/store/addons/addons.reducers';
import { useAppSelector } from '@/src/store/hooks';

import { ModelIcon } from '../Chatbar/components/ModelIcon';

import { ModelIcon } from '../Chatbar/ModelIcon';
import { EntityMarkdownDescription } from '../Common/MarkdownDescription';
import { NoResultsFound } from '../Common/NoResultsFound';

Expand Down
3 changes: 1 addition & 2 deletions apps/chat/src/components/Chat/ChatCompareSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ import { useAppSelector } from '@/src/store/hooks';
import { ModelsSelectors } from '@/src/store/models/models.reducers';
import { SettingsSelectors } from '@/src/store/settings/settings.reducers';

import { ModelIcon } from '../Chatbar/components/ModelIcon';

import { ModelIcon } from '../Chatbar/ModelIcon';
import { Combobox } from '../Common/Combobox';
import ShareIcon from '../Common/ShareIcon';

Expand Down
2 changes: 1 addition & 1 deletion apps/chat/src/components/Chat/ChatHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import { useAppDispatch, useAppSelector } from '@/src/store/hooks';
import { ModelsSelectors } from '@/src/store/models/models.reducers';
import { UISelectors } from '@/src/store/ui/ui.reducers';

import { ModelIcon } from '../Chatbar/components/ModelIcon';
import { ConfirmDialog } from '@/src/components/Common/ConfirmDialog';

import { ModelIcon } from '../Chatbar/ModelIcon';
import Tooltip from '../Common/Tooltip';
import { ChatInfoTooltip } from './ChatInfoTooltip';

Expand Down
2 changes: 1 addition & 1 deletion apps/chat/src/components/Chat/ChatInfoTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { EntityType } from '@/src/types/common';
import { OpenAIEntityAddon, OpenAIEntityModel } from '@/src/types/openai';
import { Translation } from '@/src/types/translation';

import { ModelIcon } from '../Chatbar/components/ModelIcon';
import { ModelIcon } from '../Chatbar/ModelIcon';

interface Props {
model: OpenAIEntityModel | ConversationEntityModel;
Expand Down
29 changes: 29 additions & 0 deletions apps/chat/src/components/Chat/ChatLoader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import classNames from 'classnames';

import { Spinner } from '../Common/Spinner';

interface Props {
size?: number;
slow?: boolean;
containerClassName?: string;
loaderClassName?: string;
dataQa?: string;
}

export default function ChatLoader({
size = 45,
containerClassName,
loaderClassName,
dataQa = 'chat-loader',
}: Props) {
return (
<div
className={classNames(
'flex w-full items-center justify-center',
containerClassName || 'h-full',
)}
>
<Spinner size={size} className={loaderClassName} dataQa={dataQa} />
</div>
);
}
2 changes: 1 addition & 1 deletion apps/chat/src/components/Chat/ChatMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ import { ModelsSelectors } from '@/src/store/models/models.reducers';
import { SettingsSelectors } from '@/src/store/settings/settings.reducers';
import { UISelectors } from '@/src/store/ui/ui.reducers';

import { ModelIcon } from '../Chatbar/components/ModelIcon';
import Tooltip from '@/src/components/Common/Tooltip';

import { ModelIcon } from '../Chatbar/ModelIcon';
import { ConfirmDialog } from '../Common/ConfirmDialog';
import { ErrorMessage } from '../Common/ErrorMessage';
import { AttachButton } from '../Files/AttachButton';
Expand Down
3 changes: 1 addition & 2 deletions apps/chat/src/components/Chat/ConversationSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import { ModelsSelectors } from '@/src/store/models/models.reducers';

import { DEFAULT_ASSISTANT_SUBMODEL } from '@/src/constants/default-settings';

import { ModelIcon } from '../Chatbar/components/ModelIcon';

import { ModelIcon } from '../Chatbar/ModelIcon';
import { Addons } from './Addons';
import { AssistantSubModelSelector } from './AssistantSubModelSelector';
import { ConversationSettingsModel } from './ConversationSettingsModels';
Expand Down
3 changes: 1 addition & 2 deletions apps/chat/src/components/Chat/ConversationSettingsModels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import { Translation } from '@/src/types/translation';
import { useAppSelector } from '@/src/store/hooks';
import { ModelsSelectors } from '@/src/store/models/models.reducers';

import { ModelIcon } from '../Chatbar/components/ModelIcon';

import { ModelIcon } from '../Chatbar/ModelIcon';
import { EntityMarkdownDescription } from '../Common/MarkdownDescription';
import { ModelsDialog } from './ModelsDialog';
import { ReplayAsIsButton } from './ReplayAsIsButton';
Expand Down
2 changes: 1 addition & 1 deletion apps/chat/src/components/Chat/MessageStage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { OpenAIEntityAddon } from '@/src/types/openai';
import { AddonsSelectors } from '@/src/store/addons/addons.reducers';
import { useAppSelector } from '@/src/store/hooks';

import { ModelIcon } from '@/src/components/Chatbar/components/ModelIcon';
import { ModelIcon } from '@/src/components/Chatbar/ModelIcon';

import ChevronDown from '../../../public/images/icons/chevron-down.svg';
import CircleCheck from '../../../public/images/icons/circle-check.svg';
Expand Down
3 changes: 1 addition & 2 deletions apps/chat/src/components/Chat/ModelDescription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { useTranslation } from 'next-i18next';
import { OpenAIEntityModel } from '@/src/types/openai';
import { Translation } from '@/src/types/translation';

import { ModelIcon } from '../Chatbar/components/ModelIcon';

import { ModelIcon } from '../Chatbar/ModelIcon';
import { EntityMarkdownDescription } from '../Common/MarkdownDescription';

interface Props {
Expand Down
3 changes: 1 addition & 2 deletions apps/chat/src/components/Chat/ModelsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import {
ModelsSelectors,
} from '@/src/store/models/models.reducers';

import { ModelIcon } from '../Chatbar/components/ModelIcon';

import { ModelIcon } from '../Chatbar/ModelIcon';
import { EntityMarkdownDescription } from '../Common/MarkdownDescription';
import { NoResultsFound } from '../Common/NoResultsFound';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import {

import Folder from '@/src/components/Folder/Folder';

import CollapsableSection from '../../Common/CollapsableSection';
import { BetweenFoldersLine } from '../../Sidebar/BetweenFoldersLine';
import CollapsableSection from '../Common/CollapsableSection';
import { BetweenFoldersLine } from '../Sidebar/BetweenFoldersLine';
import { ConversationComponent } from './Conversation';

interface ChatFolderProps {
Expand Down
7 changes: 3 additions & 4 deletions apps/chat/src/components/Chatbar/Chatbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ import { UISelectors } from '@/src/store/ui/ui.reducers';

import { DEFAULT_CONVERSATION_NAME } from '@/src/constants/default-settings';

import { ChatFolders } from './components/ChatFolders';
import { ChatbarSettings } from './components/ChatbarSettings';
import { Conversations } from './components/Conversations';

import PlusIcon from '../../../public/images/icons/plus-large.svg';
import Sidebar from '../Sidebar';
import { ChatFolders } from './ChatFolders';
import { ChatbarSettings } from './ChatbarSettings';
import { Conversations } from './Conversations';

const ChatActionsBlock = () => {
const { t } = useTranslation(Translation.SideBar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useCallback, useMemo, useState } from 'react';
import { useTranslation } from 'next-i18next';

import { FeatureType } from '@/src/types/common';
import { SupportedExportFormats } from '@/src/types/export';
import { SupportedExportFormats } from '@/src/types/importExport';
import { DisplayMenuItemProps } from '@/src/types/menu';
import { Translation } from '@/src/types/translation';

Expand All @@ -19,6 +19,7 @@ import {
ConversationsSelectors,
} from '@/src/store/conversations/conversations.reducers';
import { useAppDispatch, useAppSelector } from '@/src/store/hooks';
import { ImportExportActions } from '@/src/store/import-export/importExport.reducers';
import { SettingsSelectors } from '@/src/store/settings/settings.reducers';

import { DEFAULT_CONVERSATION_NAME } from '@/src/constants/default-settings';
Expand Down Expand Up @@ -57,6 +58,24 @@ export const ChatbarSettings = () => {
);
}, [dispatch]);

const jsonImportHandler = useCallback(
(jsonContent: SupportedExportFormats) => {
dispatch(
ImportExportActions.importConversations({
data: jsonContent as SupportedExportFormats,
}),
);
},
[dispatch],
);

const zipImportHandler = useCallback(
(zipFile: File) => {
dispatch(ImportExportActions.importZipConversations({ zipFile }));
},
[dispatch],
);

const menuItems: DisplayMenuItemProps[] = useMemo(
() => [
{
Expand All @@ -69,23 +88,27 @@ export const ChatbarSettings = () => {
},
{
name: t('Import conversations'),
onClick: (importJSON: unknown) => {
dispatch(
ConversationsActions.importConversations({
data: importJSON as SupportedExportFormats,
}),
);
onClick: (importArgs: unknown) => {
const typedArgs = importArgs as { content: unknown; zip?: boolean };

if (!typedArgs.zip) {
jsonImportHandler(typedArgs.content as SupportedExportFormats);
}
if (typedArgs.zip) {
zipImportHandler(typedArgs.content as File);
}
},
Icon: IconFileArrowLeft,
dataQa: 'import',
CustomTriggerRenderer: Import,
},
{
name: t('Export conversations'),
name: t('Export conversations without attachments'),
dataQa: 'export',
className: 'max-w-[158px]',
Icon: IconFileArrowRight,
onClick: () => {
dispatch(ConversationsActions.exportConversations());
dispatch(ImportExportActions.exportConversations());
},
},
{
Expand Down Expand Up @@ -116,7 +139,15 @@ export const ChatbarSettings = () => {
},
},
],
[dispatch, enabledFeatures, handleToggleCompare, isStreaming, t],
[
dispatch,
enabledFeatures,
handleToggleCompare,
isStreaming,
t,
jsonImportHandler,
zipImportHandler,
],
);

return (
Expand Down
Loading

0 comments on commit 8e138fd

Please sign in to comment.