From 7e1712f03f52a910341561a00cb2ab92d075b9da Mon Sep 17 00:00:00 2001 From: Nariman Jelveh Date: Mon, 23 Nov 2026 15:55:49 -0700 Subject: [PATCH] refactor(gui): the dashboard's Empty Trash confirm opens in its own dialog, not a UIAlert window window.empty_trash takes an optional confirm, which the Files tab fills with UIDashboardDialog; the desktop keeps its UIAlert. The file context menu's Empty Trash goes through the Files tab via onEmptyTrash. --- src/gui/src/UI/Dashboard/TabFiles.js | 13 ++++++++++- src/gui/src/UI/Dashboard/TabFiles.test.js | 22 +++++++++++++++++++ src/gui/src/helpers.js | 19 +++++++++++----- .../src/helpers/generateFileContextMenu.js | 4 +++- 4 files changed, 51 insertions(+), 7 deletions(-) diff --git a/src/gui/src/UI/Dashboard/TabFiles.js b/src/gui/src/UI/Dashboard/TabFiles.js index a79c8a5f3..224e6e2d6 100644 --- a/src/gui/src/UI/Dashboard/TabFiles.js +++ b/src/gui/src/UI/Dashboard/TabFiles.js @@ -2634,7 +2634,17 @@ const TabFiles = { * @returns {Promise} */ async emptyTrash () { - await window.empty_trash(); + await window.empty_trash({ + confirm: async () => await UIDashboardDialog({ + message: i18n('empty_trash_confirmation'), + tone: 'danger', + buttons: [ + { label: i18n('cancel', [], false), value: false, type: 'quiet' }, + { label: i18n('empty_trash', [], false), value: true, type: 'danger' }, + ], + $container: this.$el_window, + }) === true, + }); this.syncEmptiedTrash(); }, @@ -5094,6 +5104,7 @@ const TabFiles = { await _this.restoreRows([el]); }, onPasteInto: (destPath) => _this.pasteClipboardInto(destPath), + onEmptyTrash: () => _this.emptyTrash(), // The people filter and its counts, the empty notice and the // footer all come from the listing. onRemovedFromShared: () => { diff --git a/src/gui/src/UI/Dashboard/TabFiles.test.js b/src/gui/src/UI/Dashboard/TabFiles.test.js index f3d537c17..fe61c4eee 100644 --- a/src/gui/src/UI/Dashboard/TabFiles.test.js +++ b/src/gui/src/UI/Dashboard/TabFiles.test.js @@ -97,6 +97,28 @@ describe('TabFiles emptying the Trash', () => { expect(footer()).toContain('0 items'); }); + it('asks in the dashboard\'s own dialog and empties only on confirm', async () => { + mountListing(['a.txt']); + const { default: UIDashboardDialog } = await import('./UIDashboardDialog.js'); + const answers = []; + window.empty_trash = vi.fn(async ({ confirm }) => { + answers.push(await confirm()); + }); + + UIDashboardDialog.mockClear(); + UIDashboardDialog.mockResolvedValueOnce(false); + await TabFiles.emptyTrash(); + UIDashboardDialog.mockResolvedValueOnce(true); + await TabFiles.emptyTrash(); + + expect(UIDashboardDialog).toHaveBeenCalledWith(expect.objectContaining({ + tone: 'danger', + $container: TabFiles.$el_window, + })); + expect(UIDashboardDialog.mock.calls[0][0].message).toMatch(/permanently delete the items in Trash/); + expect(answers).toEqual([false, true]); + }); + it('leaves a Trash the user chose not to empty as it was', async () => { mountListing(['a.txt']); window.empty_trash = vi.fn(async () => {}); diff --git a/src/gui/src/helpers.js b/src/gui/src/helpers.js index 2bf57e11c..68f2a6c4c 100644 --- a/src/gui/src/helpers.js +++ b/src/gui/src/helpers.js @@ -2501,7 +2501,8 @@ window.upload_items = async function (items, dest_path, { onUploaded } = {}) { ); }; -window.empty_trash = async function () { +/** The desktop's confirmation for emptying the Trash. */ +const confirm_empty_trash = async () => { const alert_resp = await UIAlert({ message: i18n('empty_trash_confirmation'), buttons: [ @@ -2516,10 +2517,18 @@ window.empty_trash = async function () { }, ], }); - if ( alert_resp === 'no' ) - { - return; - } + return alert_resp !== 'no'; +}; + +/** + * Empties the Trash once the user confirms. + * + * @param {{ confirm?: () => Promise }} [options] - asks the user; + * resolves true to go ahead. Defaults to the desktop's UIAlert. + * @returns {Promise} + */ +window.empty_trash = async function ({ confirm = confirm_empty_trash } = {}) { + if ( ! await confirm() ) return; // only show progress window if it takes longer than 500ms to create folder let init_ts = Date.now(); diff --git a/src/gui/src/helpers/generateFileContextMenu.js b/src/gui/src/helpers/generateFileContextMenu.js index af368e90f..d92159abd 100644 --- a/src/gui/src/helpers/generateFileContextMenu.js +++ b/src/gui/src/helpers/generateFileContextMenu.js @@ -47,6 +47,7 @@ import build_open_with_items from './openWithItems.js'; * @param {Function} options.onPublishWorker - Publishes the file as a worker; Publish as Worker is left out of the menu without it. Receives {uid, name, path} * @param {Function} options.onPasteInto - Optional custom paste handler (used by Dashboard); receives the folder's path * @param {Function} options.onRemovedFromShared - Optional, called once Remove from Shared has dropped the user's own access (used by Dashboard) + * @param {Function} options.onEmptyTrash - Optional custom Empty Trash handler (used by Dashboard) * @returns {Promise} Array of context menu items */ const generate_file_context_menu = async function (options) { @@ -198,7 +199,8 @@ const generate_file_context_menu = async function (options) { menu_items.push({ html: i18n('empty_trash'), onClick: async function () { - window.empty_trash(); + if ( options.onEmptyTrash ) options.onEmptyTrash(); + else window.empty_trash(); }, }); }