Skip to content

Commit

Permalink
chore: add new registerHadronPlugin() mechanism COMPASS-7321 (#5060)
Browse files Browse the repository at this point in the history
* chore: refactor AppRegistryContext and move it to hadron-app-registry pkg

* chore(hadron-app-registry): add new registerHadronPlugin() mechanism COMPASS-7321

Largely based on 8054bf8.

* chore(compass-home): convert plugin to use new interface

* chore(compass-settings): convert plugin to use new interface

Co-authored-by: Sergey Petushkov <[email protected]>
  • Loading branch information
addaleax and gribnoysup authored Nov 7, 2023
1 parent dfcc0fa commit 052c51d
Show file tree
Hide file tree
Showing 75 changed files with 876 additions and 410 deletions.
24 changes: 16 additions & 8 deletions package-lock.json

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

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
DragOverlay,
} from '@dnd-kit/core';
import type { DragEndEvent, DragStartEvent } from '@dnd-kit/core';
import createLoggerAndTelemetry from '@mongodb-js/compass-logging';
import { createLoggerAndTelemetry } from '@mongodb-js/compass-logging';

import {
indexFromDroppableId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useRef, useEffect } from 'react';
import { openToast } from '@mongodb-js/compass-components';
import { GenerativeAIInput } from '@mongodb-js/compass-generative-ai';
import { connect } from 'react-redux';
import createLoggerAndTelemetry from '@mongodb-js/compass-logging';
import { createLoggerAndTelemetry } from '@mongodb-js/compass-logging';
import { usePreference } from 'compass-preferences-model';

import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
AtlasNavGraphic,
Body,
} from '@mongodb-js/compass-components';
import createLoggerAndTelemetry from '@mongodb-js/compass-logging';
import { createLoggerAndTelemetry } from '@mongodb-js/compass-logging';
const { track } = createLoggerAndTelemetry('COMPASS-AGGREGATIONS-UI');

const ATLAS_LINK =
Expand Down
2 changes: 1 addition & 1 deletion packages/compass-aggregations/src/modules/focus-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { AnyAction } from 'redux';
import type { PipelineBuilderThunkAction } from '.';
import { isAction } from '../utils/is-action';
import { addStage, pipelineFromStore } from './pipeline-builder/stage-editor';
import createLoggerAndTelemetry from '@mongodb-js/compass-logging';
import { createLoggerAndTelemetry } from '@mongodb-js/compass-logging';

const { track } = createLoggerAndTelemetry('COMPASS-AGGREGATIONS-UI');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Reducer } from 'redux';
import createLoggerAndTelemetry from '@mongodb-js/compass-logging';
import { createLoggerAndTelemetry } from '@mongodb-js/compass-logging';
import { getSimplifiedSchema } from 'mongodb-schema';
import toNS from 'mongodb-ns';
import preferences from 'compass-preferences-model';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '../modules/collection-tab';
import { css, ErrorBoundary, TabNavBar } from '@mongodb-js/compass-components';
import CollectionHeader from './collection-header';
import createLoggerAndTelemetry from '@mongodb-js/compass-logging';
import { createLoggerAndTelemetry } from '@mongodb-js/compass-logging';

const { log, mongoLogId, track } = createLoggerAndTelemetry(
'COMPASS-COLLECTION-TAB-UI'
Expand Down
6 changes: 3 additions & 3 deletions packages/compass-collection/src/stores/collection-tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ export function configureStore(options: CollectionTabOptions) {
throw new Error('Expected to get instance from App.InstanceStore');
}

const configureFieldStore = globalAppRegistry.getStore('Field.Store') as (
...args: any
) => void | undefined; // our handcrafted d.ts file doesn't match the actual code
const configureFieldStore = globalAppRegistry.getStore(
'Field.Store'
) as unknown as (...args: any) => void | undefined; // Field.Store is odd because it registers a configure method, not the actual store

configureFieldStore?.({
localAppRegistry: localAppRegistry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
useDarkMode,
} from '@mongodb-js/compass-components';

import createLoggerAndTelemetry from '@mongodb-js/compass-logging';
import { createLoggerAndTelemetry } from '@mongodb-js/compass-logging';
const { track } = createLoggerAndTelemetry('COMPASS-CONNECT-UI');

const formHelpContainerStyles = css({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import createLoggerAndTelemetry from '@mongodb-js/compass-logging';
import { createLoggerAndTelemetry } from '@mongodb-js/compass-logging';
import { isCancelError, raceWithAbort } from '@mongodb-js/compass-utils';
import type { ConnectionOptions, DataService } from 'mongodb-data-service';
import { connect } from 'mongodb-data-service';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import InsertCSFLEWarningBanner from './insert-csfle-warning-banner';
import InsertJsonDocument from './insert-json-document';
import InsertDocument from './insert-document';
import type { LoggerAndTelemetry } from '@mongodb-js/compass-logging';
import { withLoggerAndTelemetry } from '@mongodb-js/compass-logging';
import { withLoggerAndTelemetry } from '@mongodb-js/compass-logging/provider';

/**
* The insert invalid message.
Expand Down Expand Up @@ -341,8 +341,4 @@ class InsertDocumentDialog extends React.PureComponent<
}
}

export default withLoggerAndTelemetry(
InsertDocumentDialog,
'COMPASS-CRUD-UI',
React
);
export default withLoggerAndTelemetry(InsertDocumentDialog, 'COMPASS-CRUD-UI');
2 changes: 1 addition & 1 deletion packages/compass-crud/src/stores/crud-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { Element } from 'hadron-document';
import { Document } from 'hadron-document';
import HadronDocument from 'hadron-document';
import _parseShellBSON, { ParseMode } from 'ejson-shell-parser';
import createLoggerAndTelemetry from '@mongodb-js/compass-logging';
import { createLoggerAndTelemetry } from '@mongodb-js/compass-logging';
import { capMaxTimeMSAtPreferenceLimit } from 'compass-preferences-model';
import type { Stage } from '@mongodb-js/explain-plan-helper';
import { ExplainPlan } from '@mongodb-js/explain-plan-helper';
Expand Down
6 changes: 4 additions & 2 deletions packages/compass-crud/src/utils/cancellable-queries.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import createLogger from '@mongodb-js/compass-logging';
import { createLoggerAndTelemetry } from '@mongodb-js/compass-logging';
import { capMaxTimeMSAtPreferenceLimit } from 'compass-preferences-model';
import type { DataService } from 'mongodb-data-service';
import type { BSONObject } from '../stores/crud-store';

const { log, mongoLogId, debug } = createLogger('cancellable-queries');
const { log, mongoLogId, debug } = createLoggerAndTelemetry(
'COMPASS-CANCELLABLE-QUERIES'
);

export async function countDocuments(
dataService: DataService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { Action, AnyAction, Reducer } from 'redux';
import { applyMiddleware, createStore } from 'redux';
import type { ThunkAction } from 'redux-thunk';
import thunk from 'redux-thunk';
import createLoggerAndTelemetry from '@mongodb-js/compass-logging';
import { createLoggerAndTelemetry } from '@mongodb-js/compass-logging';

const { log, mongoLogId, track } =
createLoggerAndTelemetry('COMPASS-EXPLAIN-UI');
Expand Down
2 changes: 2 additions & 0 deletions packages/compass-home/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@mongodb-js/compass-components": "^1.19.0",
"@mongodb-js/compass-connections": "^1.20.0",
"@mongodb-js/compass-logging": "^1.2.5",
"@mongodb-js/compass-settings": "^0.21.0",
"@mongodb-js/compass-welcome": "^0.18.0",
"@mongodb-js/connection-storage": "^0.6.5",
"compass-preferences-model": "^2.15.5",
Expand All @@ -49,6 +50,7 @@
"@mongodb-js/compass-components": "^1.19.0",
"@mongodb-js/compass-connections": "^1.20.0",
"@mongodb-js/compass-logging": "^1.2.5",
"@mongodb-js/compass-settings": "^0.21.0",
"@mongodb-js/compass-welcome": "^0.18.0",
"@mongodb-js/connection-storage": "^0.6.5",
"compass-preferences-model": "^2.15.5",
Expand Down
27 changes: 13 additions & 14 deletions packages/compass-home/src/components/home.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import React from 'react';
import { once } from 'events';
import { cleanup, render, screen, waitFor } from '@testing-library/react';
import { expect } from 'chai';
import AppRegistry from 'hadron-app-registry';
import ipc from 'hadron-ipc';
import AppRegistry, { AppRegistryProvider } from 'hadron-app-registry';
import { ipcRenderer } from 'hadron-ipc';
import sinon from 'sinon';
import AppRegistryContext from '../contexts/app-registry-context';
import Home from '.';

const getComponent = (name: string) => {
Expand Down Expand Up @@ -61,9 +60,9 @@ describe('Home [Component]', function () {
describe('is not connected', function () {
beforeEach(function () {
render(
<AppRegistryContext.Provider value={testAppRegistry}>
<AppRegistryProvider localAppRegistry={testAppRegistry}>
<Home appName="home-testing" />
</AppRegistryContext.Provider>
</AppRegistryProvider>
);
});

Expand All @@ -82,9 +81,9 @@ describe('Home [Component]', function () {
connectionOptions = { connectionString: 'mongodb+srv://mongodb.net/' }
) {
render(
<AppRegistryContext.Provider value={testAppRegistry}>
<AppRegistryProvider localAppRegistry={testAppRegistry}>
<Home appName="home-testing" />
</AppRegistryContext.Provider>
</AppRegistryProvider>
);
testAppRegistry.emit('data-service-connected', null, dataService, {
connectionOptions,
Expand Down Expand Up @@ -128,16 +127,16 @@ describe('Home [Component]', function () {
describe('on `app:disconnect`', function () {
// Skip disconnect testing when we're not running in a renderer instance.
// eslint-disable-next-line mocha/no-setup-in-describe
if (!ipc.ipcRenderer) {
if (!ipcRenderer) {
// eslint-disable-next-line mocha/no-setup-in-describe, no-console
console.warn(
'Skipping "app:disconnect" ipc event tests on non-renderer environment.'
);
return;
return this;
}

beforeEach(async function () {
ipc.ipcRenderer.emit('app:disconnect');
ipcRenderer?.emit('app:disconnect');
await once(testAppRegistry, 'data-service-disconnected');
});

Expand All @@ -159,9 +158,9 @@ describe('Home [Component]', function () {
describe('when rendered', function () {
beforeEach(function () {
render(
<AppRegistryContext.Provider value={testAppRegistry}>
<AppRegistryProvider localAppRegistry={testAppRegistry}>
<Home appName="home-testing" />
</AppRegistryContext.Provider>
</AppRegistryProvider>
);
});

Expand All @@ -184,9 +183,9 @@ describe('Home [Component]', function () {
describe('on dismount', function () {
beforeEach(function () {
const { unmount } = render(
<AppRegistryContext.Provider value={testAppRegistry}>
<AppRegistryProvider localAppRegistry={testAppRegistry}>
<Home appName="home-testing" />
</AppRegistryContext.Provider>
</AppRegistryProvider>
);
unmount();
});
Expand Down
Loading

0 comments on commit 052c51d

Please sign in to comment.