From c9961f88afc41702640fe6c85c48128781d54369 Mon Sep 17 00:00:00 2001 From: Ilya Bondar Date: Mon, 4 Nov 2024 23:22:20 +0100 Subject: [PATCH] feat(chat): collapse the file panel --- .../CodeAppView/CodeEditor.tsx | 250 +++++++++++------- apps/chat/src/utils/app/mobile.ts | 1 + 2 files changed, 153 insertions(+), 98 deletions(-) diff --git a/apps/chat/src/components/Common/ApplicationWizard/CodeAppView/CodeEditor.tsx b/apps/chat/src/components/Common/ApplicationWizard/CodeAppView/CodeEditor.tsx index 73b7c3166..3e29a2460 100644 --- a/apps/chat/src/components/Common/ApplicationWizard/CodeAppView/CodeEditor.tsx +++ b/apps/chat/src/components/Common/ApplicationWizard/CodeAppView/CodeEditor.tsx @@ -22,6 +22,7 @@ import { getNextDefaultName, } from '@/src/utils/app/folders'; import { getIdWithoutRootPathSegments } from '@/src/utils/app/id'; +import { isSmallScreenOrMobile } from '@/src/utils/app/mobile'; import { FeatureType } from '@/src/types/common'; import { DialFile } from '@/src/types/files'; @@ -33,6 +34,10 @@ import { SettingsSelectors } from '@/src/store/settings/settings.reducers'; import { UISelectors } from '@/src/store/ui/ui.reducers'; import { CODEAPPS_REQUIRED_FILES } from '@/src/constants/applications'; +import { + DEFAULT_HEADER_ICON_SIZE, + OVERLAY_HEADER_ICON_SIZE, +} from '@/src/constants/default-ui-settings'; import SidebarActionButton from '../../../Buttons/SidebarActionButton'; import { FileItem } from '../../../Files/FileItem'; @@ -46,6 +51,8 @@ import { FormData } from '../form'; import { CodeAppExamples } from './CodeAppExamples'; import FolderPlus from '@/public/images/icons/folder-plus.svg'; +import MoveLeftIcon from '@/public/images/icons/move-left.svg'; +import MoveRightIcon from '@/public/images/icons/move-right.svg'; import { UploadStatus } from '@epam/ai-dial-shared'; interface CodeEditorFile { @@ -193,6 +200,8 @@ export const CodeEditor = ({ const [uploadFolderId, setUploadFolderId] = useState(); const [deletingFileId, setDeletingFileId] = useState(); const [isFullScreen, setIsFullScreen] = useState(false); + const [showPanel, setShowPanel] = useState(!isSmallScreenOrMobile()); + const isOverlay = useAppSelector(SettingsSelectors.selectIsOverlay); const { rootFiles, rootFolders } = useMemo(() => { if (sourcesFolderId) { @@ -312,119 +321,164 @@ export const CodeEditor = ({ return null; } + const headerIconSize = isOverlay + ? OVERLAY_HEADER_ICON_SIZE + : DEFAULT_HEADER_ICON_SIZE; + return ( <>
-
- {rootFolders.map((folder) => { - return ( - - dispatch(FilesActions.addNewFolder({ parentId })) - } - itemComponent={(props) => ( - - )} - onClickFolder={(folderId) => { - if (openedFoldersIds.includes(folderId)) { - const childFoldersIds = getChildAndCurrentFoldersIdsById( - folderId, - folders, - ); - setOpenedFoldersIds( - openedFoldersIds.filter( - (id) => !childFoldersIds.includes(id), - ), - ); - } else { - setOpenedFoldersIds(openedFoldersIds.concat(folderId)); - const folder = folders.find((f) => f.id === folderId); - if (folder?.status !== UploadStatus.LOADED) { - dispatch( - FilesActions.getFilesWithFolders({ id: folderId }), - ); - } - } - }} - withBorderHighlight={false} - featureType={FeatureType.File} - /> - ); - })} - {rootFiles.map((file) => ( - setShowPanel(!showPanel)} + > + {showPanel ? ( + - ))} - {newFileFolder && ( -
- - setNewFileName(e.target.value)} - onKeyDown={handleUploadEmptyFile} - autoFocus - /> -
- - + )} +
+
+ {showPanel && ( + <> + {rootFolders.map((folder) => { + return ( + + dispatch(FilesActions.addNewFolder({ parentId })) + } + itemComponent={(props) => ( + + )} + onClickFolder={(folderId) => { + if (openedFoldersIds.includes(folderId)) { + const childFoldersIds = + getChildAndCurrentFoldersIdsById(folderId, folders); + setOpenedFoldersIds( + openedFoldersIds.filter( + (id) => !childFoldersIds.includes(id), + ), + ); + } else { + setOpenedFoldersIds( + openedFoldersIds.concat(folderId), + ); + const folder = folders.find((f) => f.id === folderId); + if (folder?.status !== UploadStatus.LOADED) { + dispatch( + FilesActions.getFilesWithFolders({ + id: folderId, + }), + ); + } + } + }} + withBorderHighlight={false} + featureType={FeatureType.File} /> - - { - setNewFileFolder(undefined); - setNewFileName(''); - }} - dataQA="cancel-edit" + ); + })} + {rootFiles.map((file) => ( + + ))} + {newFileFolder && showPanel && ( +
- + setNewFileName(e.target.value)} + onKeyDown={handleUploadEmptyFile} + autoFocus /> - -
-
+
+ + + + { + setNewFileFolder(undefined); + setNewFileName(''); + }} + dataQA="cancel-edit" + > + + +
+
+ )} + )}
-
+