Skip to content

Commit d6f3df0

Browse files
authored
feat: disable the update preview when transactions are not supported COMPASS-7449 (#5152)
* disable the update preview when transactions are not supported * lint * fix initial state test
1 parent 7dff3b9 commit d6f3df0

File tree

5 files changed

+356
-61
lines changed

5 files changed

+356
-61
lines changed

packages/compass-crud/src/components/bulk-update-dialog.spec.tsx

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ function renderBulkUpdateDialog(
2323
},
2424
],
2525
}}
26+
enablePreview={true}
2627
closeBulkUpdateDialog={() => {}}
2728
updateBulkUpdatePreview={() => {}}
2829
runBulkUpdate={() => {}}
@@ -156,9 +157,37 @@ describe('BulkUpdateDialog Component', function () {
156157
expect(onCloseSpy).to.have.been.calledOnce;
157158
});
158159

159-
it('runs the update when the update button is clicked', function () {
160+
it('runs the update when the update button is clicked (preview supported)', function () {
160161
const onUpdateSpy = sinon.spy();
161-
renderBulkUpdateDialog({ runBulkUpdate: onUpdateSpy, count: 60 });
162+
renderBulkUpdateDialog({
163+
enablePreview: true,
164+
runBulkUpdate: onUpdateSpy,
165+
count: 60,
166+
});
167+
168+
// has a preview
169+
expect(
170+
screen.getAllByTestId('bulk-update-preview-document')
171+
).to.have.lengthOf(1);
172+
173+
userEvent.click(
174+
screen.getByRole('button', { name: 'Update 60 documents' })
175+
);
176+
expect(onUpdateSpy).to.have.been.calledOnce;
177+
});
178+
179+
it('runs the update when the update button is clicked (preview unsupported)', function () {
180+
const onUpdateSpy = sinon.spy();
181+
renderBulkUpdateDialog({
182+
enablePreview: false,
183+
runBulkUpdate: onUpdateSpy,
184+
count: 60,
185+
});
186+
187+
// does not render a preview
188+
expect(
189+
screen.queryAllByTestId('bulk-update-preview-document')
190+
).to.have.lengthOf(0);
162191

163192
userEvent.click(
164193
screen.getByRole('button', { name: 'Update 60 documents' })

packages/compass-crud/src/components/bulk-update-dialog.tsx

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ export type BulkUpdateDialogProps = {
234234
preview: UpdatePreview;
235235
syntaxError?: Error & { loc?: { index: number } };
236236
serverError?: Error;
237+
enablePreview?: boolean;
237238
closeBulkUpdateDialog: () => void;
238239
updateBulkUpdatePreview: (updateText: string) => void;
239240
runBulkUpdate: () => void;
@@ -249,6 +250,7 @@ export default function BulkUpdateDialog({
249250
preview,
250251
syntaxError,
251252
serverError,
253+
enablePreview = false,
252254
closeBulkUpdateDialog,
253255
updateBulkUpdatePreview,
254256
runBulkUpdate,
@@ -311,13 +313,13 @@ export default function BulkUpdateDialog({
311313
<Modal
312314
open={isOpen}
313315
setOpen={closeBulkUpdateDialog}
314-
size="large"
316+
size={enablePreview ? 'large' : 'default'}
315317
data-testid="bulk-update-dialog"
316318
initialFocus={`#${bulkUpdateUpdateId} .cm-content`}
317319
>
318320
<ModalHeader title={modalTitleAndButtonText} subtitle={ns} />
319321
<ModalBody>
320-
<div className={columnsStyles}>
322+
<div className={enablePreview ? columnsStyles : undefined}>
321323
<div className={queryStyles}>
322324
<div className={queryFieldStyles}>
323325
<ReadonlyFilter
@@ -373,26 +375,28 @@ export default function BulkUpdateDialog({
373375
</KeylineCard>
374376
</div>
375377
</div>
376-
<div className={previewStyles}>
377-
<Label htmlFor="bulk-update-preview">
378-
Preview{' '}
379-
<Description className={previewDescriptionStyles}>
380-
(sample of {preview.changes.length} document
381-
{preview.changes.length === 1 ? '' : 's'})
382-
</Description>
383-
</Label>
384-
<div className={updatePreviewStyles}>
385-
{previewDocuments.map((doc: HadronDocument, index: number) => {
386-
return (
387-
<UpdatePreviewDocument
388-
key={`change=${index}`}
389-
data-testid="bulk-update-preview-document"
390-
doc={doc}
391-
/>
392-
);
393-
})}
378+
{enablePreview && (
379+
<div className={previewStyles}>
380+
<Label htmlFor="bulk-update-preview">
381+
Preview{' '}
382+
<Description className={previewDescriptionStyles}>
383+
(sample of {preview.changes.length} document
384+
{preview.changes.length === 1 ? '' : 's'})
385+
</Description>
386+
</Label>
387+
<div className={updatePreviewStyles}>
388+
{previewDocuments.map((doc: HadronDocument, index: number) => {
389+
return (
390+
<UpdatePreviewDocument
391+
key={`change=${index}`}
392+
data-testid="bulk-update-preview-document"
393+
doc={doc}
394+
/>
395+
);
396+
})}
397+
</div>
394398
</div>
395-
</div>
399+
)}
396400
</div>
397401
</ModalBody>
398402
<ModalFooter className={modalFooterToolbarSpacingStyles}>

packages/compass-crud/src/components/document-list.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export type DocumentListProps = {
107107
darkMode?: boolean;
108108
isCollectionScan?: boolean;
109109
isSearchIndexesSupported: boolean;
110+
isUpdatePreviewSupported: boolean;
110111
query: QueryState;
111112
} & Omit<DocumentListViewProps, 'className'> &
112113
Omit<DocumentTableViewProps, 'className'> &
@@ -279,6 +280,7 @@ class DocumentList extends React.Component<DocumentListProps> {
279280
ns={this.props.ns}
280281
filter={this.props.query.filter}
281282
count={this.props.count}
283+
enablePreview={this.props.isUpdatePreviewSupported}
282284
{...this.props.bulkUpdate}
283285
closeBulkUpdateDialog={this.props.closeBulkUpdateDialog}
284286
updateBulkUpdatePreview={this.props.updateBulkUpdatePreview}
@@ -564,6 +566,7 @@ DocumentList.propTypes = {
564566
darkMode: PropTypes.bool,
565567
isCollectionScan: PropTypes.bool,
566568
isSearchIndexesSupported: PropTypes.bool,
569+
isUpdatePreviewSupported: PropTypes.bool,
567570
};
568571

569572
DocumentList.defaultProps = {

0 commit comments

Comments
 (0)