Skip to content

Commit 17e2df7

Browse files
committed
Notes: Delete permanently when the trash is disabled
1 parent dbabf58 commit 17e2df7

2 files changed

Lines changed: 19 additions & 11 deletions

File tree

‎packages/editor/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
- Notes: Keep floating threads aligned with their blocks when an editor notice or the device preview moves the canvas ([#83485](https://github.com/WordPress/gutenberg/pull/83485)).
2121
- Notes: Add an Undo action to the "Note deleted." snackbar, and stop the editor's undo from bringing back the highlight of a deleted note ([#83988](https://github.com/WordPress/gutenberg/pull/83988)).
2222
- Notes: Stop the editor's undo from detaching a newly added note from its block, or bringing back the highlight of a resolved note ([#84079](https://github.com/WordPress/gutenberg/pull/84079)).
23+
- Notes: Delete notes permanently when they can't be moved to the trash, instead of failing with an error.
2324

2425
### Internal
2526

‎packages/editor/src/components/collab-sidebar/hooks.js‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -444,11 +444,16 @@ export function useNoteActions() {
444444
// wrong block.
445445
const clientId = ! note.parent ? note.blockClientId : null;
446446

447-
// Without `force`, this moves the note to the trash, so the
448-
// snackbar's Undo can bring it back.
449-
await deleteEntityRecord( 'root', 'comment', note.id, undefined, {
450-
throwOnError: true,
451-
} );
447+
// Without the trash, the note can only be deleted permanently,
448+
// and there's nothing for Undo to bring back.
449+
const canMoveToTrash = !! note._links?.[ 'wp:action-trash' ];
450+
await deleteEntityRecord(
451+
'root',
452+
'comment',
453+
note.id,
454+
canMoveToTrash ? undefined : { force: true },
455+
{ throwOnError: true }
456+
);
452457

453458
// What Undo needs to re-attach the note to its block.
454459
let anchor = null;
@@ -483,12 +488,14 @@ export function useNoteActions() {
483488
createNotice( 'snackbar', __( 'Note deleted.' ), {
484489
type: 'snackbar',
485490
isDismissible: true,
486-
actions: [
487-
{
488-
label: __( 'Undo' ),
489-
onClick: () => restoreNote( note.id, anchor ),
490-
},
491-
],
491+
actions: canMoveToTrash
492+
? [
493+
{
494+
label: __( 'Undo' ),
495+
onClick: () => restoreNote( note.id, anchor ),
496+
},
497+
]
498+
: [],
492499
} );
493500

494501
return true;

0 commit comments

Comments
 (0)