Skip to content

Commit e11ef6a

Browse files
Add loading-state overlay when deleting samples (#1054)
1 parent b933fdb commit e11ef6a

File tree

1 file changed

+48
-9
lines changed

1 file changed

+48
-9
lines changed

webapp/src/components/DynamicDataTableButtons.vue

+48-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
<template>
22
<div v-if="showButtons" class="button-group d-flex justify-content-between align-items-center">
3+
<div
4+
v-if="isDeletingItems"
5+
class="position-fixed d-flex justify-content-center align-items-center"
6+
style="background-color: rgba(255, 255, 255, 0.7); z-index: 1050; inset: 0"
7+
>
8+
<div class="card p-3 shadow-sm">
9+
<div class="text-center">
10+
<font-awesome-icon
11+
:icon="['fa', 'sync']"
12+
class="fa-2x text-primary mb-2"
13+
:spin="true"
14+
aria-label="loading"
15+
/>
16+
<p class="mb-0 mt-1">Deleting {{ itemCount }} items...</p>
17+
</div>
18+
</div>
19+
</div>
320
<div class="button-left">
421
<button
522
v-if="dataType === 'samples'"
@@ -157,11 +174,16 @@ export default {
157174
"open-add-to-collection-modal",
158175
"delete-selected-items",
159176
"update:filters",
177+
"deletion-started",
178+
"deletion-completed",
179+
"deletion-error",
160180
],
161181
data() {
162182
return {
163183
localFilters: { ...this.filters },
164184
isSelectedDropdownVisible: false,
185+
isDeletingItems: false,
186+
itemCount: 0,
165187
};
166188
},
167189
watch: {
@@ -187,15 +209,32 @@ export default {
187209
}
188210
this.isSelectedDropdownVisible = false;
189211
},
190-
deleteItems(ids) {
191-
if (this.dataType === "samples") {
192-
ids.forEach((id) => deleteSample(id));
193-
} else if (this.dataType === "collections") {
194-
ids.forEach((id) => deleteCollection(id, { collection_id: id }));
195-
} else if (this.dataType === "startingMaterials") {
196-
ids.forEach((id) => deleteStartingMaterial(id));
197-
} else if (this.dataType === "equipment") {
198-
ids.forEach((id) => deleteEquipment(id));
212+
async deleteItems(ids) {
213+
try {
214+
this.itemCount = ids.length;
215+
this.isDeletingItems = true;
216+
this.$emit("deletion-started");
217+
218+
let deletePromises = [];
219+
220+
if (this.dataType === "samples") {
221+
deletePromises = ids.map((id) => deleteSample(id));
222+
} else if (this.dataType === "collections") {
223+
deletePromises = ids.map((id) => deleteCollection(id, { collection_id: id }));
224+
} else if (this.dataType === "startingMaterials") {
225+
deletePromises = ids.map((id) => deleteStartingMaterial(id));
226+
} else if (this.dataType === "equipment") {
227+
deletePromises = ids.map((id) => deleteEquipment(id));
228+
}
229+
230+
await Promise.all(deletePromises);
231+
232+
this.$emit("deletion-completed");
233+
} catch (error) {
234+
console.error("Error during batch deletion:", error);
235+
this.$emit("deletion-error", error);
236+
} finally {
237+
this.isDeletingItems = false;
199238
}
200239
},
201240
handleAddToCollection() {

0 commit comments

Comments
 (0)