Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
mabaasit committed Sep 23, 2024
1 parent 1dfed32 commit f64ea1d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 42 deletions.
40 changes: 28 additions & 12 deletions packages/compass-global-writes/src/store/index.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
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';
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<R, A extends Action> = ThunkAction<
R,
RootState,
GlobalWritesExtraArgs,
A
>;

type GlobalWritesPluginOptions = CollectionTabPluginMetadata;
type GlobalWritesPluginServices = Pick<
GlobalWritesExtraArgs,
'logger' | 'track' | 'connectionInfoRef'
> & {
atlasService: AtlasService;
};

Expand All @@ -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() };
Expand Down
32 changes: 2 additions & 30 deletions packages/compass-global-writes/src/store/reducer.ts
Original file line number Diff line number Diff line change
@@ -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 {
/**
Expand All @@ -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<RootState, Action> = (
state = initialState,
) => {
const reducer: Reducer<RootState, Action> = (state = initialState) => {
return state;
}

export type GlobalWritesExtraArgs = {
logger: Logger;
track: TrackFunction;
connectionInfoRef: ConnectionInfoRef;
atlasGlobalWritesService: AtlasGlobalWritesService;
};

export type GlobalWritesThunkDispatch<A extends Action = Action> =
ThunkDispatch<RootState, GlobalWritesExtraArgs, A>;

export type GlobalWritesThunkAction<R, A extends Action> = ThunkAction<
R,
RootState,
GlobalWritesExtraArgs,
A
>;

export default reducer;
export default reducer;

0 comments on commit f64ea1d

Please sign in to comment.