Skip to content

Commit 64d771a

Browse files
authored
fix(crud): clear the bulk update syntax error when update preview is not supported and parsing succeeds COMPASS-7522 (#5231)
clear the syntax error when update preview is not supported and parsing succeeds
1 parent d8ce60e commit 64d771a

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

package-lock.json

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2787,8 +2787,7 @@ describe('store', function () {
27872787
});
27882788
dataService.previewUpdate = previewUpdateStub;
27892789
instance.topologyDescription.type = 'Single';
2790-
});
2791-
beforeEach(function () {
2790+
27922791
const plugin = activateDocumentsPlugin(
27932792
{
27942793
isSearchIndexesSupported: true,
@@ -2821,6 +2820,37 @@ describe('store', function () {
28212820
preview: {
28222821
changes: [],
28232822
},
2823+
previewAbortController: undefined,
2824+
serverError: undefined,
2825+
syntaxError: undefined,
2826+
updateText: '{ $set: { anotherField: 2 } }',
2827+
});
2828+
});
2829+
2830+
it('resets syntaxError when there is no syntax error', async function () {
2831+
void store.openBulkUpdateDialog();
2832+
store.onQueryChanged({ filter: { field: 1 } });
2833+
await store.updateBulkUpdatePreview('{ $set: { anotherField: } }'); // syntax error
2834+
2835+
expect(previewUpdateStub.called).to.be.false;
2836+
2837+
expect(store.state.bulkUpdate.syntaxError?.name).to.equal(
2838+
'SyntaxError'
2839+
);
2840+
expect(store.state.bulkUpdate.syntaxError?.message).to.equal(
2841+
'Unexpected token (2:25)'
2842+
);
2843+
2844+
await store.updateBulkUpdatePreview('{ $set: { anotherField: 2 } }');
2845+
2846+
expect(previewUpdateStub.called).to.be.false;
2847+
2848+
expect(store.state.bulkUpdate).to.deep.equal({
2849+
isOpen: true,
2850+
preview: {
2851+
changes: [],
2852+
},
2853+
previewAbortController: undefined,
28242854
serverError: undefined,
28252855
syntaxError: undefined,
28262856
updateText: '{ $set: { anotherField: 2 } }',

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,8 +1152,22 @@ class CrudStoreImpl
11521152
previewAbortController: undefined,
11531153
},
11541154
});
1155+
return;
11551156
}
11561157

1158+
// if there's no syntax error, then just clear it
1159+
this.setState({
1160+
bulkUpdate: {
1161+
...this.state.bulkUpdate,
1162+
preview: {
1163+
changes: [],
1164+
},
1165+
serverError: undefined,
1166+
syntaxError: undefined,
1167+
previewAbortController: undefined,
1168+
},
1169+
});
1170+
11571171
return;
11581172
}
11591173

0 commit comments

Comments
 (0)