From 8ef82f089f12794cf93293f3fb46a4d49c84104d Mon Sep 17 00:00:00 2001 From: Sergey Petushkov Date: Wed, 1 Nov 2023 08:47:57 +0100 Subject: [PATCH] chore(compass-collection): replace hadron-ipc usage with globalAppRegistry events COMPASS-7310 (#5042) chore(compass-collection): replace hadron-ipc usage with global app registry events --- package-lock.json | 5 +- packages/compass-collection/package.json | 4 +- .../src/stores/tabs.spec.ts | 3 + .../compass-collection/src/stores/tabs.ts | 60 ++++++++----------- packages/compass/src/app/index.jsx | 17 ++++-- 5 files changed, 44 insertions(+), 45 deletions(-) diff --git a/package-lock.json b/package-lock.json index b73b9d1c665..0f8c4b6f082 100644 --- a/package-lock.json +++ b/package-lock.json @@ -44163,8 +44163,7 @@ "@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", @@ -44207,7 +44206,6 @@ "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" } }, @@ -58221,7 +58219,6 @@ "depcheck": "^1.4.1", "eslint": "^7.25.0", "hadron-app-registry": "^9.0.12", - "hadron-ipc": "^3.2.2", "mocha": "^10.2.0", "mongodb": "^6.0.0", "mongodb-collection-model": "^5.13.0", diff --git a/packages/compass-collection/package.json b/packages/compass-collection/package.json index 527c4407d76..575a028c17e 100644 --- a/packages/compass-collection/package.json +++ b/packages/compass-collection/package.json @@ -61,7 +61,6 @@ "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": { @@ -69,8 +68,7 @@ "@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", diff --git a/packages/compass-collection/src/stores/tabs.spec.ts b/packages/compass-collection/src/stores/tabs.spec.ts index e60f5816553..eb2190c58da 100644 --- a/packages/compass-collection/src/stores/tabs.spec.ts +++ b/packages/compass-collection/src/stores/tabs.spec.ts @@ -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', ]); }); }); diff --git a/packages/compass-collection/src/stores/tabs.ts b/packages/compass-collection/src/stores/tabs.ts index 2d47b4d1843..070afdd831f 100644 --- a/packages/compass-collection/src/stores/tabs.ts +++ b/packages/compass-collection/src/stores/tabs.ts @@ -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', }); - } + }); }, }); diff --git a/packages/compass/src/app/index.jsx b/packages/compass/src/app/index.jsx index 592ca6f2c32..84615e460fa 100644 --- a/packages/compass/src/app/index.jsx +++ b/packages/compass/src/app/index.jsx @@ -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'; @@ -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 } @@ -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');