1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Desktop: Fixes #10067: Fix dragging notebooks to the toplevel notebook (#10302)

This commit is contained in:
Henry Heino 2024-04-15 10:15:45 -07:00 committed by GitHub
parent 313587097a
commit 385fe7bbe0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 1 deletions

View File

@ -70,4 +70,25 @@ describe('onFolderDrop', () => {
expect(n1.parent_id).toBe(folder2.id);
});
it('should drop a non-deleted folder to the virtual root notebook', async () => {
const folder1 = await Folder.save({});
const folder2 = await Folder.save({ parent_id: folder1.id });
await onFolderDrop([], [folder2.id], '');
const folder2Reloaded = await Folder.load(folder2.id);
expect(folder2Reloaded.parent_id).toBe(folder1.parent_id);
expect(folder2Reloaded.parent_id).toBe('');
});
it('should drop a deleted folder to the virtual root notebook', async () => {
const folder1 = await Folder.save({});
await Folder.delete(folder1.id, { toTrash: true });
await onFolderDrop([], [folder1.id], '');
const folder1Reloaded = await Folder.load(folder1.id);
expect(folder1Reloaded.parent_id).toBe('');
expect(folder1Reloaded.deleted_time).toBe(0);
});
});

View File

@ -5,8 +5,19 @@ import restoreItems from '../../services/trash/restoreItems';
import Folder from '../Folder';
import Note from '../Note';
const rootFolder = {
id: '',
deleted_time: 0,
type_: ModelType.Folder,
};
export default async (noteIds: string[], folderIds: string[], targetFolderId: string) => {
const targetFolder = await Folder.load(targetFolderId, { fields: ['id', 'deleted_time'] });
let targetFolder: FolderEntity;
if (targetFolderId !== '') {
targetFolder = await Folder.load(targetFolderId, { fields: ['id', 'deleted_time'] });
} else {
targetFolder = rootFolder;
}
if (!targetFolder) throw new Error(`No such folder: ${targetFolderId}`);