1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-10-31 00:07:48 +02:00

Mobile: Resolves #10763: Support permanent note deletion on mobile (#10786)

This commit is contained in:
Henry Heino
2024-09-21 05:05:27 -07:00
committed by GitHub
parent 050a896c8b
commit 220f867814
9 changed files with 88 additions and 65 deletions

View File

@@ -23,6 +23,7 @@ import ItemChange from '@joplin/lib/models/ItemChange';
import { getDisplayParentId } from '@joplin/lib/services/trash';
import { itemIsReadOnlySync, ItemSlice } from '@joplin/lib/models/utils/readOnly';
import { LayoutChangeEvent } from 'react-native';
import shim from '@joplin/lib/shim';
interface WrapperProps {
}
@@ -140,6 +141,24 @@ describe('Note', () => {
});
});
it('pressing "delete permanently" should permanently delete a note', async () => {
const noteId = await openNewNote({ title: 'To be deleted', body: '...', deleted_time: Date.now() });
render(<WrappedNoteScreen />);
// Permanently delete note shows a confirmation dialog -- mock it.
const deleteId = 0;
shim.showMessageBox = jest.fn(async () => deleteId);
await openNoteActionsMenu();
const deleteButton = await screen.findByText('Permanently delete note');
fireEvent.press(deleteButton);
await waitFor(async () => {
expect(await Note.load(noteId)).toBeUndefined();
});
expect(shim.showMessageBox).toHaveBeenCalled();
});
it('delete should be disabled in a read-only note', async () => {
const shareId = 'testShare';
const noteId = await openNewNote({

View File

@@ -627,21 +627,6 @@ class NoteScreenComponent extends BaseScreenComponent<Props, State> implements B
await shared.saveOneProperty(this, name, value);
}
private async deleteNote_onPress() {
const note = this.state.note;
if (!note.id) return;
const folderId = note.parent_id;
await Note.delete(note.id, { toTrash: true, sourceDescription: 'Delete note button' });
this.props.dispatch({
type: 'NAV_GO',
routeName: 'Notes',
folderId: folderId,
});
}
private async pickDocuments() {
const result = await pickDocument({ multiple: true });
return result;
@@ -1283,30 +1268,33 @@ class NoteScreenComponent extends BaseScreenComponent<Props, State> implements B
});
}
output.push({
title: _('Delete'),
onPress: () => {
void this.deleteNote_onPress();
},
disabled: readOnly,
});
const commandService = CommandService.instance();
const whenContext = commandService.currentWhenClauseContext();
const addButtonFromCommand = (commandName: string, title?: string) => {
if (commandName === '-') {
output.push({ isDivider: true });
} else {
output.push({
title: title ?? commandService.description(commandName),
onPress: async () => {
void commandService.execute(commandName);
},
disabled: !commandService.isEnabled(commandName, whenContext),
});
}
};
if (whenContext.inTrash) {
addButtonFromCommand('permanentlyDeleteNote');
} else {
addButtonFromCommand('deleteNote', _('Delete'));
}
if (pluginCommands.length) {
output.push({ isDivider: true });
const commandService = CommandService.instance();
for (const commandName of pluginCommands) {
if (commandName === '-') {
output.push({ isDivider: true });
} else {
output.push({
title: commandService.description(commandName),
onPress: async () => {
void commandService.execute(commandName);
},
disabled: !commandService.isEnabled(commandName),
});
}
addButtonFromCommand(commandName);
}
}