You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-07-16 00:14:34 +02:00
This commit is contained in:
@ -1122,7 +1122,6 @@ packages/lib/services/trash/getTrashFolderId.js
|
|||||||
packages/lib/services/trash/index.test.js
|
packages/lib/services/trash/index.test.js
|
||||||
packages/lib/services/trash/index.js
|
packages/lib/services/trash/index.js
|
||||||
packages/lib/services/trash/isTrashableItem.js
|
packages/lib/services/trash/isTrashableItem.js
|
||||||
packages/lib/services/trash/isTrashableNoteOrFolder.js
|
|
||||||
packages/lib/services/trash/permanentlyDeleteOldItems.test.js
|
packages/lib/services/trash/permanentlyDeleteOldItems.test.js
|
||||||
packages/lib/services/trash/permanentlyDeleteOldItems.js
|
packages/lib/services/trash/permanentlyDeleteOldItems.js
|
||||||
packages/lib/services/trash/restoreItems.test.js
|
packages/lib/services/trash/restoreItems.test.js
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -1102,7 +1102,6 @@ packages/lib/services/trash/getTrashFolderId.js
|
|||||||
packages/lib/services/trash/index.test.js
|
packages/lib/services/trash/index.test.js
|
||||||
packages/lib/services/trash/index.js
|
packages/lib/services/trash/index.js
|
||||||
packages/lib/services/trash/isTrashableItem.js
|
packages/lib/services/trash/isTrashableItem.js
|
||||||
packages/lib/services/trash/isTrashableNoteOrFolder.js
|
|
||||||
packages/lib/services/trash/permanentlyDeleteOldItems.test.js
|
packages/lib/services/trash/permanentlyDeleteOldItems.test.js
|
||||||
packages/lib/services/trash/permanentlyDeleteOldItems.js
|
packages/lib/services/trash/permanentlyDeleteOldItems.js
|
||||||
packages/lib/services/trash/restoreItems.test.js
|
packages/lib/services/trash/restoreItems.test.js
|
||||||
|
@ -181,6 +181,7 @@ export default class Folder extends BaseItem {
|
|||||||
user_updated_time: now,
|
user_updated_time: now,
|
||||||
share_id: '',
|
share_id: '',
|
||||||
is_shared: 0,
|
is_shared: 0,
|
||||||
|
deleted_time: 0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { getDisplayParentId, getTrashFolderId } from '.';
|
import { getDisplayParentId, getTrashFolderId } from '.';
|
||||||
import { ModelType } from '../../BaseModel';
|
import { ModelType } from '../../BaseModel';
|
||||||
|
import Folder from '../../models/Folder';
|
||||||
|
|
||||||
describe('services/trash', () => {
|
describe('services/trash', () => {
|
||||||
|
|
||||||
@ -40,10 +41,32 @@ describe('services/trash', () => {
|
|||||||
},
|
},
|
||||||
'1',
|
'1',
|
||||||
],
|
],
|
||||||
|
|
||||||
|
// should show non-deleted conflicts in the conflicts folder
|
||||||
|
[
|
||||||
|
{
|
||||||
|
deleted_time: 0,
|
||||||
|
is_conflict: 1,
|
||||||
|
parent_id: Folder.conflictFolderId(),
|
||||||
|
id: 'b',
|
||||||
|
},
|
||||||
|
Folder.conflictFolder(),
|
||||||
|
Folder.conflictFolderId(),
|
||||||
|
],
|
||||||
|
// should show deleted conflicts in the trash folder
|
||||||
|
[
|
||||||
|
{
|
||||||
|
deleted_time: 1000,
|
||||||
|
is_conflict: 1,
|
||||||
|
parent_id: Folder.conflictFolderId(),
|
||||||
|
id: 'someidhere',
|
||||||
|
},
|
||||||
|
Folder.conflictFolder(),
|
||||||
|
getTrashFolderId(),
|
||||||
|
],
|
||||||
])('should return the display parent ID (case %#)', (item, itemParent, expected) => {
|
])('should return the display parent ID (case %#)', (item, itemParent, expected) => {
|
||||||
const defaultProps = { type_: ModelType.Folder };
|
const defaultProps = { type_: ModelType.Folder };
|
||||||
const actual = getDisplayParentId({ ...defaultProps, ...item }, { ...defaultProps, ...itemParent });
|
const actual = getDisplayParentId({ ...defaultProps, ...item }, { ...defaultProps, ...itemParent });
|
||||||
expect(actual).toBe(expected);
|
expect(actual).toBe(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -4,7 +4,6 @@ import { _ } from '../../locale';
|
|||||||
import { FolderEntity, FolderIcon, FolderIconType, NoteEntity } from '../database/types';
|
import { FolderEntity, FolderIcon, FolderIconType, NoteEntity } from '../database/types';
|
||||||
import Folder from '../../models/Folder';
|
import Folder from '../../models/Folder';
|
||||||
import getTrashFolderId from './getTrashFolderId';
|
import getTrashFolderId from './getTrashFolderId';
|
||||||
import isTrashableNoteOrFolder from './isTrashableNoteOrFolder';
|
|
||||||
|
|
||||||
// When an item is deleted, all its properties are kept, including the parent ID
|
// 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
|
// so that it can potentially be restored to the right folder. However, when
|
||||||
@ -20,14 +19,11 @@ import isTrashableNoteOrFolder from './isTrashableNoteOrFolder';
|
|||||||
// folder with ID = item.parent_id
|
// folder with ID = item.parent_id
|
||||||
export const getDisplayParentId = (item: FolderEntity | NoteEntity, originalItemParent: FolderEntity) => {
|
export const getDisplayParentId = (item: FolderEntity | NoteEntity, originalItemParent: FolderEntity) => {
|
||||||
if (!('parent_id' in item)) throw new Error(`Missing "parent_id" property: ${JSON.stringify(item)}`);
|
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)) {
|
if (!('deleted_time' in item)) {
|
||||||
throw new Error(`Missing "deleted_time" property: ${JSON.stringify(item)}`);
|
throw new Error(`Missing "deleted_time" property: ${JSON.stringify(item)}`);
|
||||||
}
|
}
|
||||||
if (originalItemParent && isTrashableNoteOrFolder(originalItemParent) && !('deleted_time' in originalItemParent)) {
|
if (originalItemParent && !('deleted_time' in originalItemParent)) {
|
||||||
throw new Error(`Missing "deleted_time" property: ${JSON.stringify(originalItemParent)}`);
|
throw new Error(`Missing "deleted_time" property: ${JSON.stringify(originalItemParent)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,10 +80,7 @@ export const getTrashFolderIcon = (type: FolderIconType): FolderIcon => {
|
|||||||
|
|
||||||
export const itemIsInTrash = (item: FolderEntity | NoteEntity) => {
|
export const itemIsInTrash = (item: FolderEntity | NoteEntity) => {
|
||||||
if (!item) return false;
|
if (!item) return false;
|
||||||
if (!isTrashableNoteOrFolder(item)) return false;
|
|
||||||
|
|
||||||
checkObjectHasProperties(item, ['id', 'deleted_time']);
|
checkObjectHasProperties(item, ['id', 'deleted_time']);
|
||||||
|
|
||||||
return item.id === getTrashFolderId() || !!item.deleted_time;
|
return item.id === getTrashFolderId() || !!item.deleted_time;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { checkObjectHasProperties } from '@joplin/utils/object';
|
import { checkObjectHasProperties } from '@joplin/utils/object';
|
||||||
import { ModelType } from '../../BaseModel';
|
import { ModelType } from '../../BaseModel';
|
||||||
import isTrashableNoteOrFolder from './isTrashableNoteOrFolder';
|
import conflictFolderId from '../../models/utils/getConflictFolderId';
|
||||||
|
import getTrashFolderId from './getTrashFolderId';
|
||||||
|
|
||||||
type ItemSlice = { id?: string };
|
type ItemSlice = { id?: string };
|
||||||
const isTrashableItem = (itemType: ModelType, item: ItemSlice) => {
|
const isTrashableItem = (itemType: ModelType, item: ItemSlice) => {
|
||||||
@ -10,7 +11,7 @@ const isTrashableItem = (itemType: ModelType, item: ItemSlice) => {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return isTrashableNoteOrFolder(item);
|
return item.id !== conflictFolderId() && item.id !== getTrashFolderId();
|
||||||
};
|
};
|
||||||
|
|
||||||
export default isTrashableItem;
|
export default isTrashableItem;
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
import { checkObjectHasProperties } from '@joplin/utils/object';
|
|
||||||
import conflictFolderId from '../../models/utils/getConflictFolderId';
|
|
||||||
import getTrashFolderId from './getTrashFolderId';
|
|
||||||
|
|
||||||
type ItemSlice = { id?: string };
|
|
||||||
|
|
||||||
// This function is separate from isTrashableItem to handle the case where we know that an item
|
|
||||||
// is either a note or a folder, but don't know which.
|
|
||||||
const isTrashableNoteOrFolder = (item: ItemSlice) => {
|
|
||||||
checkObjectHasProperties(item, ['id']);
|
|
||||||
return item.id !== conflictFolderId() && item.id !== getTrashFolderId();
|
|
||||||
};
|
|
||||||
|
|
||||||
export default isTrashableNoteOrFolder;
|
|
Reference in New Issue
Block a user