Skip to content

Commit 32f6083

Browse files
authored
fix(crud): clone the bulk delete preview docs from the ones in the list COMPASS-7521 (#5232)
* Clone the bulk delete preview docs from the ones in the list * account for the fact that previews have been cloned
1 parent 64d771a commit 32f6083

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,8 +1021,14 @@ describe('store', function () {
10211021

10221022
store.openBulkDeleteDialog();
10231023

1024+
const previews = store.state.bulkDelete.previews;
1025+
1026+
// because we make a copy of the previews what comes out will not be the
1027+
// same as what goes in so just check the previews separately
1028+
expect(previews[0].doc.a).to.deep.equal(new Int32(1));
1029+
10241030
expect(store.state.bulkDelete).to.deep.equal({
1025-
previews: [hadronDoc],
1031+
previews,
10261032
status: 'open',
10271033
affected: 1,
10281034
});
@@ -1036,8 +1042,13 @@ describe('store', function () {
10361042
store.openBulkDeleteDialog();
10371043
store.closeBulkDeleteDialog();
10381044

1045+
const previews = store.state.bulkDelete.previews;
1046+
1047+
// same comment as above
1048+
expect(previews[0].doc.a).to.deep.equal(new Int32(1));
1049+
10391050
expect(store.state.bulkDelete).to.deep.equal({
1040-
previews: [hadronDoc],
1051+
previews,
10411052
status: 'closed',
10421053
affected: 1,
10431054
});

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1859,9 +1859,18 @@ class CrudStoreImpl
18591859

18601860
const PREVIEW_DOCS = 5;
18611861

1862+
const previews = (this.state.docs?.slice(0, PREVIEW_DOCS) || []).map(
1863+
(doc) => {
1864+
// The idea is just to break the link with the docs in the list so that
1865+
// expanding/collapsing docs in the modal doesn't modify the ones in the
1866+
// list.
1867+
return Document.FromEJSON(doc.toEJSON());
1868+
}
1869+
);
1870+
18621871
this.setState({
18631872
bulkDelete: {
1864-
previews: this.state.docs?.slice(0, PREVIEW_DOCS) || [],
1873+
previews,
18651874
status: 'open',
18661875
affected: this.state.count ?? undefined,
18671876
},

0 commit comments

Comments
 (0)