From f64ea1de058aae9c7115333e6535079f53829440 Mon Sep 17 00:00:00 2001 From: Basit Chonka Date: Mon, 23 Sep 2024 20:02:14 +0200 Subject: [PATCH] clean up --- .../compass-global-writes/src/store/index.ts | 40 +++++++++++++------ .../src/store/reducer.ts | 32 +-------------- 2 files changed, 30 insertions(+), 42 deletions(-) diff --git a/packages/compass-global-writes/src/store/index.ts b/packages/compass-global-writes/src/store/index.ts index 5807b9cc877..e482b67d8af 100644 --- a/packages/compass-global-writes/src/store/index.ts +++ b/packages/compass-global-writes/src/store/index.ts @@ -1,4 +1,4 @@ -import { createStore, applyMiddleware } from 'redux'; +import { createStore, applyMiddleware, type Action } from 'redux'; import thunk from 'redux-thunk'; import type { ActivateHelpers } from 'hadron-app-registry'; import type { Logger } from '@mongodb-js/compass-logging'; @@ -6,16 +6,30 @@ import type { TrackFunction } from '@mongodb-js/compass-telemetry'; import type { ConnectionInfoRef } from '@mongodb-js/compass-connections/provider'; import type { CollectionTabPluginMetadata } from '@mongodb-js/compass-collection'; import type { AtlasService } from '@mongodb-js/atlas-service/provider'; +import type { ThunkAction } from 'redux-thunk'; -import reducer, { ShardingStatuses } from './reducer'; +import reducer, { ShardingStatuses, type RootState } from './reducer'; import { AtlasGlobalWritesService } from '../services/atlas-global-writes-service'; -type GlobalWritesPluginOptions = CollectionTabPluginMetadata; - -type GlobalWritesPluginServices = { - connectionInfoRef: ConnectionInfoRef; +type GlobalWritesExtraArgs = { logger: Logger; track: TrackFunction; + connectionInfoRef: ConnectionInfoRef; + atlasGlobalWritesService: AtlasGlobalWritesService; +}; + +export type GlobalWritesThunkAction = ThunkAction< + R, + RootState, + GlobalWritesExtraArgs, + A +>; + +type GlobalWritesPluginOptions = CollectionTabPluginMetadata; +type GlobalWritesPluginServices = Pick< + GlobalWritesExtraArgs, + 'logger' | 'track' | 'connectionInfoRef' +> & { atlasService: AtlasService; }; @@ -37,12 +51,14 @@ export function activateGlobalWritesPlugin( isNamespaceSharded: false, status: ShardingStatuses.NOT_AVAILABLE, }, - applyMiddleware(thunk.withExtraArgument({ - logger, - track, - connectionInfoRef, - atlasGlobalWritesService, - })) + applyMiddleware( + thunk.withExtraArgument({ + logger, + track, + connectionInfoRef, + atlasGlobalWritesService, + }) + ) ); return { store, deactivate: () => cleanup() }; diff --git a/packages/compass-global-writes/src/store/reducer.ts b/packages/compass-global-writes/src/store/reducer.ts index 28c566afe41..c26e7d2a18b 100644 --- a/packages/compass-global-writes/src/store/reducer.ts +++ b/packages/compass-global-writes/src/store/reducer.ts @@ -1,10 +1,4 @@ import type { Action, Reducer } from 'redux'; -import type { ThunkAction, ThunkDispatch } from 'redux-thunk'; -import type { Logger } from '@mongodb-js/compass-logging'; -import type { TrackFunction } from '@mongodb-js/compass-telemetry'; -import type { ConnectionInfoRef } from '@mongodb-js/compass-connections/provider'; - -import type { AtlasGlobalWritesService } from '../services/atlas-global-writes-service'; export enum ShardingStatuses { /** @@ -13,42 +7,20 @@ export enum ShardingStatuses { NOT_AVAILABLE = 'NOT_AVAILABLE', } - export type RootState = { namespace: string; isNamespaceSharded: boolean; status: keyof typeof ShardingStatuses; }; - const initialState: RootState = { namespace: '', isNamespaceSharded: false, status: ShardingStatuses.NOT_AVAILABLE, }; - -const reducer: Reducer = ( - state = initialState, -) => { +const reducer: Reducer = (state = initialState) => { return state; -} - -export type GlobalWritesExtraArgs = { - logger: Logger; - track: TrackFunction; - connectionInfoRef: ConnectionInfoRef; - atlasGlobalWritesService: AtlasGlobalWritesService; }; -export type GlobalWritesThunkDispatch = - ThunkDispatch; - -export type GlobalWritesThunkAction = ThunkAction< - R, - RootState, - GlobalWritesExtraArgs, - A ->; - -export default reducer; \ No newline at end of file +export default reducer;