Skip to content

Commit

Permalink
chore(compass-collection): replace hadron-ipc usage with globalAppReg…
Browse files Browse the repository at this point in the history
…istry events COMPASS-7310 (#5042)

chore(compass-collection): replace hadron-ipc usage with global app registry events
  • Loading branch information
gribnoysup authored Nov 1, 2023
1 parent 6cc3d9a commit 8ef82f0
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 45 deletions.
5 changes: 1 addition & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions packages/compass-collection/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,14 @@
"bson": "^6.0.0",
"compass-preferences-model": "^2.15.3",
"hadron-app-registry": "^9.0.12",
"hadron-ipc": "^3.2.2",
"react": "^17.0.2"
},
"dependencies": {
"@mongodb-js/compass-components": "^1.17.0",
"@mongodb-js/compass-logging": "^1.2.3",
"bson": "^6.0.0",
"compass-preferences-model": "^2.15.3",
"hadron-app-registry": "^9.0.12",
"hadron-ipc": "^3.2.2"
"hadron-app-registry": "^9.0.12"
},
"devDependencies": {
"@mongodb-js/eslint-config-compass": "^1.0.10",
Expand Down
3 changes: 3 additions & 0 deletions packages/compass-collection/src/stores/tabs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@ describe('Collection Tabs Store', function () {
'database-dropped',
'data-service-connected',
'data-service-disconnected',
'menu-share-schema-json',
'open-active-namespace-export',
'open-active-namespace-import',
]);
});
});
Expand Down
60 changes: 26 additions & 34 deletions packages/compass-collection/src/stores/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,48 +100,40 @@ export function configureStore({
thunkExtraArg.dataService = null;
});

// eslint-disable-next-line @typescript-eslint/no-var-requires
const { ipcRenderer: ipc } = require('hadron-ipc');

// TODO: importing hadron-ipc in unit tests doesn't work right now
if (ipc?.on) {
ipc.on('window:menu-share-schema-json', () => {
const activeTab = getActiveTab(store.getState());

if (!activeTab) {
return;
}

activeTab.localAppRegistry.emit('menu-share-schema-json');
});
globalAppRegistry.on('menu-share-schema-json', () => {
const activeTab = getActiveTab(store.getState());
if (!activeTab) {
return;
}
activeTab.localAppRegistry.emit('menu-share-schema-json');
});

ipc.on('compass:open-export', () => {
const activeTab = getActiveTab(store.getState());
globalAppRegistry.on('open-active-namespace-export', function () {
const activeTab = getActiveTab(store.getState());

if (!activeTab) {
return;
}
if (!activeTab) {
return;
}

globalAppRegistry.emit('open-export', {
exportFullCollection: true,
namespace: activeTab.namespace,
origin: 'menu',
});
globalAppRegistry.emit('open-export', {
exportFullCollection: true,
namespace: activeTab.namespace,
origin: 'menu',
});
});

ipc.on('compass:open-import', () => {
const activeTab = getActiveTab(store.getState());
globalAppRegistry.on('open-active-namespace-import', function () {
const activeTab = getActiveTab(store.getState());

if (!activeTab) {
return;
}
if (!activeTab) {
return;
}

globalAppRegistry.emit('open-import', {
namespace: activeTab.namespace,
origin: 'menu',
});
globalAppRegistry.emit('open-import', {
namespace: activeTab.namespace,
origin: 'menu',
});
}
});
},
});

Expand Down
17 changes: 13 additions & 4 deletions packages/compass/src/app/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import '../setup-hadron-distribution';

import dns from 'dns';
import ipc from 'hadron-ipc';
import { ipcRenderer } from 'hadron-ipc';
import * as remote from '@electron/remote';

import preferences, { getActiveUser } from 'compass-preferences-model';
Expand All @@ -19,7 +19,7 @@ if (!process.env.NODE_OPTIONS.includes('--dns-result-order')) {
// Setup error reporting to main process before anything else.
window.addEventListener('error', (event) => {
event.preventDefault();
ipc.call(
ipcRenderer?.call(
'compass:error:fatal',
event.error
? { message: event.error.message, stack: event.error.stack }
Expand Down Expand Up @@ -231,13 +231,22 @@ app.extend({
// noop
}
// Catch a data refresh coming from window-manager.
ipc.on('app:refresh-data', () =>
ipcRenderer?.on('app:refresh-data', () =>
global.hadronApp.appRegistry.emit('refresh-data')
);
// Catch a toggle sidebar coming from window-manager.
ipc.on('app:toggle-sidebar', () =>
ipcRenderer?.on('app:toggle-sidebar', () =>
global.hadronApp.appRegistry.emit('toggle-sidebar')
);
ipcRenderer?.on('window:menu-share-schema-json', () => {
global.hadronApp.appRegistry.emit('menu-share-schema-json');
});
ipcRenderer?.on('compass:open-export', () => {
global.hadronApp.appRegistry.emit('open-active-namespace-export');
});
ipcRenderer?.on('compass:open-import', () => {
global.hadronApp.appRegistry.emit('open-active-namespace-import');
});
// As soon as dom is ready, render and set up the rest.
state.render();
marky.stop('Time to Connect rendered');
Expand Down

0 comments on commit 8ef82f0

Please sign in to comment.