Skip to content

Commit

Permalink
chore(my-queries-storage): implement provider for my-queries-storage C…
Browse files Browse the repository at this point in the history
…OMPASS-7411 (#5384)

* chore: introduce PipelineStorageProvider

* chore: introduce FavoriteQueryStorageProvider

* chore: introduce RecentQueryStorageContextProvider

* chore: fix type for SavedQueryAggregationExtraArgs

* chore: fix for missing react dep

* chore: enable eslint plugin and fix for testcases and source

* chore: minor refactor in name

* chore: remove duplicate import

* chore: fixes the render issue with previous implementation of storage locator

* chore: fixes for failing tests - added mock provider

* chore: use type instead of derived ones

* chore: addresses PR review

- expands eslint config to exclude test helpers from reporting on
  no-restricted-imports
- use PipelineStorage and Fav/RecentQueryStorage directly in test setups

* fix: remove namespace from QueryStorage options and make it part of loadAll method

* fix: fixes for failing test cases in compass-crud

* fix: fixes for failing test cases in compass-crud - 1

* fix for lint

* fix for compass-home tests

* add my-queries-storage as dev-dep for compas-home

* chore: PR feedback

- expose getStorage to retrieve QueryStorage instead of createStorage
- use interfaces to describe the implementation being injected in
  plugins instead of actual implementation itself (Compass specific)

* eslint rule check modified

* PR feedback - use exported helper to reduce usage verbosity in tests
  • Loading branch information
himanshusinghs authored Feb 14, 2024
1 parent bfadcc9 commit 20a6ff8
Show file tree
Hide file tree
Showing 42 changed files with 739 additions and 381 deletions.
10 changes: 8 additions & 2 deletions configs/eslint-config-compass/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const tsxOverrides = {

const testJsOverrides = {
...common.testOverrides,
files: ['**/*.spec.js', '**/*.spec.jsx', '**/*.test.js'],
files: ['**/*.spec.js', '**/*.spec.jsx', '**/*.test.js', '**/test/**/*.js'],
rules: {
...common.testRules,
'@mongodb-js/compass/unique-mongodb-log-id': 'off',
Expand All @@ -48,7 +48,13 @@ const testJsOverrides = {
};

const testTsOverrides = {
files: ['**/*.spec.ts', '**/*.spec.tsx', '**/*.test.tsx', '**/*.test.ts'],
files: [
'**/*.spec.ts',
'**/*.spec.tsx',
'**/*.test.tsx',
'**/*.test.ts',
'**/test/**/*.ts',
],
rules: {
...common.testRules,
...extraTsRules,
Expand Down
3 changes: 1 addition & 2 deletions configs/eslint-config-compass/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ module.exports = {
restrictedProviderImport('mongodb-data-service'),
restrictedProviderImport('@mongodb-js/compass-logging'),
restrictedProviderImport('@mongodb-js/compass-app-stores'),
// TODO(COMPASS-7411): enable when possible
// restrictedProviderImport('@mongodb-js/my-queries-storage'),
restrictedProviderImport('@mongodb-js/my-queries-storage'),
// TODO(COMPASS-7412): enable when possible
// restrictedProviderImport('@mongodb-js/atlas-service'),
restrictedProviderImport('compass-preferences-model'),
Expand Down
9 changes: 9 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions packages/compass-aggregations/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type {
import { mongoDBInstanceLocator } from '@mongodb-js/compass-app-stores/provider';
import { workspacesServiceLocator } from '@mongodb-js/compass-workspaces/provider';
import { preferencesLocator } from 'compass-preferences-model/provider';
import { pipelineStorageLocator } from '@mongodb-js/my-queries-storage/provider';

export const CompassAggregationsHadronPlugin = registerHadronPlugin(
{
Expand All @@ -33,6 +34,7 @@ export const CompassAggregationsHadronPlugin = registerHadronPlugin(
instance: mongoDBInstanceLocator,
preferences: preferencesLocator,
logger: createLoggerAndTelemetryLocator('COMPASS-AGGREGATIONS-UI'),
pipelineStorage: pipelineStorageLocator,
}
);

Expand Down
2 changes: 1 addition & 1 deletion packages/compass-aggregations/src/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import workspace from './workspace';
import aggregationWorkspaceId from './aggregation-workspace-id';
import type { ThunkAction, ThunkDispatch } from 'redux-thunk';
import type { PipelineBuilder } from './pipeline-builder/pipeline-builder';
import type { PipelineStorage } from '@mongodb-js/my-queries-storage';
import type { PipelineStorage } from '@mongodb-js/my-queries-storage/provider';
import focusMode from './focus-mode';
import sidePanel from './side-panel';
import collectionsFields from './collections-fields';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from './stage-editor';
import type { StageEditorState, StoreStage, Wizard } from './stage-editor';
import reducer from '../';
import { PipelineStorage } from '@mongodb-js/my-queries-storage';
import { CompassPipelineStorage } from '@mongodb-js/my-queries-storage';
import Sinon from 'sinon';
import type Stage from './stage';
import { mockDataService } from '../../../test/mocks/data-service';
Expand Down Expand Up @@ -117,7 +117,7 @@ function createStore({
localAppRegistry: new AppRegistry(),
atlasService: new AtlasService(),
pipelineBuilder,
pipelineStorage: new PipelineStorage(),
pipelineStorage: new CompassPipelineStorage(),
instance: {} as any,
workspaces: {} as any,
preferences,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { PipelineBuilderThunkDispatch } from '..';
import reducer from '..';
import Sinon from 'sinon';
import { toggleAutoPreview } from '../auto-preview';
import { PipelineStorage } from '@mongodb-js/my-queries-storage';
import { CompassPipelineStorage } from '@mongodb-js/my-queries-storage';
import { mockDataService } from '../../../test/mocks/data-service';

function createStore(
Expand Down Expand Up @@ -47,7 +47,7 @@ function createStore(
thunk.withExtraArgument({
atlasService: new AtlasService(),
pipelineBuilder,
pipelineStorage: new PipelineStorage(),
pipelineStorage: new CompassPipelineStorage(),
instance: {} as any,
workspaces: {} as any,
preferences: {
Expand Down
10 changes: 3 additions & 7 deletions packages/compass-aggregations/src/stores/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { openStoredPipeline } from '../modules/saved-pipeline';
import { PipelineBuilder } from '../modules/pipeline-builder/pipeline-builder';
import { generateAggregationFromQuery } from '../modules/pipeline-builder/pipeline-ai';
import type { SavedPipeline } from '@mongodb-js/my-queries-storage';
import { PipelineStorage } from '@mongodb-js/my-queries-storage';
import {
mapBuilderStageToStoreStage,
mapStoreStagesToStageIdAndType,
Expand All @@ -36,6 +35,7 @@ import type { CollectionTabPluginMetadata } from '@mongodb-js/compass-collection
import type { PreferencesAccess } from 'compass-preferences-model';
import { preferencesMaxTimeMSChanged } from '../modules/max-time-ms';
import type { LoggerAndTelemetry } from '@mongodb-js/compass-logging/provider';
import type { PipelineStorage } from '@mongodb-js/my-queries-storage/provider';

export type ConfigureStoreOptions = CollectionTabPluginMetadata &
Partial<{
Expand All @@ -59,10 +59,6 @@ export type ConfigureStoreOptions = CollectionTabPluginMetadata &
* the stage wizard to populate the dropdown for $lookup use-case.
*/
collections: CollectionInfo[];
/**
* Storage service for saved aggregations
*/
pipelineStorage: PipelineStorage;
/**
* Service for interacting with Atlas-only features
*/
Expand All @@ -77,6 +73,7 @@ export type AggregationsPluginServices = {
instance: MongoDBInstance;
preferences: PreferencesAccess;
logger: LoggerAndTelemetry;
pipelineStorage: PipelineStorage;
};

export function activateAggregationsPlugin(
Expand All @@ -89,6 +86,7 @@ export function activateAggregationsPlugin(
instance,
preferences,
logger,
pipelineStorage,
}: AggregationsPluginServices,
{ on, cleanup, addCleanup }: ActivateHelpers
) {
Expand Down Expand Up @@ -118,8 +116,6 @@ export function activateAggregationsPlugin(

const atlasService = options.atlasService ?? new AtlasService();

const pipelineStorage = options.pipelineStorage ?? new PipelineStorage();

const stages = pipelineBuilder.stages.map((stage, idx) =>
mapBuilderStageToStoreStage(stage, idx)
);
Expand Down
3 changes: 3 additions & 0 deletions packages/compass-aggregations/test/configure-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import type { DataService } from '../src/modules/data-service';
import { ReadOnlyPreferenceAccess } from 'compass-preferences-model/provider';
import { createNoopLoggerAndTelemetry } from '@mongodb-js/compass-logging/provider';

import { CompassPipelineStorage } from '@mongodb-js/my-queries-storage';

export default function configureStore(
options: Partial<ConfigureStoreOptions> = {},
dataService: DataService = mockDataService(),
Expand All @@ -35,6 +37,7 @@ export default function configureStore(
localAppRegistry: new AppRegistry(),
workspaces: {} as any,
logger: createNoopLoggerAndTelemetry(),
pipelineStorage: new CompassPipelineStorage(),
...services,
},
createActivateHelpers()
Expand Down
6 changes: 6 additions & 0 deletions packages/compass-crud/src/components/crud-toolbar.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import { createSandboxFromDefaultPreferences } from 'compass-preferences-model';
import { CrudToolbar } from './crud-toolbar';
import { PreferencesProvider } from 'compass-preferences-model/provider';
import QueryBarPlugin from '@mongodb-js/compass-query-bar';
import {
compassFavoriteQueryStorageAccess,
compassRecentQueryStorageAccess,
} from '@mongodb-js/my-queries-storage';

const noop = () => {
/* noop */
Expand All @@ -33,6 +37,8 @@ const MockQueryBarPlugin = QueryBarPlugin.withMockServices({
},
},
instance: { on() {}, removeListener() {} } as any,
favoriteQueryStorageAccess: compassFavoriteQueryStorageAccess,
recentQueryStorageAccess: compassRecentQueryStorageAccess,
});

const addDataText = 'Add Data';
Expand Down
6 changes: 6 additions & 0 deletions packages/compass-crud/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import { mongoDBInstanceLocator } from '@mongodb-js/compass-app-stores/provider'
import { registerHadronPlugin } from 'hadron-app-registry';
import { preferencesLocator } from 'compass-preferences-model/provider';
import { createLoggerAndTelemetryLocator } from '@mongodb-js/compass-logging/provider';
import {
favoriteQueryStorageAccessLocator,
recentQueryStorageAccessLocator,
} from '@mongodb-js/my-queries-storage/provider';

export const CompassDocumentsHadronPlugin = registerHadronPlugin(
{
Expand All @@ -32,6 +36,8 @@ export const CompassDocumentsHadronPlugin = registerHadronPlugin(
instance: mongoDBInstanceLocator,
preferences: preferencesLocator,
logger: createLoggerAndTelemetryLocator('COMPASS-CRUD-UI'),
favoriteQueryStorageAccess: favoriteQueryStorageAccessLocator,
recentQueryStorageAccess: recentQueryStorageAccessLocator,
}
);

Expand Down
Loading

0 comments on commit 20a6ff8

Please sign in to comment.