Skip to content

Commit 857b535

Browse files
[6.x] Update bulk action selections when individual row is deleted (#14196)
1 parent c841503 commit 857b535

4 files changed

Lines changed: 19 additions & 1 deletion

File tree

.storybook/preview.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import FullscreenHeader from '@/components/publish/FullscreenHeader.vue';
1414
import Portal from '@/components/portals/Portal.vue';
1515
import PortalTargets from '@/components/portals/PortalTargets.vue';
1616
import {keys, portals, slug, stacks} from '@api';
17+
import useGlobalEventBus from '@/composables/global-event-bus';
1718

1819
// Intercept Inertia navigation and log to Actions tab.
1920
router.on('before', (event) => {
@@ -46,6 +47,7 @@ setup(async (app) => {
4647
//
4748
}
4849
},
50+
$events: useGlobalEventBus(),
4951
$progress: {
5052
loading(name, loading) {
5153
//

resources/js/bootstrap/App.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ export default {
4949
document.body.querySelectorAll(`img[src='${url}']`).forEach((img) => (img.src = url));
5050
});
5151
});
52+
53+
Statamic.$callbacks.add('removeFromSelections', function (ids) {
54+
Statamic.$events.$emit('removeFromSelections', ids);
55+
});
5256
},
5357
5458
methods: {

resources/js/components/ui/Listing/Listing.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ watch(
237237
}
238238
);
239239
240+
const removeFromSelections = (ids) => selections.value = selections.value.filter(selection => !ids.includes(selection));
241+
Statamic.$events.$on('removeFromSelections', removeFromSelections);
242+
onBeforeUnmount(() => Statamic.$events.$off('removeFromSelections', removeFromSelections));
243+
240244
const rawParameters = computed(() => ({
241245
page: currentPage.value,
242246
perPage: perPage.value,

src/Actions/Delete.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,15 @@ public function run($items, $values)
8686
}
8787
}
8888

89-
return trans_choice('Item deleted|Items deleted', $total);
89+
$ids = $items
90+
->map(fn ($item) => method_exists($item, 'id') ? $item->id() : null)
91+
->filter()
92+
->values();
93+
94+
return [
95+
'message' => trans_choice('Item deleted|Items deleted', $total),
96+
'callback' => $ids->isNotEmpty() ? ['removeFromSelections', $ids] : null,
97+
];
9098
}
9199

92100
public function redirect($items, $values)

0 commit comments

Comments
 (0)