Skip to content

Commit 9b46270

Browse files
authored
feat(compass-import-export): remove export feature flag, use new export, remove old code COMPASS-6582 (#4336)
1 parent 7c77a98 commit 9b46270

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+117
-5967
lines changed

package-lock.json

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

packages/compass-collection/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
"@mongodb-js/compass-components": "^1.8.0",
6262
"@mongodb-js/compass-logging": "^1.1.5",
6363
"bson": "^5.2.0",
64-
"compass-preferences-model": "^2.8.0",
6564
"hadron-app-registry": "^9.0.6",
6665
"hadron-ipc": "^3.1.2",
6766
"react": "^17.0.2"
@@ -70,7 +69,6 @@
7069
"@mongodb-js/compass-components": "^1.8.0",
7170
"@mongodb-js/compass-logging": "^1.1.5",
7271
"bson": "^5.2.0",
73-
"compass-preferences-model": "^2.8.0",
7472
"hadron-app-registry": "^9.0.6",
7573
"hadron-ipc": "^3.1.2"
7674
},

packages/compass-collection/src/stores/index.ts

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type { AnyAction } from 'redux';
66
import thunk from 'redux-thunk';
77
import toNS from 'mongodb-ns';
88
import type { DataService } from 'mongodb-data-service';
9-
import preferences from 'compass-preferences-model';
109

1110
import appRegistry, {
1211
appRegistryActivated,
@@ -342,30 +341,20 @@ store.onActivated = (appRegistry: AppRegistry) => {
342341
const activeTab = state.tabs.find(
343342
(tab: WorkspaceTabObject) => tab.isActive === true
344343
);
345-
if (activeTab) {
346-
const crudStore = activeTab.localAppRegistry.getStore('CRUD.Store');
347-
const { query: crudQuery, count } = crudStore.state;
348-
// TODO(COMPASS-6582): Remove feature flag, use new export.
349-
if (preferences.getPreferences().useNewExport) {
350-
const { filter, project, collation, limit, skip, sort } = crudQuery;
351-
appRegistry.emit('open-export', {
352-
exportFullCollection: true,
353-
namespace: activeTab.namespace,
354-
query: { filter, project, collation, limit, skip, sort },
355-
count,
356-
origin: 'menu',
357-
});
358-
return;
359-
}
360-
361-
const { filter, project, collation, limit, skip, sort } = crudQuery;
362-
appRegistry.emit('open-export', {
363-
exportFullCollection: true,
364-
namespace: activeTab.namespace,
365-
query: { filter, project, collation, limit, skip, sort },
366-
count,
367-
});
344+
if (!activeTab) {
345+
return;
368346
}
347+
const crudStore = activeTab.localAppRegistry.getStore('CRUD.Store');
348+
const { query: crudQuery, count } = crudStore.state;
349+
350+
const { filter, project, collation, limit, skip, sort } = crudQuery;
351+
appRegistry.emit('open-export', {
352+
exportFullCollection: true,
353+
namespace: activeTab.namespace,
354+
query: { filter, project, collation, limit, skip, sort },
355+
count,
356+
origin: 'menu',
357+
});
369358
});
370359

371360
ipc.on('compass:open-import', () => {

packages/compass-crud/src/components/crud-toolbar.spec.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,11 @@ describe('CrudToolbar Component', function () {
262262
});
263263

264264
expect(exportSpy.called).to.be.false;
265-
fireEvent.click(screen.getByText('Export Collection'));
265+
fireEvent.click(screen.getByText('Export Data'));
266+
fireEvent.click(screen.getByText('Export the full collection'));
266267

267268
expect(exportSpy.calledOnce).to.be.true;
269+
expect(exportSpy.firstCall.args[0]).to.be.true;
268270
});
269271

270272
it('should not render the outdated message', function () {

packages/compass-crud/src/components/crud-toolbar.tsx

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import React, { useCallback, useMemo, useRef } from 'react';
33
import { createLoggerAndTelemetry } from '@mongodb-js/compass-logging';
44
import {
55
Body,
6-
Button,
76
DropdownMenuButton,
87
Icon,
98
IconButton,
@@ -16,7 +15,6 @@ import {
1615
WarningSummary,
1716
ErrorSummary,
1817
} from '@mongodb-js/compass-components';
19-
import { usePreference } from 'compass-preferences-model';
2018
import type { MenuAction } from '@mongodb-js/compass-components';
2119

2220
import { AddDataMenu } from './add-data-menu';
@@ -137,8 +135,6 @@ const CrudToolbar: React.FunctionComponent<CrudToolbarProps> = ({
137135
}) => {
138136
const queryBarRole = localAppRegistry.getRole('Query.QueryBar')![0];
139137

140-
const useNewExport = usePreference('useNewExport', React);
141-
142138
const queryBarRef = useRef(
143139
isExportable
144140
? {
@@ -194,32 +190,19 @@ const CrudToolbar: React.FunctionComponent<CrudToolbarProps> = ({
194190
instanceDescription={instanceDescription}
195191
/>
196192
)}
197-
{/* TODO(COMPASS-6582): Remove feature flag, use next export. */}
198-
{useNewExport ? (
199-
<DropdownMenuButton<ExportDataOption>
200-
data-testid="crud-export-collection"
201-
actions={exportDataActions}
202-
onAction={(action: ExportDataOption) =>
203-
openExportFileDialog(action === 'export-full-collection')
204-
}
205-
buttonText="Export Data"
206-
buttonProps={{
207-
className: exportCollectionButtonStyles,
208-
size: 'xsmall',
209-
leftGlyph: <Icon glyph="Export" />,
210-
}}
211-
/>
212-
) : (
213-
<Button
214-
className={exportCollectionButtonStyles}
215-
leftGlyph={<Icon glyph="Export" />}
216-
data-testid="export-collection-button"
217-
size="xsmall"
218-
onClick={() => openExportFileDialog(undefined)}
219-
>
220-
Export Collection
221-
</Button>
222-
)}
193+
<DropdownMenuButton<ExportDataOption>
194+
data-testid="crud-export-collection"
195+
actions={exportDataActions}
196+
onAction={(action: ExportDataOption) =>
197+
openExportFileDialog(action === 'export-full-collection')
198+
}
199+
buttonText="Export Data"
200+
buttonProps={{
201+
className: exportCollectionButtonStyles,
202+
size: 'xsmall',
203+
leftGlyph: <Icon glyph="Export" />,
204+
}}
205+
/>
223206
</div>
224207
<div className={toolbarRightActionStyles}>
225208
<Body data-testid="crud-document-count-display">

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

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ import type { Element } from 'hadron-document';
88
import { Document } from 'hadron-document';
99
import HadronDocument from 'hadron-document';
1010
import createLoggerAndTelemetry from '@mongodb-js/compass-logging';
11-
import preferences, {
12-
capMaxTimeMSAtPreferenceLimit,
13-
} from 'compass-preferences-model';
11+
import { capMaxTimeMSAtPreferenceLimit } from 'compass-preferences-model';
1412

1513
import {
1614
findDocuments,
@@ -986,27 +984,13 @@ class CrudStoreImpl
986984
* Emits a global app registry event the plugin listens to.
987985
*/
988986
openExportFileDialog(exportFullCollection?: boolean) {
989-
// TODO(COMPASS-6582): Remove feature flag, use new export.
990-
if (preferences.getPreferences().useNewExport) {
991-
const { filter, project, collation, limit, skip, sort } =
992-
this.state.query;
993-
994-
this.globalAppRegistry.emit('open-export', {
995-
namespace: this.state.ns,
996-
query: { filter, project, collation, limit, skip, sort },
997-
exportFullCollection,
998-
origin: 'crud-toolbar',
999-
});
1000-
return;
1001-
}
987+
const { filter, project, collation, limit, skip, sort } = this.state.query;
1002988

1003-
// Only three query fields that export modal will handle
1004-
const { filter, limit, skip } = this.state.query;
1005989
this.globalAppRegistry.emit('open-export', {
1006990
namespace: this.state.ns,
1007-
query: { filter, limit, skip },
1008-
// Pass the doc count to the export modal so we can avoid re-counting.
1009-
count: this.state.count,
991+
query: { filter, project, collation, limit, skip, sort },
992+
exportFullCollection,
993+
origin: 'crud-toolbar',
1010994
});
1011995
}
1012996

packages/compass-e2e-tests/helpers/commands/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,4 @@ export * from './drop-database-from-sidebar';
5656
export * from './toggle-aggregation-side-panel';
5757
export * from './add-wizard';
5858
export * from './set-combo-box-value';
59+
export * from './wait-for-export-to-finish';
Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import chai, { expect } from 'chai';
22
import { promises as fs } from 'fs';
33
import type { CompassBrowser } from '../compass-browser';
4-
import * as Selectors from '../selectors';
54
import chaiAsPromised from 'chai-as-promised';
65

76
chai.use(chaiAsPromised);
87

98
export async function setExportFilename(
109
browser: CompassBrowser,
11-
filename: string,
12-
skipUIElementCheck?: boolean // TODO(COMPASS-6582): Remove this option an default to skipping the UI element check.
10+
filename: string
1311
): Promise<void> {
1412
// make sure the file doesn't already exist
1513
await expect(fs.stat(filename)).to.be.rejected;
@@ -19,20 +17,4 @@ export async function setExportFilename(
1917
new CustomEvent('selectExportFileName', { detail: f })
2018
);
2119
}, filename);
22-
23-
if (skipUIElementCheck) {
24-
// With the new export we use the electron file window directly (showSaveDialog) instead
25-
// of using an html input element. So we don't have an element to check here.
26-
return;
27-
}
28-
29-
await browser.waitUntil(async () => {
30-
const exportModalFileInput = await browser.$(
31-
Selectors.ExportModalFileInput
32-
);
33-
const filenames: string = await exportModalFileInput.getAttribute(
34-
'data-filenames'
35-
);
36-
return JSON.parse(filenames).includes(filename);
37-
});
3820
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { CompassBrowser } from '../compass-browser';
2+
import * as Selectors from '../selectors';
3+
4+
export async function waitForExportToFinishAndCloseToast(
5+
browser: CompassBrowser
6+
) {
7+
// Wait for the export to finish and close the toast.
8+
const toastElement = await browser.$(Selectors.ExportToast);
9+
await toastElement.waitForDisplayed();
10+
11+
const exportShowFileButtonElement = await browser.$(
12+
Selectors.ExportToastShowFile
13+
);
14+
await exportShowFileButtonElement.waitForDisplayed();
15+
await browser
16+
.$(Selectors.closeToastButton(Selectors.ExportToast))
17+
.waitForDisplayed();
18+
await browser.clickVisible(Selectors.closeToastButton(Selectors.ExportToast));
19+
await toastElement.waitForDisplayed({ reverse: true });
20+
}

packages/compass-e2e-tests/helpers/selectors.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,6 @@ export const collectionHeaderTitle = (
507507
// Documents tab
508508
export const DocumentListActionBarMessage =
509509
'[data-testid="crud-document-count-display"]';
510-
export const ExportCollectionButton =
511-
'[data-testid="export-collection-button"]'; // TODO(COMPASS-6582): Remove.
512510
export const ExportCollectionMenuButton =
513511
'[data-testid="crud-export-collection-show-actions"]';
514512
export const ExportCollectionQueryOption =
@@ -1053,28 +1051,16 @@ export const ExportJSONFormatAccordion =
10531051
'[data-testid="export-modal"] [data-testid="export-advanced-json-format"]';
10541052
export const ExportJSONFormatCanonical =
10551053
'[data-testid="export-modal"] [data-testid="export-json-format-canonical"]';
1056-
export const ExportModalFullCollectionOption =
1057-
'[data-testid="export-modal"] [data-testid="export-full-collection"]'; // TODO(COMPASS-6582): Remove.
1058-
export const ExportModalSelectFieldsButton =
1059-
'[data-testid="export-modal"] [data-testid="select-fields-button"]'; // TODO(COMPASS-6582): Remove.
1060-
export const ExportModalSelectOutputButton =
1061-
'[data-testid="export-modal"] [data-testid="select-output-button"]'; // TODO(COMPASS-6582): Remove.
10621054
export const ExportModalExportButton =
1063-
'[data-testid="export-modal"] [data-testid="export-button"]'; // TODO(COMPASS-6582): Remove.
1064-
export const ExportModalShowFileButton =
1065-
'[data-testid="export-modal"] [data-testid="show-file-button"]'; // TODO(COMPASS-6582): Remove.
1066-
export const ExportModalCloseButton =
1067-
'[data-testid="export-modal"] [data-testid="close-button"]'; // TODO(COMPASS-6582): Remove.
1068-
export const ExportModalFileInput =
1069-
'[data-testid="export-modal"] #export-file_file_input'; // // // // TODO(COMPASS-6582): Remove.
1055+
'[data-testid="export-modal"] [data-testid="export-button"]';
10701056
export const ExportToast = '[data-testid="toast-export-toast"]';
10711057
export const ExportToastAbort =
1072-
'[data-testid="toast-export-toast"] [data-testid="toast-action-stop"]'; // TODO: Add test that uses this.
1058+
'[data-testid="toast-export-toast"] [data-testid="toast-action-stop"]';
10731059
export const ExportToastShowFile =
10741060
'[data-testid="toast-export-toast"] [data-testid="toast-action-show file"]';
10751061

10761062
export const exportModalExportField = (fieldName: string): string => {
1077-
return `[data-testid="export-modal"] input[type="checkbox"][name="${fieldName}"]`; // TODO(COMPASS-6582): Remove.
1063+
return `[data-testid="export-modal"] input[type="checkbox"][name="${fieldName}"]`;
10781064
};
10791065

10801066
// Export to language modal

0 commit comments

Comments
 (0)