Skip to content

Commit 67beee8

Browse files
authored
fix(compass-crud): don't show negative count on delete when no document count COMPASS-5996 (#3961)
1 parent 304357e commit 67beee8

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ describe('store', function () {
456456
},
457457
actions: actions,
458458
namespace: 'compass-crud.test',
459+
noRefreshOnConfigure: true,
459460
});
460461
});
461462

@@ -505,6 +506,29 @@ describe('store', function () {
505506
});
506507
});
507508

509+
context('when the count is null', function () {
510+
const doc = { _id: null, name: 'Depeche Mode' };
511+
const hadronDoc = new HadronDocument(doc);
512+
513+
beforeEach(function () {
514+
store.state.docs = [hadronDoc];
515+
store.state.count = null;
516+
store.state.end = 1;
517+
});
518+
519+
it('keeps the count as null after the delete', async function () {
520+
const listener = waitForState(store, (state) => {
521+
expect(state.docs.length).to.equal(0);
522+
expect(state.count).to.equal(null);
523+
expect(state.end).to.equal(0);
524+
});
525+
526+
store.removeDocument(hadronDoc);
527+
528+
await listener;
529+
});
530+
});
531+
508532
context('when the deletion errors', function () {
509533
const doc = { _id: 'testing', name: 'Depeche Mode' };
510534
const hadronDoc = new HadronDocument(doc);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ class CrudStoreImpl
540540
const index = this.findDocumentIndex(doc);
541541
this.state.docs?.splice(index, 1);
542542
this.setState({
543-
count: (this.state.count ?? 1) - 1,
543+
count: this.state.count === null ? null : this.state.count - 1,
544544
end: Math.max(this.state.end - 1, 0),
545545
});
546546
}

0 commit comments

Comments
 (0)