1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-07-16 00:14:34 +02:00

Desktop,Mobile: Resolves #10073, #10080: Fix conflicts notebook doesn't work with the trash feature (#10104)

This commit is contained in:
Henry Heino
2024-03-14 11:30:49 -07:00
committed by GitHub
parent 8eea3953f3
commit c16ce1c434
16 changed files with 193 additions and 15 deletions

View File

@ -3,6 +3,8 @@ import { ModelType } from '../../BaseModel';
import { _ } from '../../locale';
import { FolderEntity, FolderIcon, FolderIconType, NoteEntity } from '../database/types';
import Folder from '../../models/Folder';
import getTrashFolderId from './getTrashFolderId';
import isTrashableNoteOrFolder from './isTrashableNoteOrFolder';
// When an item is deleted, all its properties are kept, including the parent ID
// so that it can potentially be restored to the right folder. However, when
@ -17,8 +19,17 @@ import Folder from '../../models/Folder';
// `originalItemParent` is the parent before the item was deleted, which is the
// folder with ID = item.parent_id
export const getDisplayParentId = (item: FolderEntity | NoteEntity, originalItemParent: FolderEntity) => {
if (!('deleted_time' in item) || !('parent_id' in item)) throw new Error(`Missing "deleted_time" or "parent_id" property: ${JSON.stringify(item)}`);
if (originalItemParent && !('deleted_time' in originalItemParent)) throw new Error(`Missing "deleted_time" property: ${JSON.stringify(originalItemParent)}`);
if (!('parent_id' in item)) throw new Error(`Missing "parent_id" property: ${JSON.stringify(item)}`);
if (!isTrashableNoteOrFolder(item)) {
return item.parent_id;
}
if (!('deleted_time' in item)) {
throw new Error(`Missing "deleted_time" property: ${JSON.stringify(item)}`);
}
if (originalItemParent && isTrashableNoteOrFolder(originalItemParent) && !('deleted_time' in originalItemParent)) {
throw new Error(`Missing "deleted_time" property: ${JSON.stringify(originalItemParent)}`);
}
if (!item.deleted_time) return item.parent_id;
@ -33,10 +44,6 @@ export const getDisplayParentTitle = (item: FolderEntity | NoteEntity, originalI
return originalItemParent && originalItemParent.id === displayParentId ? originalItemParent.title : '';
};
export const getTrashFolderId = () => {
return 'de1e7ede1e7ede1e7ede1e7ede1e7ede';
};
export const getTrashFolderTitle = () => {
return _('Trash');
};
@ -77,6 +84,7 @@ export const getTrashFolderIcon = (type: FolderIconType): FolderIcon => {
export const itemIsInTrash = (item: FolderEntity | NoteEntity) => {
if (!item) return false;
if (!isTrashableNoteOrFolder(item)) return false;
checkObjectHasProperties(item, ['id', 'deleted_time']);
@ -89,3 +97,5 @@ export const getRestoreFolder = async () => {
if (output) return output;
return Folder.save({ title });
};
export { getTrashFolderId };