Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(chat): add new code editor folder renaming and fix issue with temporary folders renaming (Issues #2542, #2293) #2565

Open
wants to merge 5 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion apps/chat/src/components/Chat/ChangePathDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@
const modifiedFileIds = useAppSelector(
CodeEditorSelectors.selectModifiedFileIds,
);
const newFolderId = useAppSelector(FilesSelectors.selectNewAddedFolderId);

Check failure on line 284 in apps/chat/src/components/Common/ApplicationWizard/CodeAppView/CodeEditor.tsx

View workflow job for this annotation

GitHub Actions / run_tests / test / style_checks

'newFolderId' is assigned a value but never used. Allowed unused vars must match /^__/u
const filesContent = useAppSelector(CodeEditorSelectors.selectFilesContent);

const [openedFoldersIds, setOpenedFoldersIds] = useState<string[]>([]);
Expand Down Expand Up @@ -438,6 +439,14 @@
loadingFolderIds={loadingFolderIds}
openedFoldersIds={openedFoldersIds}
allItems={files}
onRenameFolder={(newName, folderId) =>
dispatch(
FilesActions.renameFolder({
folderId,
newName,
}),
)
}
onAddFolder={(parentId) =>
dispatch(FilesActions.addNewFolder({ parentId }))
}
Expand Down
10 changes: 9 additions & 1 deletion apps/chat/src/components/Common/FolderContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down Expand Up @@ -205,6 +212,7 @@ export const FolderContextMenu = ({
onUpload,
disableAll,
onRename,
newFileFolderId,
folder,
isNameInvalid,
isEmpty,
Expand Down
25 changes: 20 additions & 5 deletions apps/chat/src/store/conversations/conversations.reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down
23 changes: 20 additions & 3 deletions apps/chat/src/store/prompts/prompts.reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down
Loading