Skip to content

Commit 0747439

Browse files
use confirm dialog in history selection operations
1 parent d35b3fb commit 0747439

2 files changed

Lines changed: 49 additions & 56 deletions

File tree

client/src/components/History/CurrentHistory/HistoryOperations/SelectionOperations.test.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@ import { setupMockConfig } from "@tests/vitest/mockConfig";
33
import { shallowMount } from "@vue/test-utils";
44
import flushPromises from "flush-promises";
55
import { createPinia } from "pinia";
6-
import { beforeEach, describe, expect, it } from "vitest";
6+
import { beforeEach, describe, expect, it, vi } from "vitest";
77

88
import { useServerMock } from "@/api/client/__mocks__";
99

1010
import SelectionOperations from "./SelectionOperations.vue";
1111

12+
vi.mock("@/composables/confirmDialog", () => ({
13+
useConfirmDialog: () => ({
14+
confirm: vi.fn().mockResolvedValue(true),
15+
}),
16+
}));
17+
1218
const localVue = getLocalVue();
1319

1420
const { server, http } = useServerMock();
@@ -145,7 +151,7 @@ describe("History Selection Operations", () => {
145151
expect(wrapper.find(option).exists()).toBe(false);
146152
});
147153

148-
it("should display 'permanently delete' option always", async () => {
154+
it("should display 'permanently delete' option unless all selected items are purged", async () => {
149155
const option = getMenuSelectorFor("purge");
150156
expect(wrapper.find(option).exists()).toBe(true);
151157
await wrapper.setProps({ filterText: "deleted:any visible:any" });

client/src/components/History/CurrentHistory/HistoryOperations/SelectionOperations.vue

Lines changed: 41 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,19 @@
1414
>{{ localize("With") }} {{ numSelected }} {{ localize("selected...") }}</span
1515
>
1616
</b-dropdown-text>
17-
<b-dropdown-item v-if="canUnhideSelection" v-b-modal:show-selected-content data-description="unhide option">
17+
<b-dropdown-item v-if="canUnhideSelection" data-description="unhide option" @click="unhideSelected">
1818
<span v-localize>Unhide</span>
1919
</b-dropdown-item>
20-
<b-dropdown-item v-if="canHideSelection" v-b-modal:hide-selected-content data-description="hide option">
20+
<b-dropdown-item v-if="canHideSelection" data-description="hide option" @click="hideSelected">
2121
<span v-localize>Hide</span>
2222
</b-dropdown-item>
23-
<b-dropdown-item
24-
v-if="canUndeleteSelection"
25-
v-b-modal:restore-selected-content
26-
data-description="undelete option">
23+
<b-dropdown-item v-if="canUndeleteSelection" data-description="undelete option" @click="undeleteSelected">
2724
<span v-localize>Undelete</span>
2825
</b-dropdown-item>
29-
<b-dropdown-item
30-
v-if="canDeleteSelection"
31-
v-b-modal:delete-selected-content
32-
data-description="delete option">
26+
<b-dropdown-item v-if="canDeleteSelection" data-description="delete option" @click="deleteSelected">
3327
<span v-localize>Delete</span>
3428
</b-dropdown-item>
35-
<b-dropdown-item v-b-modal:purge-selected-content data-description="purge option">
29+
<b-dropdown-item v-if="canPurgeSelection" data-description="purge option" @click="purgeSelected">
3630
<span v-localize>Delete (permanently)</span>
3731
</b-dropdown-item>
3832
<b-dropdown-divider v-if="showBuildOptions" />
@@ -68,42 +62,6 @@
6862
</b-dropdown-item>
6963
</b-dropdown>
7064

71-
<b-modal
72-
id="hide-selected-content"
73-
:title="localize('Hide Selected Content?')"
74-
title-tag="h2"
75-
@ok="hideSelected">
76-
<p v-localize>Really hide {{ numSelected }} content items?</p>
77-
</b-modal>
78-
<b-modal
79-
id="show-selected-content"
80-
:title="localize('Show Selected Content?')"
81-
title-tag="h2"
82-
@ok="unhideSelected">
83-
<p v-localize>Really show {{ numSelected }} content items?</p>
84-
</b-modal>
85-
<b-modal
86-
id="delete-selected-content"
87-
:title="localize('Delete Selected Content?')"
88-
title-tag="h2"
89-
@ok="deleteSelected">
90-
<p v-localize>Really delete {{ numSelected }} content items?</p>
91-
</b-modal>
92-
<b-modal
93-
id="restore-selected-content"
94-
:title="localize('Restore Selected Content?')"
95-
title-tag="h2"
96-
@ok="undeleteSelected">
97-
<p v-localize>Really restore {{ numSelected }} content items?</p>
98-
</b-modal>
99-
<b-modal
100-
id="purge-selected-content"
101-
:title="localize('Purge Selected Content?')"
102-
title-tag="h2"
103-
@ok="purgeSelected">
104-
<p v-localize>Permanently delete {{ numSelected }} content items?</p>
105-
<p><strong v-localize class="text-danger">Warning, this operation cannot be undone.</strong></p>
106-
</b-modal>
10765
<b-modal
10866
id="change-dbkey-of-selected-content"
10967
title="Change Database/Build?"
@@ -185,6 +143,7 @@ import {
185143
import { DatatypesProvider, DbKeyProvider } from "@/components/providers";
186144
import { StatelessTags } from "@/components/Tags";
187145
import { useConfig } from "@/composables/config";
146+
import { useConfirmDialog } from "@/composables/confirmDialog";
188147
import { useCollectionBuilderItemSelection } from "@/stores/collectionBuilderItemsStore";
189148
190149
import CollectionCreatorIndex from "@/components/Collections/CollectionCreatorIndex.vue";
@@ -209,7 +168,9 @@ export default {
209168
},
210169
setup() {
211170
const { config, isConfigLoaded } = useConfig(true);
212-
return { config, isConfigLoaded };
171+
const { confirm } = useConfirmDialog();
172+
173+
return { config, confirm, isConfigLoaded };
213174
},
214175
data: function () {
215176
return {
@@ -239,6 +200,10 @@ export default {
239200
return this.areAllSelectedActive || (this.isAnyDeletedStateAllowed && !this.areAllSelectedDeleted);
240201
},
241202
/** @returns {Boolean} */
203+
canPurgeSelection() {
204+
return this.contentSelection.size === 0 || this.isQuerySelection || !this.areAllSelectedPurged;
205+
},
206+
/** @returns {Boolean} */
242207
canUndeleteSelection() {
243208
return this.showDeleted && (this.isQuerySelection || !this.areAllSelectedPurged);
244209
},
@@ -333,21 +298,43 @@ export default {
333298
this.$router.push(`/collection/new_list?advanced=${advanced}`);
334299
}
335300
},
336-
// Selected content manipulation, hide/show/delete/purge
301+
// Selected content manipulation, hide/show/delete/purge (using the confirm dialog)
302+
async confirmAndRun(operation, message, options = {}) {
303+
if (await this.confirm(message, options)) {
304+
this.runOnSelection(operation);
305+
}
306+
},
337307
hideSelected() {
338-
this.runOnSelection(hideSelectedContent);
308+
return this.confirmAndRun(hideSelectedContent, `Really hide ${this.numSelected} content items?`, {
309+
title: "Hide Selected Content?",
310+
okText: "Hide",
311+
});
339312
},
340313
unhideSelected() {
341-
this.runOnSelection(unhideSelectedContent);
314+
return this.confirmAndRun(unhideSelectedContent, `Really show ${this.numSelected} content items?`, {
315+
title: "Show Selected Content?",
316+
okText: "Show",
317+
});
342318
},
343319
deleteSelected() {
344-
this.runOnSelection(deleteSelectedContent);
320+
return this.confirmAndRun(deleteSelectedContent, `Really delete ${this.numSelected} content items?`, {
321+
title: "Delete Selected Content?",
322+
okText: "Delete",
323+
okColor: "red",
324+
});
345325
},
346326
undeleteSelected() {
347-
this.runOnSelection(undeleteSelectedContent);
327+
return this.confirmAndRun(undeleteSelectedContent, `Really restore ${this.numSelected} content items?`, {
328+
title: "Restore Selected Content?",
329+
okText: "Restore",
330+
});
348331
},
349332
purgeSelected() {
350-
this.runOnSelection(purgeSelectedContent);
333+
return this.confirmAndRun(purgeSelectedContent, `Really purge ${this.numSelected} content items?`, {
334+
title: "Purge Selected Content?",
335+
okText: "Purge",
336+
okColor: "red",
337+
});
351338
},
352339
changeDbkeyOfSelected() {
353340
this.runOnSelection(changeDbkeyOfSelectedContent, { dbkey: this.selectedDbKey.id });

0 commit comments

Comments
 (0)