Skip to content

Commit

Permalink
Merge pull request #921 from internxt/bugfix/PB-1235-create-folder-wi…
Browse files Browse the repository at this point in the history
…hitin-the-move

[PB-1235] bugfix/Put new created folder in move levels collection
  • Loading branch information
CandelR authored Nov 17, 2023
2 parents d83b06f + 0238347 commit 625b121
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ const CreateFolderDialog = ({ onFolderCreated, currentFolderId, neededFolderId }
}, [isOpen]);

const onClose = (): void => {
setIsLoading(false);
dispatch(uiActions.setIsCreateFolderDialogOpen(false));
if (!isLoading) {
dispatch(uiActions.setIsCreateFolderDialogOpen(false));
}
};

const createFolder = async () => {
Expand Down
47 changes: 23 additions & 24 deletions src/app/drive/components/MoveItemsDialog/MoveItemsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,38 @@ const MoveItemsDialog = (props: MoveItemsDialogProps): JSX.Element => {

useEffect(() => {
if (isOpen) {
setIsLoading(true);
setCurrentNamePaths([]);
onShowFolderContentClicked(props.parentFolderId ?? rootFolderID, 'Drive');
setIsLoading(false);
}
}, [isOpen]);

useEffect(() => {
if (isOpen && !newFolderIsOpen) {
onShowFolderContentClicked(currentFolderId, currentFolderName);
}
}, [newFolderIsOpen]);

const onShowFolderContentClicked = (folderId: number, name: string): void => {
setIsLoading(true);
dispatch(fetchDialogContentThunk(folderId))
.unwrap()
.then(() => {
getDatabaseItems(folderId, name);
});
retrieveMoveDialogItems(folderId, name);
})
.finally(() => setIsLoading(false));
};

const getDatabaseItems = (folderId: number, name: string) => {
const handleDialogBreadcrumbs = (folderId: number, name: string) => {
let auxCurrentPaths: FolderPathDialog[] = [...currentNamePaths];
const currentIndex = auxCurrentPaths.findIndex((i) => {
return i.id === folderId;
});
if (currentIndex > -1) {
auxCurrentPaths = auxCurrentPaths.slice(0, currentIndex + 1);
dispatch(storageActions.popNamePathDialogUpTo({ id: folderId, name: name }));
} else {
auxCurrentPaths.push({ id: folderId, name: name });
dispatch(storageActions.pushNamePathDialog({ id: folderId, name: name }));
}

setCurrentNamePaths(auxCurrentPaths);
};

const retrieveMoveDialogItems = (folderId: number, name: string) => {
databaseService.get(DatabaseCollection.MoveDialogLevels, folderId).then((items) => {
setCurrentFolderId(folderId);
setCurrentFolderName(name);
Expand All @@ -99,19 +109,8 @@ const MoveItemsDialog = (props: MoveItemsDialogProps): JSX.Element => {
return i.isFolder;
});

let auxCurrentPaths: FolderPathDialog[] = [...currentNamePaths];
const currentIndex = auxCurrentPaths.findIndex((i) => {
return i.id === folderId;
});
if (currentIndex > -1) {
auxCurrentPaths = auxCurrentPaths.slice(0, currentIndex + 1);
dispatch(storageActions.popNamePathDialogUpTo({ id: folderId, name: name }));
} else {
auxCurrentPaths.push({ id: folderId, name: name });
dispatch(storageActions.pushNamePathDialog({ id: folderId, name: name }));
}
handleDialogBreadcrumbs(folderId, name);

setCurrentNamePaths(auxCurrentPaths);
if (folders) {
const unselectedFolders = folders.filter((item) => item.id != itemsToMove[0].id);
setShownFolders(unselectedFolders);
Expand Down Expand Up @@ -190,7 +189,7 @@ const MoveItemsDialog = (props: MoveItemsDialogProps): JSX.Element => {
{/* Create folder dialog */}
<CreateFolderDialog
currentFolderId={currentFolderId}
onFolderCreated={() => setTimeout(() => onShowFolderContentClicked(currentFolderId, currentFolderName), 500)}
onFolderCreated={() => onShowFolderContentClicked(currentFolderId, currentFolderName)}
/>

{/* Folder list */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ export const fetchDialogContentThunk = createAsyncThunk<void, number, { state: R
items: databaseContent,
}),
);
} else {
await responsePromise;
}

responsePromise.then((response) => {
await responsePromise.then(async (response) => {
const folders = response.children.map((folder) => ({ ...folder, isFolder: true }));
const items = _.concat(folders as DriveItemData[], response.files as DriveItemData[]);
dispatch(
Expand All @@ -40,13 +38,17 @@ export const fetchDialogContentThunk = createAsyncThunk<void, number, { state: R
items,
}),
);
databaseService.put(DatabaseCollection.MoveDialogLevels, folderId, items);
await databaseService.delete(DatabaseCollection.MoveDialogLevels, folderId);
await databaseService.put(DatabaseCollection.MoveDialogLevels, folderId, items);
});
},
);

export const fetchDialogContentThunkExtraReducers = (builder: ActionReducerMapBuilder<StorageState>): void => {
builder.addCase(fetchDialogContentThunk.rejected, (state, action) => {
notificationsService.show({ text: t('error.fetchingFolderContent'), type: ToastType.Error });
});
builder
.addCase(fetchDialogContentThunk.pending, () => undefined)
.addCase(fetchDialogContentThunk.fulfilled, () => undefined)
.addCase(fetchDialogContentThunk.rejected, (state, action) => {
notificationsService.show({ text: t('error.fetchingFolderContent'), type: ToastType.Error });
});
};

0 comments on commit 625b121

Please sign in to comment.