Skip to content

Commit 7928456

Browse files
committed
chore(import-export, home): setup connected app registry scope; refactor export store to use service injection
1 parent 99217bd commit 7928456

File tree

14 files changed

+83
-118
lines changed

14 files changed

+83
-118
lines changed

package-lock.json

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

packages/compass-home/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
"@mongodb-js/compass-import-export": "^7.19.1",
4848
"compass-preferences-model": "^2.15.6",
4949
"hadron-app-registry": "^9.0.14",
50-
"hadron-ipc": "^3.2.4"
50+
"hadron-ipc": "^3.2.4",
51+
"mongodb-data-service": "^22.15.1"
5152
},
5253
"peerDependencies": {
5354
"@mongodb-js/atlas-service": "^0.10.1",
@@ -64,6 +65,7 @@
6465
"compass-preferences-model": "^2.15.6",
6566
"hadron-app-registry": "^9.0.14",
6667
"hadron-ipc": "^3.2.4",
68+
"mongodb-data-service": "^22.15.1",
6769
"react": "^17.0.2"
6870
},
6971
"devDependencies": {
@@ -82,7 +84,6 @@
8284
"eventemitter3": "^4.0.0",
8385
"mocha": "^10.2.0",
8486
"mongodb-collection-model": "^5.15.1",
85-
"mongodb-data-service": "^22.15.1",
8687
"mongodb-ns": "^2.4.0",
8788
"nyc": "^15.1.0",
8889
"prettier": "^2.7.1",

packages/compass-home/src/components/home.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import React, {
3333
} from 'react';
3434
import preferences from 'compass-preferences-model';
3535
import { createLoggerAndTelemetry } from '@mongodb-js/compass-logging';
36-
import { useLocalAppRegistry } from 'hadron-app-registry';
36+
import { AppRegistryProvider, useLocalAppRegistry } from 'hadron-app-registry';
3737
import updateTitle from '../modules/update-title';
3838
import Workspace from './workspace';
3939
import { SignalHooksProvider } from '@mongodb-js/compass-components';
@@ -352,9 +352,13 @@ function Home({
352352
}}
353353
>
354354
{isConnected && connectedDataService.current && (
355-
<DataServiceProvider value={connectedDataService.current}>
356-
<Workspace namespace={namespace} />
357-
</DataServiceProvider>
355+
// AppRegistry scope for a connected application
356+
<AppRegistryProvider>
357+
<DataServiceProvider value={connectedDataService.current}>
358+
<ExportPlugin></ExportPlugin>
359+
<Workspace namespace={namespace} />
360+
</DataServiceProvider>
361+
</AppRegistryProvider>
358362
)}
359363
{/* Hide <Connections> but keep it in scope if connected so that the connection
360364
import/export functionality can still be used through the application menu */}
@@ -383,7 +387,6 @@ function Home({
383387
<CreateCollectionPlugin></CreateCollectionPlugin>
384388
<DropCollectionPlugin></DropCollectionPlugin>
385389
<ImportPlugin></ImportPlugin>
386-
<ExportPlugin></ExportPlugin>
387390
<AtlasSignIn></AtlasSignIn>
388391
</SignalHooksProvider>
389392
);

packages/compass-home/src/components/workspace-content.spec.tsx

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { cleanup, render, screen } from '@testing-library/react';
33
import { expect } from 'chai';
4-
import AppRegistry, { AppRegistryProvider } from 'hadron-app-registry';
4+
import { globalAppRegistry, AppRegistryProvider } from 'hadron-app-registry';
55
import WorkspaceContent from './workspace-content';
66

77
const getComponent = (name: string) => {
@@ -20,28 +20,18 @@ const getComponent = (name: string) => {
2020
};
2121

2222
describe('WorkspaceContent [Component]', function () {
23-
let testAppRegistry: AppRegistry;
24-
beforeEach(function () {
25-
testAppRegistry = new AppRegistry();
26-
23+
before(function () {
2724
['Collection.Workspace', 'Database.Workspace', 'Instance.Workspace'].map(
28-
(name) => testAppRegistry.registerComponent(name, getComponent(name))
25+
(name) => globalAppRegistry.registerComponent(name, getComponent(name))
2926
);
30-
testAppRegistry.onActivated();
27+
globalAppRegistry.onActivated();
3128
});
3229

33-
afterEach(function () {
34-
testAppRegistry = null;
35-
cleanup();
36-
});
30+
afterEach(cleanup);
3731

3832
describe('namespace is unset', function () {
3933
beforeEach(function () {
40-
render(
41-
<AppRegistryProvider localAppRegistry={testAppRegistry}>
42-
<WorkspaceContent namespace={{ database: '', collection: '' }} />
43-
</AppRegistryProvider>
44-
);
34+
render(<WorkspaceContent namespace={{ database: '', collection: '' }} />);
4535
});
4636

4737
it('renders content correctly', function () {
@@ -54,7 +44,7 @@ describe('WorkspaceContent [Component]', function () {
5444
describe('namespace has a db', function () {
5545
beforeEach(function () {
5646
render(
57-
<AppRegistryProvider localAppRegistry={testAppRegistry}>
47+
<AppRegistryProvider>
5848
<WorkspaceContent namespace={{ database: 'db', collection: '' }} />
5949
</AppRegistryProvider>
6050
);
@@ -70,7 +60,7 @@ describe('WorkspaceContent [Component]', function () {
7060
describe('namespace has db and collection', function () {
7161
beforeEach(function () {
7262
render(
73-
<AppRegistryProvider localAppRegistry={testAppRegistry}>
63+
<AppRegistryProvider>
7464
<WorkspaceContent namespace={{ database: 'db', collection: 'col' }} />
7565
</AppRegistryProvider>
7666
);

packages/compass-import-export/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"electron": "^25.9.3",
6666
"hadron-app-registry": "^9.0.14",
6767
"hadron-document": "^8.4.3",
68+
"mongodb-data-service": "^22.15.1",
6869
"react": "^17.0.2"
6970
},
7071
"dependencies": {
@@ -76,7 +77,8 @@
7677
"compass-preferences-model": "^2.15.6",
7778
"electron": "^25.9.3",
7879
"hadron-app-registry": "^9.0.14",
79-
"hadron-document": "^8.4.3"
80+
"hadron-document": "^8.4.3",
81+
"mongodb-data-service": "^22.15.1"
8082
},
8183
"devDependencies": {
8284
"@electron/remote": "^2.0.12",
@@ -106,7 +108,6 @@
106108
"lodash": "^4.17.21",
107109
"mocha": "^10.2.0",
108110
"mongodb": "^6.0.0",
109-
"mongodb-data-service": "^22.15.1",
110111
"mongodb-ns": "^2.4.0",
111112
"mongodb-query-parser": "^3.1.3",
112113
"mongodb-schema": "^12.1.0",

packages/compass-import-export/src/components/export-modal.spec.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ function renderModal(exportState: any = {}) {
1212
// component in a state that can actually be achieved when actions are emitted
1313
// on the store. Refactor this to either test unconnected component, or to
1414
// not mutate state directly for tests
15-
const store = configureStore();
15+
const store = configureStore({
16+
dataService: {},
17+
globalAppRegistry: {},
18+
} as any);
1619
const state = store.getState();
1720
state.export = {
1821
...state.export,

packages/compass-import-export/src/export/export-csv.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export async function exportCSVFromAggregation({
259259
...exportOptions
260260
}: Omit<ExportCSVOptions, 'input' | 'columns'> & {
261261
ns: string;
262-
dataService: DataService;
262+
dataService: Pick<DataService, 'aggregateCursor'>;
263263
aggregation: ExportAggregation;
264264
}) {
265265
debug('exportCSVFromAggregation()', { ns: toNS(ns), aggregation });
@@ -319,7 +319,7 @@ export async function exportCSVFromQuery({
319319
...exportOptions
320320
}: Omit<ExportCSVOptions, 'input' | 'columns'> & {
321321
ns: string;
322-
dataService: DataService;
322+
dataService: Pick<DataService, 'findCursor'>;
323323
query?: ExportQuery;
324324
}) {
325325
debug('exportCSVFromQuery()', { ns: toNS(ns), query });

packages/compass-import-export/src/export/export-json.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export async function exportJSONFromAggregation({
118118
...exportOptions
119119
}: Omit<ExportJSONOptions, 'input'> & {
120120
ns: string;
121-
dataService: DataService;
121+
dataService: Pick<DataService, 'aggregateCursor'>;
122122
aggregation: ExportAggregation;
123123
}) {
124124
debug('exportJSONFromAggregation()', { ns: toNS(ns), aggregation });
@@ -146,7 +146,7 @@ export async function exportJSONFromQuery({
146146
...exportOptions
147147
}: Omit<ExportJSONOptions, 'input'> & {
148148
ns: string;
149-
dataService: DataService;
149+
dataService: Pick<DataService, 'findCursor'>;
150150
query?: ExportQuery;
151151
}) {
152152
debug('exportJSONFromQuery()', { ns: toNS(ns), query });

packages/compass-import-export/src/export/gather-fields.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export async function gatherFieldsFromQuery({
141141
...exportOptions
142142
}: Omit<GatherFieldsOptions, 'input'> & {
143143
ns: string;
144-
dataService: DataService;
144+
dataService: Pick<DataService, 'findCursor'>;
145145
query?: ExportQuery;
146146
sampleSize?: number;
147147
}): ReturnType<typeof _gatherFields> {

packages/compass-import-export/src/index.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { registerHadronPlugin } from 'hadron-app-registry';
2+
import { dataServiceLocator } from 'mongodb-data-service/provider';
23
import ImportPluginComponent from './import-plugin';
34
import { activatePlugin as activateImportPlugin } from './stores/import-store';
45
import ExportPluginComponent from './export-plugin';
@@ -16,11 +17,18 @@ export const ImportPlugin = registerHadronPlugin({
1617
/**
1718
* The export plugin.
1819
*/
19-
export const ExportPlugin = registerHadronPlugin({
20-
name: 'Export',
21-
component: ExportPluginComponent,
22-
activate: activateExportPlugin,
23-
});
20+
export const ExportPlugin = registerHadronPlugin(
21+
{
22+
name: 'Export',
23+
component: ExportPluginComponent,
24+
activate: activateExportPlugin,
25+
},
26+
{
27+
dataService: dataServiceLocator as typeof dataServiceLocator<
28+
'findCursor' | 'aggregateCursor'
29+
>,
30+
}
31+
);
2432

2533
function activate(): void {
2634
// noop

0 commit comments

Comments
 (0)