From 5c8be448ab4e8e851fc26b0bb8d7a31397b189c5 Mon Sep 17 00:00:00 2001 From: pedr Date: Fri, 2 Aug 2024 13:44:30 -0300 Subject: [PATCH] Desktop: Fixes #10668: Tags and Delete note not being available on Search and on All Notes list (#10729) --- .eslintignore | 1 + .gitignore | 1 + .../commands/stateToWhenClauseContext.test.ts | 74 +++++++++++++++++++ .../commands/stateToWhenClauseContext.ts | 4 +- 4 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 packages/lib/services/commands/stateToWhenClauseContext.test.ts diff --git a/.eslintignore b/.eslintignore index c374d6487..ded57319f 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1050,6 +1050,7 @@ packages/lib/services/commands/commandsToMarkdownTable.js packages/lib/services/commands/focusEditorIfEditorCommand.js packages/lib/services/commands/isEditorCommand.js packages/lib/services/commands/propsHaveChanged.js +packages/lib/services/commands/stateToWhenClauseContext.test.js packages/lib/services/commands/stateToWhenClauseContext.js packages/lib/services/contextkey/contextkey.js packages/lib/services/database/addMigrationFile.js diff --git a/.gitignore b/.gitignore index 2b88524bf..eb7c81679 100644 --- a/.gitignore +++ b/.gitignore @@ -1028,6 +1028,7 @@ packages/lib/services/commands/commandsToMarkdownTable.js packages/lib/services/commands/focusEditorIfEditorCommand.js packages/lib/services/commands/isEditorCommand.js packages/lib/services/commands/propsHaveChanged.js +packages/lib/services/commands/stateToWhenClauseContext.test.js packages/lib/services/commands/stateToWhenClauseContext.js packages/lib/services/contextkey/contextkey.js packages/lib/services/database/addMigrationFile.js diff --git a/packages/lib/services/commands/stateToWhenClauseContext.test.ts b/packages/lib/services/commands/stateToWhenClauseContext.test.ts new file mode 100644 index 000000000..2c0dc9922 --- /dev/null +++ b/packages/lib/services/commands/stateToWhenClauseContext.test.ts @@ -0,0 +1,74 @@ +import { State } from '../../reducer'; +import { getTrashFolderId } from '../trash'; +import stateToWhenClauseContext from './stateToWhenClauseContext'; + + +describe('stateToWhenClauseContext', () => { + + it('should be in trash if selected note has been deleted and selected folder is trash', async () => { + const applicationState = { + selectedNoteIds: ['1'], + selectedFolderId: getTrashFolderId(), + notes: [ + { id: '1', deleted_time: 1722567036580 }, + ], + folders: [], + } as State; + const resultingState = stateToWhenClauseContext(applicationState); + + expect(resultingState.inTrash).toBe(true); + }); + + it('should NOT be in trash if selected note has not been deleted', async () => { + const applicationState = { + selectedNoteIds: ['1'], + selectedFolderId: getTrashFolderId(), + notes: [ + { id: '1', deleted_time: 0 }, + ], + folders: [], + } as State; + const resultingState = stateToWhenClauseContext(applicationState); + + expect(resultingState.inTrash).toBe(false); + }); + + it('should NOT be in trash if selected folder is not trash', async () => { + const applicationState = { + selectedNoteIds: ['1'], + selectedFolderId: 'any-other-folder', + notes: [ + { id: '1', deleted_time: 1722567036580 }, + ], + folders: [], + } as State; + const resultingState = stateToWhenClauseContext(applicationState); + + expect(resultingState.inTrash).toBe(false); + }); + + it('should be in trash if command folder is deleted', async () => { + const applicationState = { + notes: [], + folders: [ + { id: '1', deleted_time: 1722567036580, share_id: '', parent_id: '' }, + ], + } as State; + const resultingState = stateToWhenClauseContext(applicationState, { commandFolderId: '1' }); + + expect(resultingState.inTrash).toBe(true); + }); + + it('should NOT be in trash if command folder is not deleted', async () => { + const applicationState = { + notes: [], + folders: [ + { id: '1', deleted_time: 0, share_id: '', parent_id: '' }, + ], + } as State; + const resultingState = stateToWhenClauseContext(applicationState, { commandFolderId: '1' }); + + expect(resultingState.inTrash).toBe(false); + }); + +}); diff --git a/packages/lib/services/commands/stateToWhenClauseContext.ts b/packages/lib/services/commands/stateToWhenClauseContext.ts index 89b4a11bc..18e9f1b35 100644 --- a/packages/lib/services/commands/stateToWhenClauseContext.ts +++ b/packages/lib/services/commands/stateToWhenClauseContext.ts @@ -68,7 +68,7 @@ export default function stateToWhenClauseContext(state: State, options: WhenClau // Current location inConflictFolder: state.selectedFolderId === Folder.conflictFolderId(), - inTrash: state.selectedFolderId === getTrashFolderId() || commandFolder && !!commandFolder.deleted_time, + inTrash: !!((state.selectedFolderId === getTrashFolderId() && !!selectedNote?.deleted_time) || commandFolder && !!commandFolder.deleted_time), // Note selection oneNoteSelected: !!selectedNote, @@ -101,7 +101,7 @@ export default function stateToWhenClauseContext(state: State, options: WhenClau folderIsShared: commandFolder ? !!commandFolder.share_id : false, folderIsDeleted: commandFolder ? !!commandFolder.deleted_time : false, folderIsTrash: commandFolder ? commandFolder.id === getTrashFolderId() : false, - folderIsReadOnly: commandFolder ? itemIsReadOnlySync(ModelType.Note, ItemChange.SOURCE_UNSPECIFIED, commandFolder as ItemSlice, settings['sync.userId'], state.shareService) : false, + folderIsReadOnly: commandFolder ? itemIsReadOnlySync(ModelType.Folder, ItemChange.SOURCE_UNSPECIFIED, commandFolder as ItemSlice, settings['sync.userId'], state.shareService) : false, joplinServerConnected: [9, 10].includes(settings['sync.target']), joplinCloudAccountType: settings['sync.target'] === 10 ? settings['sync.10.accountType'] : 0,