Skip to content

Commit

Permalink
Desktop: Fixes laurent22#10668: Tags and Delete note not being availa…
Browse files Browse the repository at this point in the history
…ble on Search and on All Notes list (laurent22#10729)
  • Loading branch information
pedr authored Aug 2, 2024
1 parent f69dffc commit 5c8be44
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 2 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
74 changes: 74 additions & 0 deletions packages/lib/services/commands/stateToWhenClauseContext.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});

});
4 changes: 2 additions & 2 deletions packages/lib/services/commands/stateToWhenClauseContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 5c8be44

Please sign in to comment.