diff --git a/apps/chat/src/components/Chat/ChangePathDialog.tsx b/apps/chat/src/components/Chat/ChangePathDialog.tsx index 5eb9a03c1..fc09444bc 100644 --- a/apps/chat/src/components/Chat/ChangePathDialog.tsx +++ b/apps/chat/src/components/Chat/ChangePathDialog.tsx @@ -165,9 +165,24 @@ export const ChangePathDialog = ({ return; } + const trimmedName = newName.trim(); + const newOpenedFolderIds = openedFoldersIds.map((id) => { + if (id === folderId || id.startsWith(`${folderId}/`)) { + const renamedFolderPartsCount = folderId.split('/').length; + const currentIdParts = id.split('/'); + currentIdParts[renamedFolderPartsCount - 1] = trimmedName; + + return constructPath(...currentIdParts); + } + + return id; + }); + + setOpenedFoldersIds(newOpenedFolderIds); + dispatch(actions.renameTemporaryFolder({ folderId, name: newName })); }, - [actions, dispatch, folders, t], + [actions, dispatch, folders, openedFoldersIds, t], ); const handleAddFolder = useCallback( diff --git a/apps/chat/src/components/Common/ApplicationWizard/CodeAppView/CodeEditor.tsx b/apps/chat/src/components/Common/ApplicationWizard/CodeAppView/CodeEditor.tsx index 8f33b5d61..254ef54e5 100644 --- a/apps/chat/src/components/Common/ApplicationWizard/CodeAppView/CodeEditor.tsx +++ b/apps/chat/src/components/Common/ApplicationWizard/CodeAppView/CodeEditor.tsx @@ -281,6 +281,7 @@ export const CodeEditor = ({ sourcesFolderId, setValue }: Props) => { const modifiedFileIds = useAppSelector( CodeEditorSelectors.selectModifiedFileIds, ); + const newFolderId = useAppSelector(FilesSelectors.selectNewAddedFolderId); const filesContent = useAppSelector(CodeEditorSelectors.selectFilesContent); const [openedFoldersIds, setOpenedFoldersIds] = useState([]); @@ -438,6 +439,14 @@ export const CodeEditor = ({ sourcesFolderId, setValue }: Props) => { loadingFolderIds={loadingFolderIds} openedFoldersIds={openedFoldersIds} allItems={files} + onRenameFolder={(newName, folderId) => + dispatch( + FilesActions.renameFolder({ + folderId, + newName, + }), + ) + } onAddFolder={(parentId) => dispatch(FilesActions.addNewFolder({ parentId })) } diff --git a/apps/chat/src/components/Common/FolderContextMenu.tsx b/apps/chat/src/components/Common/FolderContextMenu.tsx index d70c7632a..8d3156f87 100644 --- a/apps/chat/src/components/Common/FolderContextMenu.tsx +++ b/apps/chat/src/components/Common/FolderContextMenu.tsx @@ -26,6 +26,7 @@ import { FolderInterface } from '@/src/types/folder'; import { DisplayMenuItemProps } from '@/src/types/menu'; import { Translation } from '@/src/types/translation'; +import { FilesSelectors } from '@/src/store/files/files.reducers'; import { useAppSelector } from '@/src/store/hooks'; import { SettingsSelectors } from '@/src/store/settings/settings.reducers'; @@ -78,6 +79,7 @@ export const FolderContextMenu = ({ const isSharingEnabled = useAppSelector((state) => SettingsSelectors.isSharingEnabled(state, featureType), ); + const newFileFolderId = useAppSelector(FilesSelectors.selectNewAddedFolderId); const isExternal = isEntityIdExternal(folder); const isNameInvalid = isEntityNameInvalid(folder.name); @@ -103,7 +105,12 @@ export const FolderContextMenu = ({ }, { name: t('Rename'), - display: (!!onRename && !isExternal) || !!folder.temporary, + display: + (!!onRename && + !isExternal && + (featureType !== FeatureType.File || + newFileFolderId === folder.id)) || + !!folder.temporary, dataQa: 'rename', Icon: IconPencilMinus, onClick: onRename, @@ -205,6 +212,7 @@ export const FolderContextMenu = ({ onUpload, disableAll, onRename, + newFileFolderId, folder, isNameInvalid, isEmpty, diff --git a/apps/chat/src/store/conversations/conversations.reducers.ts b/apps/chat/src/store/conversations/conversations.reducers.ts index b52db8ad0..08e2736ce 100644 --- a/apps/chat/src/store/conversations/conversations.reducers.ts +++ b/apps/chat/src/store/conversations/conversations.reducers.ts @@ -6,6 +6,7 @@ import { combineEntities } from '@/src/utils/app/common'; import { constructPath } from '@/src/utils/app/file'; import { addGeneratedFolderId, + getFolderIdFromEntityId, getNextDefaultName, isFolderEmpty, } from '@/src/utils/app/folders'; @@ -416,12 +417,26 @@ export const conversationsSlice = createSlice({ ) => { state.newAddedFolderId = undefined; const name = payload.name.trim(); - - state.temporaryFolders = state.temporaryFolders.map((folder) => - folder.id !== payload.folderId - ? folder - : { ...folder, name, id: constructPath(folder.folderId, name) }, + const newFolderId = constructPath( + getFolderIdFromEntityId(payload.folderId), + name, ); + + state.temporaryFolders = state.temporaryFolders.map((folder) => { + if (folder.id === payload.folderId) { + return { ...folder, name, id: newFolderId }; + } + + if (folder.id.startsWith(`${payload.folderId}/`)) { + return { + ...folder, + id: folder.id.replace(folder.folderId, newFolderId), + folderId: folder.folderId.replace(folder.folderId, newFolderId), + }; + } + + return folder; + }); }, resetNewFolderId: (state) => { state.newAddedFolderId = undefined; diff --git a/apps/chat/src/store/prompts/prompts.reducers.ts b/apps/chat/src/store/prompts/prompts.reducers.ts index 1df2fb678..22d226db3 100644 --- a/apps/chat/src/store/prompts/prompts.reducers.ts +++ b/apps/chat/src/store/prompts/prompts.reducers.ts @@ -4,6 +4,7 @@ import { combineEntities } from '@/src/utils/app/common'; import { constructPath } from '@/src/utils/app/file'; import { addGeneratedFolderId, + getFolderIdFromEntityId, getNextDefaultName, isFolderEmpty, } from '@/src/utils/app/folders'; @@ -251,10 +252,26 @@ export const promptsSlice = createSlice({ ) => { state.newAddedFolderId = undefined; const name = payload.name.trim(); - - state.temporaryFolders = state.temporaryFolders.map((folder) => - folder.id !== payload.folderId ? folder : { ...folder, name }, + const newFolderId = constructPath( + getFolderIdFromEntityId(payload.folderId), + name, ); + + state.temporaryFolders = state.temporaryFolders.map((folder) => { + if (folder.id === payload.folderId) { + return { ...folder, name, id: newFolderId }; + } + + if (folder.id.startsWith(`${payload.folderId}/`)) { + return { + ...folder, + id: folder.id.replace(folder.folderId, newFolderId), + folderId: folder.folderId.replace(folder.folderId, newFolderId), + }; + } + + return folder; + }); }, resetNewFolderId: (state) => { state.newAddedFolderId = undefined;