From cd812088348f3417c50995507554a60e03cf6ef2 Mon Sep 17 00:00:00 2001 From: Himanshu Singh Date: Mon, 6 May 2024 14:38:23 +0200 Subject: [PATCH 01/10] chore: remove unnecessary state from open-item reducer --- .../src/stores/open-item.ts | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/packages/compass-saved-aggregations-queries/src/stores/open-item.ts b/packages/compass-saved-aggregations-queries/src/stores/open-item.ts index ead693e9c6f..28de3aa8545 100644 --- a/packages/compass-saved-aggregations-queries/src/stores/open-item.ts +++ b/packages/compass-saved-aggregations-queries/src/stores/open-item.ts @@ -7,7 +7,6 @@ export type Status = 'initial' | 'fetching' | 'error' | 'ready'; export type State = { isModalOpen: boolean; selectedItem: Item | null; - createCollectionStatus: Status; databases: string[]; selectedDatabase: string | null; databasesStatus: Status; @@ -20,7 +19,6 @@ export type State = { const INITIAL_STATE: State = { isModalOpen: false, selectedItem: null, - createCollectionStatus: 'initial', databases: [], selectedDatabase: null, databasesStatus: 'initial', @@ -33,7 +31,6 @@ const INITIAL_STATE: State = { export enum ActionTypes { OpenModal = 'compass-saved-aggregations-queries/openModal', CloseModal = 'compass-saved-aggregations-queries/closeModal', - CreateNamespaceStatusChange = 'compass-saved-aggregations-queries/createNamespaceStatusChange', SelectDatabase = 'compass-saved-aggregations-queries/selectDatabase', LoadDatabases = 'compass-saved-aggregations-queries/loadDatabases', LoadDatabasesSuccess = 'compass-saved-aggregations-queries/loadDatabasesSuccess', @@ -54,11 +51,6 @@ type CloseModalAction = { type: ActionTypes.CloseModal; }; -type CreateNamespaceStatusChangeAction = { - type: ActionTypes.CreateNamespaceStatusChange; - status: Status; -}; - type SelectDatabaseAction = { type: ActionTypes.SelectDatabase; database: string; @@ -103,7 +95,6 @@ type UpdateNamespaceChecked = { export type Actions = | OpenModalAction | CloseModalAction - | CreateNamespaceStatusChangeAction | SelectDatabaseAction | LoadDatabasesAction | LoadDatabasesErrorAction @@ -124,11 +115,6 @@ const reducer: Reducer = (state = INITIAL_STATE, action) => { }; case ActionTypes.CloseModal: return { ...INITIAL_STATE }; - case ActionTypes.CreateNamespaceStatusChange: - return { - ...state, - createCollectionStatus: action.status, - }; case ActionTypes.SelectDatabase: return { ...state, From 4055889be193a55228e48f135c8936c8df3987d3 Mon Sep 17 00:00:00 2001 From: Himanshu Singh Date: Mon, 6 May 2024 15:37:20 +0200 Subject: [PATCH 02/10] chore: use isAction helper --- .../src/stores/open-item.ts | 176 +++++++++++------- 1 file changed, 112 insertions(+), 64 deletions(-) diff --git a/packages/compass-saved-aggregations-queries/src/stores/open-item.ts b/packages/compass-saved-aggregations-queries/src/stores/open-item.ts index 28de3aa8545..70f4fe20177 100644 --- a/packages/compass-saved-aggregations-queries/src/stores/open-item.ts +++ b/packages/compass-saved-aggregations-queries/src/stores/open-item.ts @@ -1,7 +1,14 @@ -import type { ActionCreator, Reducer } from 'redux'; +import type { ActionCreator, AnyAction, Reducer } from 'redux'; import type { SavedQueryAggregationThunkAction } from '.'; import type { Item } from './aggregations-queries-items'; +function isAction( + action: AnyAction, + type: A['type'] +): action is A { + return action.type === type; +} + export type Status = 'initial' | 'fetching' | 'error' | 'ready'; export type State = { @@ -87,7 +94,7 @@ type LoadCollectionsErrorAction = { type: ActionTypes.LoadCollectionsError; }; -type UpdateNamespaceChecked = { +type UpdateNamespaceCheckedAction = { type: ActionTypes.UpdateNamespaceChecked; updateItemNamespace: boolean; }; @@ -103,71 +110,112 @@ export type Actions = | LoadCollectionsAction | LoadCollectionsErrorAction | LoadCollectionsSuccessAction - | UpdateNamespaceChecked; + | UpdateNamespaceCheckedAction; const reducer: Reducer = (state = INITIAL_STATE, action) => { - switch (action.type) { - case ActionTypes.OpenModal: - return { - ...state, - selectedItem: action.selectedItem, - isModalOpen: true, - }; - case ActionTypes.CloseModal: - return { ...INITIAL_STATE }; - case ActionTypes.SelectDatabase: - return { - ...state, - selectedDatabase: action.database, - collections: [], - collectionsStatus: 'initial', - selectedCollection: null, - }; - case ActionTypes.LoadDatabases: - return { - ...state, - databasesStatus: 'fetching', - }; - case ActionTypes.LoadDatabasesError: - return { - ...state, - databasesStatus: 'error', - }; - case ActionTypes.LoadDatabasesSuccess: - return { - ...state, - databases: action.databases, - databasesStatus: 'ready', - }; - case ActionTypes.SelectCollection: - return { - ...state, - selectedCollection: action.collection, - }; - case ActionTypes.LoadCollections: - return { - ...state, - collectionsStatus: 'fetching', - }; - case ActionTypes.LoadCollectionsError: - return { - ...state, - collectionsStatus: 'error', - }; - case ActionTypes.LoadCollectionsSuccess: - return { - ...state, - collections: action.collections, - collectionsStatus: 'ready', - }; - case ActionTypes.UpdateNamespaceChecked: - return { - ...state, - updateItemNamespace: action.updateItemNamespace, - }; - default: - return state; + if (isAction(action, ActionTypes.OpenModal)) { + return { + ...state, + selectedItem: action.selectedItem, + isModalOpen: true, + }; + } + + if (isAction(action, ActionTypes.CloseModal)) { + return { ...INITIAL_STATE }; + } + + if (isAction(action, ActionTypes.SelectDatabase)) { + return { + ...state, + selectedDatabase: action.database, + collections: [], + collectionsStatus: 'initial', + selectedCollection: null, + }; + } + + if (isAction(action, ActionTypes.LoadDatabases)) { + return { + ...state, + databasesStatus: 'fetching', + }; + } + + if ( + isAction(action, ActionTypes.LoadDatabasesError) + ) { + return { + ...state, + databasesStatus: 'error', + }; + } + + if ( + isAction( + action, + ActionTypes.LoadDatabasesSuccess + ) + ) { + return { + ...state, + databases: action.databases, + databasesStatus: 'ready', + }; } + + if (isAction(action, ActionTypes.SelectCollection)) { + return { + ...state, + selectedCollection: action.collection, + }; + } + + if (isAction(action, ActionTypes.LoadCollections)) { + return { + ...state, + collectionsStatus: 'fetching', + }; + } + + if ( + isAction( + action, + ActionTypes.LoadCollectionsError + ) + ) { + return { + ...state, + collectionsStatus: 'error', + }; + } + + if ( + isAction( + action, + ActionTypes.LoadCollectionsSuccess + ) + ) { + return { + ...state, + collections: action.collections, + collectionsStatus: 'ready', + }; + } + + if ( + isAction( + action, + ActionTypes.UpdateNamespaceChecked + ) + ) { + return { + ...state, + updateItemNamespace: action.updateItemNamespace, + }; + } + + return state; }; export const updateItemNamespaceChecked = (updateItemNamespace: boolean) => ({ From de275f44b2f1cc1938fcde7743a8fdb7ba0eff96 Mon Sep 17 00:00:00 2001 From: Himanshu Singh Date: Mon, 6 May 2024 15:48:33 +0200 Subject: [PATCH 03/10] chore: new actions to reduce connection state as well --- .../src/stores/open-item.ts | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/packages/compass-saved-aggregations-queries/src/stores/open-item.ts b/packages/compass-saved-aggregations-queries/src/stores/open-item.ts index 70f4fe20177..38292c51f72 100644 --- a/packages/compass-saved-aggregations-queries/src/stores/open-item.ts +++ b/packages/compass-saved-aggregations-queries/src/stores/open-item.ts @@ -14,6 +14,8 @@ export type Status = 'initial' | 'fetching' | 'error' | 'ready'; export type State = { isModalOpen: boolean; selectedItem: Item | null; + activeConnections: string[]; + selectedConnection: string | null; databases: string[]; selectedDatabase: string | null; databasesStatus: Status; @@ -26,6 +28,8 @@ export type State = { const INITIAL_STATE: State = { isModalOpen: false, selectedItem: null, + activeConnections: [], + selectedConnection: null, databases: [], selectedDatabase: null, databasesStatus: 'initial', @@ -38,6 +42,9 @@ const INITIAL_STATE: State = { export enum ActionTypes { OpenModal = 'compass-saved-aggregations-queries/openModal', CloseModal = 'compass-saved-aggregations-queries/closeModal', + ConnectionConnected = 'compass-saved-aggregations-queries/connectionConnected', + ConnectionDisconnected = 'compass-saved-aggregations-queries/connectionDisconnected', + ConnectionSelected = 'compass-saved-aggregations-queries/connectionSelected', SelectDatabase = 'compass-saved-aggregations-queries/selectDatabase', LoadDatabases = 'compass-saved-aggregations-queries/loadDatabases', LoadDatabasesSuccess = 'compass-saved-aggregations-queries/loadDatabasesSuccess', @@ -58,6 +65,21 @@ type CloseModalAction = { type: ActionTypes.CloseModal; }; +type ConnectionConnectedAction = { + type: ActionTypes.ConnectionConnected; + connection: string; +}; + +type ConnectionDisconnectedAction = { + type: ActionTypes.ConnectionDisconnected; + connection: string; +}; + +type ConnectionSelectedAction = { + type: ActionTypes.ConnectionSelected; + connection: string; +}; + type SelectDatabaseAction = { type: ActionTypes.SelectDatabase; database: string; @@ -102,6 +124,9 @@ type UpdateNamespaceCheckedAction = { export type Actions = | OpenModalAction | CloseModalAction + | ConnectionConnectedAction + | ConnectionDisconnectedAction + | ConnectionSelectedAction | SelectDatabaseAction | LoadDatabasesAction | LoadDatabasesErrorAction @@ -125,6 +150,48 @@ const reducer: Reducer = (state = INITIAL_STATE, action) => { return { ...INITIAL_STATE }; } + if ( + isAction(action, ActionTypes.ConnectionConnected) + ) { + const activeConnections = new Set(state.activeConnections); + activeConnections.add(action.connection); + + return { + ...state, + activeConnections: Array.from(activeConnections), + }; + } + + if ( + isAction( + action, + ActionTypes.ConnectionDisconnected + ) + ) { + const activeConnections = new Set(state.activeConnections); + activeConnections.delete(action.connection); + + return { + ...state, + activeConnections: Array.from(activeConnections), + }; + } + + if ( + isAction(action, ActionTypes.ConnectionSelected) + ) { + return { + ...state, + selectedConnection: action.connection, + selectedDatabase: null, + databases: [], + databasesStatus: 'initial', + collections: [], + collectionsStatus: 'initial', + selectedCollection: null, + }; + } + if (isAction(action, ActionTypes.SelectDatabase)) { return { ...state, From e4d1ffecab2942c8a73910e390a250c80405b718 Mon Sep 17 00:00:00 2001 From: Himanshu Singh Date: Wed, 8 May 2024 11:46:21 +0200 Subject: [PATCH 04/10] chore: action creators for new connection related actions --- .../src/stores/open-item.ts | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/packages/compass-saved-aggregations-queries/src/stores/open-item.ts b/packages/compass-saved-aggregations-queries/src/stores/open-item.ts index 38292c51f72..e87f2e26cfb 100644 --- a/packages/compass-saved-aggregations-queries/src/stores/open-item.ts +++ b/packages/compass-saved-aggregations-queries/src/stores/open-item.ts @@ -285,6 +285,27 @@ const reducer: Reducer = (state = INITIAL_STATE, action) => { return state; }; +export const connectionConnected = ( + connection: string +): ConnectionConnectedAction => ({ + type: ActionTypes.ConnectionConnected, + connection, +}); + +export const connectionDisconnected = ( + connection: string +): ConnectionDisconnectedAction => ({ + type: ActionTypes.ConnectionDisconnected, + connection, +}); + +export const connectionSelected = ( + connection: string +): ConnectionSelectedAction => ({ + type: ActionTypes.ConnectionSelected, + connection, +}); + export const updateItemNamespaceChecked = (updateItemNamespace: boolean) => ({ type: ActionTypes.UpdateNamespaceChecked, updateItemNamespace, @@ -380,15 +401,6 @@ export const openSavedItem = dispatch(openItem(item, database, collection)); }; -export const updateNamespaceChecked = - (updateNamespaceChecked: boolean): SavedQueryAggregationThunkAction => - (dispatch) => { - dispatch({ - type: ActionTypes.UpdateNamespaceChecked, - updateNamespaceChecked, - }); - }; - export const openSelectedItem = (): SavedQueryAggregationThunkAction> => async (dispatch, getState, { queryStorage, pipelineStorage }) => { From 0af9f547aedc42ba30ba7c2193d537ff0805f16a Mon Sep 17 00:00:00 2001 From: Himanshu Singh Date: Wed, 8 May 2024 13:41:39 +0200 Subject: [PATCH 05/10] chore: openItem slice modified to work with multiple connections --- package-lock.json | 2 + .../package.json | 1 + .../src/index.spec.tsx | 46 ++++- .../src/index.ts | 16 +- .../src/stores/index.ts | 53 +++-- .../src/stores/open-item.ts | 184 +++++++++++++----- 6 files changed, 221 insertions(+), 81 deletions(-) diff --git a/package-lock.json b/package-lock.json index c00a0c2813e..b3a41acb2e0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -46199,6 +46199,7 @@ "@mongodb-js/compass-workspaces": "^0.8.0", "@mongodb-js/my-queries-storage": "^0.8.0", "bson": "^6.6.0", + "compass-preferences-model": "^2.20.0", "fuse.js": "^6.5.3", "hadron-app-registry": "^9.1.11", "mongodb-ns": "^2.4.0", @@ -56867,6 +56868,7 @@ "@types/sinon-chai": "^3.2.5", "bson": "^6.6.0", "chai": "^4.3.4", + "compass-preferences-model": "^2.20.0", "depcheck": "^1.4.1", "electron-mocha": "^12.2.0", "eslint": "^7.25.0", diff --git a/packages/compass-saved-aggregations-queries/package.json b/packages/compass-saved-aggregations-queries/package.json index 73092844413..9e7b410c81e 100644 --- a/packages/compass-saved-aggregations-queries/package.json +++ b/packages/compass-saved-aggregations-queries/package.json @@ -55,6 +55,7 @@ "@mongodb-js/compass-workspaces": "^0.8.0", "@mongodb-js/my-queries-storage": "^0.8.0", "bson": "^6.6.0", + "compass-preferences-model": "^2.20.0", "fuse.js": "^6.5.3", "hadron-app-registry": "^9.1.11", "mongodb-ns": "^2.4.0", diff --git a/packages/compass-saved-aggregations-queries/src/index.spec.tsx b/packages/compass-saved-aggregations-queries/src/index.spec.tsx index a66bed677d1..48c05008cc4 100644 --- a/packages/compass-saved-aggregations-queries/src/index.spec.tsx +++ b/packages/compass-saved-aggregations-queries/src/index.spec.tsx @@ -15,6 +15,10 @@ import type { PipelineStorage, FavoriteQueryStorage, } from '@mongodb-js/my-queries-storage/provider'; +import { ConnectionsManager } from '@mongodb-js/compass-connections/provider'; +import { createNoopLoggerAndTelemetry } from '@mongodb-js/compass-logging/provider'; +import { TestMongoDBInstanceManager } from '@mongodb-js/compass-app-stores/provider'; +import type { PreferencesAccess } from 'compass-preferences-model/provider'; describe('AggregationsQueriesList', function () { const sandbox = Sinon.createSandbox(); @@ -29,19 +33,43 @@ describe('AggregationsQueriesList', function () { updateAttributes: sandbox.stub().resolves({}), }; - const Plugin = MyQueriesPlugin.withMockServices({ - dataService, - instance, - favoriteQueryStorageAccess: { - getStorage() { - return queryStorage as unknown as FavoriteQueryStorage; - }, + const connectionsManager = new ConnectionsManager({ + logger: createNoopLoggerAndTelemetry().log.unbound, + }); + + const instancesManager = new TestMongoDBInstanceManager(); + + const preferencesAccess = { + getPreferences() { + return { + enableNewMultipleConnectionSystem: false, + }; }, - pipelineStorage: pipelineStorage as unknown as PipelineStorage, + } as PreferencesAccess; + let Plugin: any; + + beforeEach(function () { + sandbox + .stub(connectionsManager, 'getDataServiceForConnection') + .returns(dataService); + sandbox + .stub(instancesManager, 'getMongoDBInstanceForConnection') + .returns(instance); + Plugin = MyQueriesPlugin.withMockServices({ + connectionsManager, + instancesManager, + preferencesAccess, + favoriteQueryStorageAccess: { + getStorage() { + return queryStorage as unknown as FavoriteQueryStorage; + }, + }, + pipelineStorage: pipelineStorage as unknown as PipelineStorage, + }); }); afterEach(function () { - sandbox.resetHistory(); + sandbox.restore(); cleanup(); }); diff --git a/packages/compass-saved-aggregations-queries/src/index.ts b/packages/compass-saved-aggregations-queries/src/index.ts index cfc1defff5d..73850d0b559 100644 --- a/packages/compass-saved-aggregations-queries/src/index.ts +++ b/packages/compass-saved-aggregations-queries/src/index.ts @@ -1,11 +1,9 @@ import { registerHadronPlugin } from 'hadron-app-registry'; import { connectionInfoAccessLocator, - dataServiceLocator, - type DataService, - type DataServiceLocator, + connectionsManagerLocator, } from '@mongodb-js/compass-connections/provider'; -import { mongoDBInstanceLocator } from '@mongodb-js/compass-app-stores/provider'; +import { mongoDBInstancesManagerLocator } from '@mongodb-js/compass-app-stores/provider'; import { createLoggerAndTelemetryLocator } from '@mongodb-js/compass-logging/provider'; import { activatePlugin } from './stores'; import AggregationsQueriesList from './components/aggregations-queries-list'; @@ -15,14 +13,12 @@ import { pipelineStorageLocator, favoriteQueryStorageAccessLocator, } from '@mongodb-js/my-queries-storage/provider'; +import { preferencesLocator } from 'compass-preferences-model/provider'; const serviceLocators = { - dataService: dataServiceLocator as DataServiceLocator< - // Getting passed to the mongodb instance so hard to be more explicit - // about used methods - keyof DataService - >, - instance: mongoDBInstanceLocator, + connectionsManager: connectionsManagerLocator, + instancesManager: mongoDBInstancesManagerLocator, + preferencesAccess: preferencesLocator, logger: createLoggerAndTelemetryLocator('COMPASS-MY-QUERIES-UI'), workspaces: workspacesServiceLocator, pipelineStorage: pipelineStorageLocator, diff --git a/packages/compass-saved-aggregations-queries/src/stores/index.ts b/packages/compass-saved-aggregations-queries/src/stores/index.ts index 5de08c2e54b..70fa79827b4 100644 --- a/packages/compass-saved-aggregations-queries/src/stores/index.ts +++ b/packages/compass-saved-aggregations-queries/src/stores/index.ts @@ -4,13 +4,17 @@ import type { AnyAction, Action } from 'redux'; import thunk from 'redux-thunk'; import type { ThunkAction } from 'redux-thunk'; import itemsReducer from './aggregations-queries-items'; -import openItemReducer from './open-item'; +import openItemReducer, { + connectionConnected, + connectionDisconnected, +} from './open-item'; import editItemReducer from './edit-item'; -import type { - ConnectionInfoAccess, - DataService, +import { + ConnectionsManagerEvents, + type ConnectionInfoAccess, + type ConnectionsManager, } from '@mongodb-js/compass-connections/provider'; -import type { MongoDBInstance } from '@mongodb-js/compass-app-stores/provider'; +import type { MongoDBInstancesManager } from '@mongodb-js/compass-app-stores/provider'; import type { LoggerAndTelemetry } from '@mongodb-js/compass-logging/provider'; import type { workspacesServiceLocator } from '@mongodb-js/compass-workspaces/provider'; import type { @@ -18,10 +22,13 @@ import type { PipelineStorage, FavoriteQueryStorage, } from '@mongodb-js/my-queries-storage/provider'; +import type { ActivateHelpers } from 'hadron-app-registry'; +import type { PreferencesAccess } from 'compass-preferences-model'; type MyQueriesServices = { - dataService: DataService; - instance: MongoDBInstance; + connectionsManager: ConnectionsManager; + instancesManager: MongoDBInstancesManager; + preferencesAccess: PreferencesAccess; globalAppRegistry: AppRegistry; logger: LoggerAndTelemetry; pipelineStorage?: PipelineStorage; @@ -32,8 +39,9 @@ type MyQueriesServices = { export function configureStore({ globalAppRegistry, - dataService, - instance, + connectionsManager, + instancesManager, + preferencesAccess, logger, workspaces, pipelineStorage, @@ -49,8 +57,9 @@ export function configureStore({ applyMiddleware( thunk.withExtraArgument({ globalAppRegistry, - dataService, - instance, + connectionsManager, + instancesManager, + preferencesAccess, logger, pipelineStorage, queryStorage: favoriteQueryStorageAccess?.getStorage(), @@ -79,13 +88,27 @@ export type SavedQueryAggregationThunkAction< export function activatePlugin( _: Record, - services: MyQueriesServices + services: MyQueriesServices, + { on, cleanup }: ActivateHelpers ) { const store = configureStore(services); + on( + services.connectionsManager, + ConnectionsManagerEvents.ConnectionAttemptSuccessful, + function (connection: string) { + store.dispatch(connectionConnected(connection)); + } + ); + + on( + services.connectionsManager, + ConnectionsManagerEvents.ConnectionDisconnected, + function (connection: string) { + store.dispatch(connectionDisconnected(connection)); + } + ); return { store, - deactivate() { - // noop, no subscriptions in this plugin - }, + deactivate: cleanup, }; } diff --git a/packages/compass-saved-aggregations-queries/src/stores/open-item.ts b/packages/compass-saved-aggregations-queries/src/stores/open-item.ts index e87f2e26cfb..6fb5603f747 100644 --- a/packages/compass-saved-aggregations-queries/src/stores/open-item.ts +++ b/packages/compass-saved-aggregations-queries/src/stores/open-item.ts @@ -1,6 +1,8 @@ import type { ActionCreator, AnyAction, Reducer } from 'redux'; import type { SavedQueryAggregationThunkAction } from '.'; import type { Item } from './aggregations-queries-items'; +import type { DataService } from '@mongodb-js/compass-connections/provider'; +import type { MongoDBInstance } from '@mongodb-js/compass-app-stores/provider'; function isAction( action: AnyAction, @@ -299,26 +301,71 @@ export const connectionDisconnected = ( connection, }); -export const connectionSelected = ( - connection: string -): ConnectionSelectedAction => ({ - type: ActionTypes.ConnectionSelected, - connection, -}); +const getDataServiceAndInstanceForConnection = + ( + connection: string | null + ): SavedQueryAggregationThunkAction< + | { + dataService?: never; + instance?: never; + error: Error; + } + | { + dataService: DataService; + instance: MongoDBInstance; + error?: never; + } + > => + (_dispatch, _getState, { connectionsManager, instancesManager }) => { + if (!connection) { + return { + error: new Error('Connection not provided'), + }; + } -export const updateItemNamespaceChecked = (updateItemNamespace: boolean) => ({ - type: ActionTypes.UpdateNamespaceChecked, - updateItemNamespace, -}); + const dataService = + connectionsManager.getDataServiceForConnection(connection); + if (!dataService) { + return { + error: new Error( + `DataService for connection - ${connection} not found` + ), + }; + } + + const instance = + instancesManager.getMongoDBInstanceForConnection(connection); + if (!instance) { + return { + error: new Error(`Instance for connection - ${connection} not found`), + }; + } -const openModal = - (selectedItem: Item): SavedQueryAggregationThunkAction> => - async (dispatch, _getState, { instance, dataService }) => { - dispatch({ type: ActionTypes.OpenModal, selectedItem }); + return { + dataService, + instance, + }; + }; - dispatch({ type: ActionTypes.LoadDatabases }); +export const connectionSelected = + ( + selectedConnection: string + ): SavedQueryAggregationThunkAction> => + async (dispatch) => { + dispatch({ + type: ActionTypes.ConnectionSelected, + connection: selectedConnection, + }); + dispatch({ type: ActionTypes.LoadDatabases }); try { + const { error, instance, dataService } = dispatch( + getDataServiceAndInstanceForConnection(selectedConnection) + ); + if (error) { + throw error; + } + await instance.fetchDatabases({ dataService }); dispatch({ type: ActionTypes.LoadDatabasesSuccess, @@ -329,21 +376,28 @@ const openModal = } }; -export const closeModal: ActionCreator = () => { - return { type: ActionTypes.CloseModal }; -}; +export const updateItemNamespaceChecked = (updateItemNamespace: boolean) => ({ + type: ActionTypes.UpdateNamespaceChecked, + updateItemNamespace, +}); + +const openModal = (selectedItem: Item): OpenModalAction => ({ + type: ActionTypes.OpenModal, + selectedItem, +}); + +export const closeModal = (): CloseModalAction => ({ + type: ActionTypes.CloseModal, +}); const openItem = ( item: Item, + connection: string, database: string, collection: string ): SavedQueryAggregationThunkAction => - ( - _dispatch, - _getState, - { logger: { track }, workspaces, connectionInfoAccess } - ) => { + (_dispatch, _getState, { logger: { track }, workspaces }) => { track( item.type === 'aggregation' ? 'Aggregation Opened' @@ -354,11 +408,8 @@ const openItem = } ); - const { id: connectionId } = - connectionInfoAccess.getCurrentConnectionInfo(); - workspaces.openCollectionWorkspace( - connectionId, + connection, `${database}.${collection}`, { initialAggregation: @@ -374,7 +425,7 @@ const openItem = export const openSavedItem = (id: string): SavedQueryAggregationThunkAction> => - async (dispatch, getState, { instance, dataService }) => { + async (dispatch, getState, { preferencesAccess, connectionInfoAccess }) => { const { savedItems: { items }, } = getState(); @@ -386,19 +437,38 @@ export const openSavedItem = } const { database, collection } = item; + const multiConnectionsEnabled = + preferencesAccess.getPreferences().enableNewMultipleConnectionSystem; + + if (!multiConnectionsEnabled) { + const { id: singleConnectionId } = + connectionInfoAccess.getCurrentConnectionInfo(); + const { error, dataService, instance } = dispatch( + getDataServiceAndInstanceForConnection(singleConnectionId) + ); + if (error) { + return; + } - const coll = await instance.getNamespace({ - dataService, - database, - collection, - }); + const coll = await instance.getNamespace({ + dataService, + database, + collection, + }); - if (!coll) { - void dispatch(openModal(item)); - return; - } + if (!coll) { + // There is no way for users to select a connection in single + // connections world but to keep the parity with the state we dispatch + // this selection explicitly + void dispatch(connectionSelected(singleConnectionId)); + dispatch(openModal(item)); + return; + } - dispatch(openItem(item, database, collection)); + dispatch(openItem(item, singleConnectionId, database, collection)); + } else { + // TODO: COMPASS-7904 + } }; export const openSelectedItem = @@ -407,13 +477,19 @@ export const openSelectedItem = const { openItem: { selectedItem, + selectedConnection, selectedDatabase, selectedCollection, updateItemNamespace, }, } = getState(); - if (!selectedItem || !selectedDatabase || !selectedCollection) { + if ( + !selectedItem || + !selectedConnection || + !selectedDatabase || + !selectedCollection + ) { return; } @@ -431,14 +507,21 @@ export const openSelectedItem = } dispatch({ type: ActionTypes.CloseModal }); - dispatch(openItem(selectedItem, selectedDatabase, selectedCollection)); + dispatch( + openItem( + selectedItem, + selectedConnection, + selectedDatabase, + selectedCollection + ) + ); }; export const selectDatabase = (database: string): SavedQueryAggregationThunkAction> => - async (dispatch, getState, { instance, dataService }) => { + async (dispatch, getState) => { const { - openItem: { selectedDatabase }, + openItem: { selectedDatabase, selectedConnection }, } = getState(); if (database === selectedDatabase) { @@ -447,13 +530,20 @@ export const selectDatabase = dispatch({ type: ActionTypes.SelectDatabase, database }); - const db = instance.databases.get(database); + dispatch({ type: ActionTypes.LoadCollections }); + try { + const { error, instance, dataService } = dispatch( + getDataServiceAndInstanceForConnection(selectedConnection) + ); + if (error) { + throw error; + } - if (!db) { - return; - } + const db = instance.databases.get(database); + if (!db) { + throw new Error('Database not found'); + } - try { await db.fetchCollections({ dataService }); // Check with the the current value in case db was re-selected while we // were fetching From 11283b330fa22dc35d7b98d28d41af596062946c Mon Sep 17 00:00:00 2001 From: Himanshu Singh Date: Mon, 13 May 2024 12:37:30 +0200 Subject: [PATCH 06/10] chore: removed activeConnections state from store --- .../src/stores/index.ts | 29 ++-------- .../src/stores/open-item.ts | 57 ------------------- 2 files changed, 5 insertions(+), 81 deletions(-) diff --git a/packages/compass-saved-aggregations-queries/src/stores/index.ts b/packages/compass-saved-aggregations-queries/src/stores/index.ts index 70fa79827b4..1b231b2b082 100644 --- a/packages/compass-saved-aggregations-queries/src/stores/index.ts +++ b/packages/compass-saved-aggregations-queries/src/stores/index.ts @@ -4,13 +4,9 @@ import type { AnyAction, Action } from 'redux'; import thunk from 'redux-thunk'; import type { ThunkAction } from 'redux-thunk'; import itemsReducer from './aggregations-queries-items'; -import openItemReducer, { - connectionConnected, - connectionDisconnected, -} from './open-item'; +import openItemReducer from './open-item'; import editItemReducer from './edit-item'; import { - ConnectionsManagerEvents, type ConnectionInfoAccess, type ConnectionsManager, } from '@mongodb-js/compass-connections/provider'; @@ -22,7 +18,6 @@ import type { PipelineStorage, FavoriteQueryStorage, } from '@mongodb-js/my-queries-storage/provider'; -import type { ActivateHelpers } from 'hadron-app-registry'; import type { PreferencesAccess } from 'compass-preferences-model'; type MyQueriesServices = { @@ -88,27 +83,13 @@ export type SavedQueryAggregationThunkAction< export function activatePlugin( _: Record, - services: MyQueriesServices, - { on, cleanup }: ActivateHelpers + services: MyQueriesServices ) { const store = configureStore(services); - on( - services.connectionsManager, - ConnectionsManagerEvents.ConnectionAttemptSuccessful, - function (connection: string) { - store.dispatch(connectionConnected(connection)); - } - ); - - on( - services.connectionsManager, - ConnectionsManagerEvents.ConnectionDisconnected, - function (connection: string) { - store.dispatch(connectionDisconnected(connection)); - } - ); return { store, - deactivate: cleanup, + deactivate: () => { + // noop, no subscriptions in this plugin + }, }; } diff --git a/packages/compass-saved-aggregations-queries/src/stores/open-item.ts b/packages/compass-saved-aggregations-queries/src/stores/open-item.ts index 6fb5603f747..853c1df2929 100644 --- a/packages/compass-saved-aggregations-queries/src/stores/open-item.ts +++ b/packages/compass-saved-aggregations-queries/src/stores/open-item.ts @@ -16,7 +16,6 @@ export type Status = 'initial' | 'fetching' | 'error' | 'ready'; export type State = { isModalOpen: boolean; selectedItem: Item | null; - activeConnections: string[]; selectedConnection: string | null; databases: string[]; selectedDatabase: string | null; @@ -30,7 +29,6 @@ export type State = { const INITIAL_STATE: State = { isModalOpen: false, selectedItem: null, - activeConnections: [], selectedConnection: null, databases: [], selectedDatabase: null, @@ -44,8 +42,6 @@ const INITIAL_STATE: State = { export enum ActionTypes { OpenModal = 'compass-saved-aggregations-queries/openModal', CloseModal = 'compass-saved-aggregations-queries/closeModal', - ConnectionConnected = 'compass-saved-aggregations-queries/connectionConnected', - ConnectionDisconnected = 'compass-saved-aggregations-queries/connectionDisconnected', ConnectionSelected = 'compass-saved-aggregations-queries/connectionSelected', SelectDatabase = 'compass-saved-aggregations-queries/selectDatabase', LoadDatabases = 'compass-saved-aggregations-queries/loadDatabases', @@ -67,16 +63,6 @@ type CloseModalAction = { type: ActionTypes.CloseModal; }; -type ConnectionConnectedAction = { - type: ActionTypes.ConnectionConnected; - connection: string; -}; - -type ConnectionDisconnectedAction = { - type: ActionTypes.ConnectionDisconnected; - connection: string; -}; - type ConnectionSelectedAction = { type: ActionTypes.ConnectionSelected; connection: string; @@ -126,8 +112,6 @@ type UpdateNamespaceCheckedAction = { export type Actions = | OpenModalAction | CloseModalAction - | ConnectionConnectedAction - | ConnectionDisconnectedAction | ConnectionSelectedAction | SelectDatabaseAction | LoadDatabasesAction @@ -152,33 +136,6 @@ const reducer: Reducer = (state = INITIAL_STATE, action) => { return { ...INITIAL_STATE }; } - if ( - isAction(action, ActionTypes.ConnectionConnected) - ) { - const activeConnections = new Set(state.activeConnections); - activeConnections.add(action.connection); - - return { - ...state, - activeConnections: Array.from(activeConnections), - }; - } - - if ( - isAction( - action, - ActionTypes.ConnectionDisconnected - ) - ) { - const activeConnections = new Set(state.activeConnections); - activeConnections.delete(action.connection); - - return { - ...state, - activeConnections: Array.from(activeConnections), - }; - } - if ( isAction(action, ActionTypes.ConnectionSelected) ) { @@ -287,20 +244,6 @@ const reducer: Reducer = (state = INITIAL_STATE, action) => { return state; }; -export const connectionConnected = ( - connection: string -): ConnectionConnectedAction => ({ - type: ActionTypes.ConnectionConnected, - connection, -}); - -export const connectionDisconnected = ( - connection: string -): ConnectionDisconnectedAction => ({ - type: ActionTypes.ConnectionDisconnected, - connection, -}); - const getDataServiceAndInstanceForConnection = ( connection: string | null From 3deac6bc83ca400b7cb2023e961872bafc052688 Mon Sep 17 00:00:00 2001 From: Himanshu Singh Date: Mon, 13 May 2024 19:41:23 +0200 Subject: [PATCH 07/10] chore: dispatch single action instead of batching multiple --- .../src/stores/index.ts | 2 +- .../src/stores/open-item.ts | 52 ++++++++++++------- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/packages/compass-saved-aggregations-queries/src/stores/index.ts b/packages/compass-saved-aggregations-queries/src/stores/index.ts index 1b231b2b082..a49638d0ced 100644 --- a/packages/compass-saved-aggregations-queries/src/stores/index.ts +++ b/packages/compass-saved-aggregations-queries/src/stores/index.ts @@ -88,7 +88,7 @@ export function activatePlugin( const store = configureStore(services); return { store, - deactivate: () => { + deactivate() { // noop, no subscriptions in this plugin }, }; diff --git a/packages/compass-saved-aggregations-queries/src/stores/open-item.ts b/packages/compass-saved-aggregations-queries/src/stores/open-item.ts index 853c1df2929..1eeb18215c4 100644 --- a/packages/compass-saved-aggregations-queries/src/stores/open-item.ts +++ b/packages/compass-saved-aggregations-queries/src/stores/open-item.ts @@ -57,6 +57,7 @@ export enum ActionTypes { type OpenModalAction = { type: ActionTypes.OpenModal; selectedItem: Item; + selectedConnection?: string; }; type CloseModalAction = { @@ -128,6 +129,7 @@ const reducer: Reducer = (state = INITIAL_STATE, action) => { return { ...state, selectedItem: action.selectedItem, + selectedCollection: action.selectedConnection ?? state.selectedConnection, isModalOpen: true, }; } @@ -290,20 +292,13 @@ const getDataServiceAndInstanceForConnection = }; }; -export const connectionSelected = - ( - selectedConnection: string - ): SavedQueryAggregationThunkAction> => +const loadDatabasesForConnection = + (connectionId: string): SavedQueryAggregationThunkAction> => async (dispatch) => { - dispatch({ - type: ActionTypes.ConnectionSelected, - connection: selectedConnection, - }); - dispatch({ type: ActionTypes.LoadDatabases }); try { const { error, instance, dataService } = dispatch( - getDataServiceAndInstanceForConnection(selectedConnection) + getDataServiceAndInstanceForConnection(connectionId) ); if (error) { throw error; @@ -319,15 +314,38 @@ export const connectionSelected = } }; +export const connectionSelected = + (selectedConnection: string): SavedQueryAggregationThunkAction => + (dispatch) => { + dispatch({ + type: ActionTypes.ConnectionSelected, + connection: selectedConnection, + }); + + void dispatch(loadDatabasesForConnection(selectedConnection)); + }; + export const updateItemNamespaceChecked = (updateItemNamespace: boolean) => ({ type: ActionTypes.UpdateNamespaceChecked, updateItemNamespace, }); -const openModal = (selectedItem: Item): OpenModalAction => ({ - type: ActionTypes.OpenModal, - selectedItem, -}); +const openModal = + ( + selectedItem: Item, + selectedConnection?: string + ): SavedQueryAggregationThunkAction => + (dispatch) => { + dispatch({ + type: ActionTypes.OpenModal, + selectedItem, + selectedConnection, + }); + + if (selectedConnection) { + void dispatch(loadDatabasesForConnection(selectedConnection)); + } + }; export const closeModal = (): CloseModalAction => ({ type: ActionTypes.CloseModal, @@ -400,11 +418,7 @@ export const openSavedItem = }); if (!coll) { - // There is no way for users to select a connection in single - // connections world but to keep the parity with the state we dispatch - // this selection explicitly - void dispatch(connectionSelected(singleConnectionId)); - dispatch(openModal(item)); + dispatch(openModal(item, singleConnectionId)); return; } From ea5519ea4d07b15948c2bd6513fd3057a680b0ee Mon Sep 17 00:00:00 2001 From: Himanshu Singh Date: Mon, 13 May 2024 20:10:54 +0200 Subject: [PATCH 08/10] chore: remove singleConnectionConnectionInfo from 'My Queries' plugin and Workspace and instead rely on getting the activeConnection from useActiveConnections --- .../components/aggregations-queries-list.tsx | 12 ++++++--- .../src/index.ts | 6 +---- .../src/stores/index.ts | 8 +----- .../src/stores/open-item.ts | 23 +++++++++++------ packages/compass-sidebar/src/plugin.tsx | 15 +++++------ .../src/components/index.tsx | 13 +--------- .../src/components/workspaces.tsx | 25 +++---------------- packages/compass/src/app/components/home.tsx | 20 +-------------- .../compass/src/app/components/workspace.tsx | 20 ++++++--------- 9 files changed, 44 insertions(+), 98 deletions(-) diff --git a/packages/compass-saved-aggregations-queries/src/components/aggregations-queries-list.tsx b/packages/compass-saved-aggregations-queries/src/components/aggregations-queries-list.tsx index 89ee10e1630..d4a27a2de15 100644 --- a/packages/compass-saved-aggregations-queries/src/components/aggregations-queries-list.tsx +++ b/packages/compass-saved-aggregations-queries/src/components/aggregations-queries-list.tsx @@ -21,6 +21,10 @@ import { editItem } from '../stores/edit-item'; import { confirmDeleteItem } from '../stores/delete-item'; import { copyToClipboard } from '../stores/copy-to-clipboard'; import { useTrackOnChange } from '@mongodb-js/compass-logging/provider'; +import { + type ConnectionInfo, + useActiveConnections, +} from '@mongodb-js/compass-connections/provider'; const sortBy: { name: keyof Item; label: string }[] = [ { @@ -73,7 +77,7 @@ export type AggregationsQueriesListProps = { loading: boolean; items: Item[]; onMount(): void; - onOpenItem(id: string): void; + onOpenItem(id: string, activeConnections: ConnectionInfo[]): void; onEditItem(id: string): void; onDeleteItem(id: string): void; onCopyToClipboard(id: string): void; @@ -92,6 +96,8 @@ export const AggregationsQueriesList = ({ void onMount(); }, [onMount]); + const activeConnections = useActiveConnections(); + const { controls: filterControls, conditions: filters, @@ -155,7 +161,7 @@ export const AggregationsQueriesList = ({ (id: string, actionName: Action) => { switch (actionName) { case 'open': - onOpenItem(id); + onOpenItem(id, activeConnections); return; case 'rename': onEditItem(id); @@ -168,7 +174,7 @@ export const AggregationsQueriesList = ({ return; } }, - [onOpenItem, onEditItem, onDeleteItem, onCopyToClipboard] + [activeConnections, onOpenItem, onEditItem, onDeleteItem, onCopyToClipboard] ); const renderItem: React.ComponentProps['renderItem'] = diff --git a/packages/compass-saved-aggregations-queries/src/index.ts b/packages/compass-saved-aggregations-queries/src/index.ts index 73850d0b559..f9293d2d635 100644 --- a/packages/compass-saved-aggregations-queries/src/index.ts +++ b/packages/compass-saved-aggregations-queries/src/index.ts @@ -1,8 +1,5 @@ import { registerHadronPlugin } from 'hadron-app-registry'; -import { - connectionInfoAccessLocator, - connectionsManagerLocator, -} from '@mongodb-js/compass-connections/provider'; +import { connectionsManagerLocator } from '@mongodb-js/compass-connections/provider'; import { mongoDBInstancesManagerLocator } from '@mongodb-js/compass-app-stores/provider'; import { createLoggerAndTelemetryLocator } from '@mongodb-js/compass-logging/provider'; import { activatePlugin } from './stores'; @@ -23,7 +20,6 @@ const serviceLocators = { workspaces: workspacesServiceLocator, pipelineStorage: pipelineStorageLocator, favoriteQueryStorageAccess: favoriteQueryStorageAccessLocator, - connectionInfoAccess: connectionInfoAccessLocator, }; export const MyQueriesPlugin = registerHadronPlugin< diff --git a/packages/compass-saved-aggregations-queries/src/stores/index.ts b/packages/compass-saved-aggregations-queries/src/stores/index.ts index a49638d0ced..7a54d6b570a 100644 --- a/packages/compass-saved-aggregations-queries/src/stores/index.ts +++ b/packages/compass-saved-aggregations-queries/src/stores/index.ts @@ -6,10 +6,7 @@ import type { ThunkAction } from 'redux-thunk'; import itemsReducer from './aggregations-queries-items'; import openItemReducer from './open-item'; import editItemReducer from './edit-item'; -import { - type ConnectionInfoAccess, - type ConnectionsManager, -} from '@mongodb-js/compass-connections/provider'; +import { type ConnectionsManager } from '@mongodb-js/compass-connections/provider'; import type { MongoDBInstancesManager } from '@mongodb-js/compass-app-stores/provider'; import type { LoggerAndTelemetry } from '@mongodb-js/compass-logging/provider'; import type { workspacesServiceLocator } from '@mongodb-js/compass-workspaces/provider'; @@ -29,7 +26,6 @@ type MyQueriesServices = { pipelineStorage?: PipelineStorage; workspaces: ReturnType; favoriteQueryStorageAccess?: FavoriteQueryStorageAccess; - connectionInfoAccess: ConnectionInfoAccess; }; export function configureStore({ @@ -41,7 +37,6 @@ export function configureStore({ workspaces, pipelineStorage, favoriteQueryStorageAccess, - connectionInfoAccess, }: MyQueriesServices) { return createStore( combineReducers({ @@ -59,7 +54,6 @@ export function configureStore({ pipelineStorage, queryStorage: favoriteQueryStorageAccess?.getStorage(), workspaces, - connectionInfoAccess, }) ) ); diff --git a/packages/compass-saved-aggregations-queries/src/stores/open-item.ts b/packages/compass-saved-aggregations-queries/src/stores/open-item.ts index 1eeb18215c4..0186bae4612 100644 --- a/packages/compass-saved-aggregations-queries/src/stores/open-item.ts +++ b/packages/compass-saved-aggregations-queries/src/stores/open-item.ts @@ -1,7 +1,10 @@ import type { ActionCreator, AnyAction, Reducer } from 'redux'; import type { SavedQueryAggregationThunkAction } from '.'; import type { Item } from './aggregations-queries-items'; -import type { DataService } from '@mongodb-js/compass-connections/provider'; +import type { + ConnectionInfo, + DataService, +} from '@mongodb-js/compass-connections/provider'; import type { MongoDBInstance } from '@mongodb-js/compass-app-stores/provider'; function isAction( @@ -385,8 +388,11 @@ const openItem = }; export const openSavedItem = - (id: string): SavedQueryAggregationThunkAction> => - async (dispatch, getState, { preferencesAccess, connectionInfoAccess }) => { + ( + id: string, + activeConnections: ConnectionInfo[] + ): SavedQueryAggregationThunkAction> => + async (dispatch, getState, { preferencesAccess }) => { const { savedItems: { items }, } = getState(); @@ -402,10 +408,11 @@ export const openSavedItem = preferencesAccess.getPreferences().enableNewMultipleConnectionSystem; if (!multiConnectionsEnabled) { - const { id: singleConnectionId } = - connectionInfoAccess.getCurrentConnectionInfo(); + // In single connections mode, we only expect one connections to be here + // in the list of active connections. + const [activeConnection] = activeConnections; const { error, dataService, instance } = dispatch( - getDataServiceAndInstanceForConnection(singleConnectionId) + getDataServiceAndInstanceForConnection(activeConnection.id) ); if (error) { return; @@ -418,11 +425,11 @@ export const openSavedItem = }); if (!coll) { - dispatch(openModal(item, singleConnectionId)); + dispatch(openModal(item, activeConnection.id)); return; } - dispatch(openItem(item, singleConnectionId, database, collection)); + dispatch(openItem(item, activeConnection.id, database, collection)); } else { // TODO: COMPASS-7904 } diff --git a/packages/compass-sidebar/src/plugin.tsx b/packages/compass-sidebar/src/plugin.tsx index 9e2473bee0e..83d215f2520 100644 --- a/packages/compass-sidebar/src/plugin.tsx +++ b/packages/compass-sidebar/src/plugin.tsx @@ -5,12 +5,14 @@ import { css, defaultSidebarWidth, } from '@mongodb-js/compass-components'; -import type { ConnectionInfo } from '@mongodb-js/connection-info'; import { useActiveWorkspace } from '@mongodb-js/compass-workspaces/provider'; import Sidebar from './components/legacy/sidebar'; import { usePreference } from 'compass-preferences-model/provider'; import MultipleConnectionSidebar from './components/multiple-connections/sidebar'; -import { ConnectionInfoProvider } from '@mongodb-js/compass-connections/provider'; +import { + ConnectionInfoProvider, + useActiveConnections, +} from '@mongodb-js/compass-connections/provider'; const errorBoundaryStyles = css({ width: defaultSidebarWidth, @@ -18,15 +20,12 @@ const errorBoundaryStyles = css({ export interface SidebarPluginProps { showConnectionInfo?: boolean; - singleConnectionConnectionInfo?: ConnectionInfo; } const SidebarPlugin: React.FunctionComponent = ({ showConnectionInfo, - // TODO(COMPASS-7397): the need for passing this directly to sidebar should go - // away with refactoring compass-connection to a plugin - singleConnectionConnectionInfo, }) => { + const [activeConnection] = useActiveConnections(); const isMultiConnectionEnabled = usePreference( 'enableNewMultipleConnectionSystem' ); @@ -39,9 +38,7 @@ const SidebarPlugin: React.FunctionComponent = ({ sidebar = ; } else { sidebar = ( - + {(connectionInfo) => { return ( = ({ - singleConnectionConnectionInfo, activeTab, activeTabCollectionInfo, openOnEmptyWorkspace, @@ -120,10 +112,7 @@ const WorkspacesWithSidebar: React.FunctionComponent< {renderSidebar && React.createElement(renderSidebar)}
- +
{renderModals && React.createElement(renderModals)} diff --git a/packages/compass-workspaces/src/components/workspaces.tsx b/packages/compass-workspaces/src/components/workspaces.tsx index 212629eac93..d4f617e5f0d 100644 --- a/packages/compass-workspaces/src/components/workspaces.tsx +++ b/packages/compass-workspaces/src/components/workspaces.tsx @@ -32,7 +32,6 @@ import { connect } from '../stores/context'; import { WorkspaceTabStateProvider } from './workspace-tab-state-provider'; import { NamespaceProvider } from '@mongodb-js/compass-app-stores/provider'; import { - type ConnectionInfo, ConnectionInfoProvider, useTabConnectionTheme, } from '@mongodb-js/compass-connections/provider'; @@ -74,7 +73,6 @@ type CompassWorkspacesProps = { activeTab?: WorkspaceTab | null; collectionInfo: Record; openOnEmptyWorkspace?: OpenWorkspaceOptions | null; - singleConnectionConnectionInfo?: ConnectionInfo; onSelectTab(at: number): void; onSelectNextTab(): void; @@ -101,7 +99,6 @@ const CompassWorkspaces: React.FunctionComponent = ({ onCreateTab, onCloseTab, onNamespaceNotFound, - singleConnectionConnectionInfo, }) => { const { log, mongoLogId } = useLoggerAndTelemetry('COMPASS-WORKSPACES'); const { getWorkspacePluginByName } = useWorkspacePlugins(); @@ -183,23 +180,12 @@ const CompassWorkspaces: React.FunctionComponent = ({ const activeWorkspaceElement = useMemo(() => { switch (activeTab?.type) { - case 'Welcome': { + case 'Welcome': + case 'My Queries': { const Component = getWorkspacePluginByName(activeTab.type); return ; } - // TODO: Remove the ConnectionInfoProvider when we make My Queries - // workspace work independently of a DataService - case 'My Queries': { - const Component = getWorkspacePluginByName(activeTab.type); - return ( - - - - ); - } case 'Performance': case 'Databases': { const Component = getWorkspacePluginByName(activeTab.type); @@ -244,12 +230,7 @@ const CompassWorkspaces: React.FunctionComponent = ({ default: return null; } - }, [ - singleConnectionConnectionInfo, - activeTab, - getWorkspacePluginByName, - onNamespaceNotFound, - ]); + }, [activeTab, getWorkspacePluginByName, onNamespaceNotFound]); const onCreateNewTab = useCallback(() => { onCreateTab(openOnEmptyWorkspace); diff --git a/packages/compass/src/app/components/home.tsx b/packages/compass/src/app/components/home.tsx index c242039e697..3e4100c0044 100644 --- a/packages/compass/src/app/components/home.tsx +++ b/packages/compass/src/app/components/home.tsx @@ -345,31 +345,13 @@ function Home({ {multiConnectionsEnabled && ( - + )} {!multiConnectionsEnabled && (isConnected ? ( diff --git a/packages/compass/src/app/components/workspace.tsx b/packages/compass/src/app/components/workspace.tsx index 3bad0e62671..16d80c6a404 100644 --- a/packages/compass/src/app/components/workspace.tsx +++ b/packages/compass/src/app/components/workspace.tsx @@ -1,6 +1,5 @@ import React from 'react'; import { css } from '@mongodb-js/compass-components'; -import type { ConnectionInfo } from '@mongodb-js/connection-storage/renderer'; import { CompassShellPlugin } from '@mongodb-js/compass-shell'; import { WorkspaceTab as CollectionWorkspace, @@ -36,7 +35,10 @@ import { import { ImportPlugin, ExportPlugin } from '@mongodb-js/compass-import-export'; import ExplainPlanCollectionTabModal from '@mongodb-js/compass-explain-plan'; import ExportToLanguageCollectionTabModal from '@mongodb-js/compass-export-to-language'; -import { ConnectionInfoProvider } from '@mongodb-js/compass-connections/provider'; +import { + ConnectionInfoProvider, + useActiveConnections, +} from '@mongodb-js/compass-connections/provider'; import { usePreference } from 'compass-preferences-model/provider'; const verticalSplitStyles = css({ @@ -53,14 +55,13 @@ const shellContainerStyles = css({ }); export default function Workspace({ - singleConnectionConnectionInfo, onActiveWorkspaceTabChange, }: { - singleConnectionConnectionInfo?: ConnectionInfo; onActiveWorkspaceTabChange: React.ComponentProps< typeof WorkspacesPlugin >['onActiveWorkspaceTabChange']; }): React.ReactElement { + const [activeConnection] = useActiveConnections(); const multiConnectionsEnabled = usePreference( 'enableNewMultipleConnectionSystem' ); @@ -96,13 +97,8 @@ export default function Workspace({ initialWorkspaceTabs={[ { type: multiConnectionsEnabled ? 'Welcome' : 'My Queries' }, ]} - singleConnectionConnectionInfo={singleConnectionConnectionInfo} onActiveWorkspaceTabChange={onActiveWorkspaceTabChange} - renderSidebar={() => ( - - )} + renderSidebar={() => } renderModals={() => ( <> @@ -117,9 +113,7 @@ export default function Workspace({
- +
From 1c41ed61ef6e4cbde0d5a4dabf6330c4f6252741 Mon Sep 17 00:00:00 2001 From: Himanshu Singh Date: Mon, 13 May 2024 20:25:26 +0200 Subject: [PATCH 09/10] chore: compass-web check fixes --- packages/compass-web/src/entrypoint.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/compass-web/src/entrypoint.tsx b/packages/compass-web/src/entrypoint.tsx index 358f2ff4214..b7f15f9acec 100644 --- a/packages/compass-web/src/entrypoint.tsx +++ b/packages/compass-web/src/entrypoint.tsx @@ -156,7 +156,6 @@ function CompassWorkspace({ return ( ); }} From 2483837b52f3ea52272b5802290acf39eaa3b8de Mon Sep 17 00:00:00 2001 From: Himanshu Singh Date: Mon, 13 May 2024 22:09:22 +0200 Subject: [PATCH 10/10] chore: fix typo in reducer --- .../compass-saved-aggregations-queries/src/stores/open-item.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/compass-saved-aggregations-queries/src/stores/open-item.ts b/packages/compass-saved-aggregations-queries/src/stores/open-item.ts index 0186bae4612..157cc5fc7e1 100644 --- a/packages/compass-saved-aggregations-queries/src/stores/open-item.ts +++ b/packages/compass-saved-aggregations-queries/src/stores/open-item.ts @@ -132,7 +132,7 @@ const reducer: Reducer = (state = INITIAL_STATE, action) => { return { ...state, selectedItem: action.selectedItem, - selectedCollection: action.selectedConnection ?? state.selectedConnection, + selectedConnection: action.selectedConnection ?? state.selectedConnection, isModalOpen: true, }; }