Skip to content

Commit e983257

Browse files
authored
fix(crud): emit documents-deleted event during bulk delete (deleteMany) COMPASS-10102 (#7620)
1 parent 305f949 commit e983257

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

packages/compass-app-stores/src/stores/instance-store.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ export function createInstancesStore(
554554
);
555555

556556
on(globalAppRegistry, 'document-deleted', refreshNamespaceStats);
557+
on(globalAppRegistry, 'documents-deleted', refreshNamespaceStats);
557558
on(globalAppRegistry, 'document-inserted', refreshNamespaceStats);
558559
on(globalAppRegistry, 'import-finished', refreshNamespaceStats);
559560

packages/compass-crud/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ application can be listened to via [compass-app-registry][compass-app-registry].
101101
`insertMany` and `insertOne` complete.
102102
- **'document-updated'**: indicates a document was updated.
103103
- **'document-deleted'**: indicates a document was deleted.
104+
- **'documents-deleted'**: indicates multiple documents were deleted.
104105

105106
#### Local
106107

@@ -110,6 +111,7 @@ application can be listened to via [compass-app-registry][compass-app-registry].
110111
`insertMany` and `insertOne` complete.
111112
- **'document-updated'**: indicates a document was updated.
112113
- **'document-deleted'**: indicates a document was deleted.
114+
- **'documents-deleted'**: indicates multiple documents were deleted.
113115

114116
### App Registry Events Received
115117

@@ -135,6 +137,7 @@ application can be listened to via [compass-app-registry][compass-app-registry].
135137
- **document-inserted**
136138
- **document-updated**
137139
- **document-deleted**
140+
- **documents-deleted**
138141

139142
## Development
140143

packages/compass-crud/src/stores/crud-store.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export type EmittedAppRegistryEvents =
7878
| 'open-import'
7979
| 'open-export'
8080
| 'document-deleted'
81+
| 'documents-deleted' //Added new type for handling bulk deletion
8182
| 'document-inserted';
8283

8384
export type CrudActions = {
@@ -1977,6 +1978,10 @@ class CrudStoreImpl
19771978
try {
19781979
await this.dataService.deleteMany(this.state.ns, filter);
19791980
this.bulkDeleteSuccess();
1981+
// Emit both events so all listeners update (fixes bulk delete document count not updating)
1982+
const payload = { view: this.state.view, ns: this.state.ns };
1983+
this.localAppRegistry.emit('documents-deleted', payload);
1984+
this.connectionScopedAppRegistry.emit('documents-deleted', payload);
19801985
} catch (ex) {
19811986
this.bulkDeleteFailed(ex as Error);
19821987
}

0 commit comments

Comments
 (0)