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.
This commit is contained in:
Nariman Jelveh committed 2026-11-23 15:55:49 -07:00
1 parent f199916d18
commit 7e1712f03f
4 files changed
+51 -7

No files matched your search

+12 -1
View File
@@ -2634,7 +2634,17 @@ const TabFiles = {
* @returns {Promise<void>}
*/
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: () => {
+22
View File
@@ -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 () => {});
+14 -5
View File
@@ -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<boolean> }} [options] - asks the user;
* resolves true to go ahead. Defaults to the desktop's UIAlert.
* @returns {Promise<void>}
*/
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();
@@ -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>} 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();
},
});
}