Skip to content

Commit 9cd9989

Browse files
authored
chore(compass-collection): Add more types to tab reducers (#3545)
1 parent 6293b54 commit 9cd9989

File tree

12 files changed

+142
-81
lines changed

12 files changed

+142
-81
lines changed

package-lock.json

Lines changed: 0 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-collection/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@
104104
"redux": "^4.2.0",
105105
"redux-thunk": "^2.3.0",
106106
"rimraf": "^3.0.2",
107-
"semver": "^5.4.1",
108107
"sinon": "^9.2.3",
109108
"xvfb-maybe": "^0.2.1"
110109
}

packages/compass-collection/src/components/collection-header/collection-header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ type CollectionHeaderProps = {
117117
isFLE: boolean;
118118
selectOrCreateTab: (options: any) => any;
119119
sourceName?: string;
120-
sourceReadonly: boolean;
120+
sourceReadonly?: boolean;
121121
sourceViewOn?: string;
122122
editViewName?: string;
123123
pipeline: Document[];

packages/compass-collection/src/components/collection/collection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type CollectionProps = {
4040
isClustered: boolean;
4141
isFLE: boolean;
4242
editViewName?: string;
43-
sourceReadonly: boolean;
43+
sourceReadonly?: boolean;
4444
sourceViewOn?: string;
4545
selectOrCreateTab: (options: any) => any;
4646
pipeline: Document[];

packages/compass-collection/src/modules/data-service.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ export default function reducer(
5151
*
5252
* @returns {Object} The data service connected action.
5353
*/
54-
export const dataServiceConnected = (
55-
error: any,
56-
dataService: DataService
57-
): any => ({
54+
export const dataServiceConnected = (error: any, dataService: DataService) => ({
5855
type: DATA_SERVICE_CONNECTED,
5956
error: error,
6057
dataService: dataService,

packages/compass-collection/src/modules/server-version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default function reducer(
4040
*
4141
* @returns {Object} The server version changed action.
4242
*/
43-
export const serverVersionChanged = (version: string): any => ({
43+
export const serverVersionChanged = (version: string) => ({
4444
type: SERVER_VERSION_CHANGED,
4545
version: version,
4646
});

packages/compass-collection/src/modules/tabs.ts

Lines changed: 103 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
import type { AnyAction } from 'redux';
1+
import type { AnyAction, Dispatch } from 'redux';
2+
import type { ThunkAction, ThunkDispatch } from 'redux-thunk';
23
import type AppRegistry from 'hadron-app-registry';
34
import type { Document } from 'mongodb';
45
import { ObjectId } from 'bson';
56
import toNS from 'mongodb-ns';
67

78
import createContext from '../stores/context';
9+
import type { ContextProps } from '../stores/context';
810
import { appRegistryEmit } from './app-registry';
11+
import type { RootState } from '../stores';
912

1013
/**
1114
* The prefix.
@@ -77,7 +80,7 @@ export interface WorkspaceTabObject {
7780
scopedModals: any[];
7881
sourceName: string;
7982
editViewName: string;
80-
sourceReadonly?: any;
83+
sourceReadonly?: boolean;
8184
sourceViewOn?: string;
8285
localAppRegistry: AppRegistry;
8386
}
@@ -87,6 +90,8 @@ export interface WorkspaceTabObject {
8790
*/
8891
export const INITIAL_STATE = [];
8992

93+
type State = WorkspaceTabObject[];
94+
9095
const showCollectionSubmenu = ({ isReadOnly }: { isReadOnly: boolean }) => {
9196
// eslint-disable-next-line @typescript-eslint/no-var-requires
9297
const { ipcRenderer } = require('hadron-ipc');
@@ -113,8 +118,8 @@ const doClearTabs = () => {
113118
*
114119
* @returns {Object} The new state.
115120
*/
116-
const doSelectNamespace = (state: any, action: AnyAction) => {
117-
return state.reduce((newState: any, tab: WorkspaceTabObject) => {
121+
const doSelectNamespace = (state: State, action: AnyAction) => {
122+
return state.reduce((newState: State, tab: WorkspaceTabObject) => {
118123
if (tab.isActive) {
119124
const subTabIndex = action.editViewName ? 1 : 0;
120125
newState.push({
@@ -154,7 +159,7 @@ const doSelectNamespace = (state: any, action: AnyAction) => {
154159
*
155160
* @returns {Object} The new state.
156161
*/
157-
const doCreateTab = (state: any, action: AnyAction) => {
162+
const doCreateTab = (state: State, action: AnyAction) => {
158163
const newState = state.map((tab: WorkspaceTabObject) => {
159164
return { ...tab, isActive: false };
160165
});
@@ -200,16 +205,16 @@ const doCreateTab = (state: any, action: AnyAction) => {
200205
*
201206
* @returns {Object} The new state.
202207
*/
203-
const doCloseTab = (state: any, action: AnyAction) => {
208+
const doCloseTab = (state: State, action: AnyAction) => {
204209
const closeIndex = action.index;
205210
const activeIndex = state.findIndex((tab: WorkspaceTabObject) => {
206211
return tab.isActive;
207212
});
208213
const numTabs = state.length;
209214

210-
return state.reduce((newState: any, tab: WorkspaceTabObject, i: number) => {
215+
return state.reduce((newState: State, tab: WorkspaceTabObject, i: number) => {
211216
if (closeIndex !== i) {
212-
// We follow stnadard browser behaviour with tabs on how we
217+
// We follow standard browser behavior with tabs on how we
213218
// handle which tab gets activated if we close the active tab.
214219
// If the active tab is the last tab, we activate the one before
215220
// it, otherwise we activate the next tab.
@@ -226,7 +231,7 @@ const doCloseTab = (state: any, action: AnyAction) => {
226231
}, []);
227232
};
228233

229-
const doCollectionDropped = (state: any, action: AnyAction) => {
234+
const doCollectionDropped = (state: State, action: AnyAction) => {
230235
const tabs = state.filter((tab: WorkspaceTabObject) => {
231236
return tab.namespace !== action.namespace;
232237
});
@@ -238,7 +243,7 @@ const doCollectionDropped = (state: any, action: AnyAction) => {
238243
return tabs;
239244
};
240245

241-
const doDatabaseDropped = (state: any, action: AnyAction) => {
246+
const doDatabaseDropped = (state: State, action: AnyAction) => {
242247
const tabs = state.filter((tab: WorkspaceTabObject) => {
243248
const tabDbName = toNS(tab.namespace).database;
244249
return tabDbName !== action.name;
@@ -259,7 +264,7 @@ const doDatabaseDropped = (state: any, action: AnyAction) => {
259264
*
260265
* @returns {Object} The new state.
261266
*/
262-
const doMoveTab = (state: any, action: AnyAction) => {
267+
const doMoveTab = (state: State, action: AnyAction) => {
263268
if (action.fromIndex === action.toIndex) return state;
264269
const newState = state.map((tab: WorkspaceTabObject) => ({ ...tab }));
265270
newState.splice(action.toIndex, 0, newState.splice(action.fromIndex, 1)[0]);
@@ -273,7 +278,7 @@ const doMoveTab = (state: any, action: AnyAction) => {
273278
*
274279
* @returns {Object} The new state.
275280
*/
276-
const doNextTab = (state: any) => {
281+
const doNextTab = (state: State) => {
277282
const activeIndex = state.findIndex(
278283
(tab: WorkspaceTabObject) => tab.isActive
279284
);
@@ -292,7 +297,7 @@ const doNextTab = (state: any) => {
292297
*
293298
* @returns {Object} The new state.
294299
*/
295-
const doPrevTab = (state: any) => {
300+
const doPrevTab = (state: State) => {
296301
const activeIndex = state.findIndex(
297302
(tab: WorkspaceTabObject) => tab.isActive
298303
);
@@ -312,7 +317,7 @@ const doPrevTab = (state: any) => {
312317
*
313318
* @returns {Object} The new state.
314319
*/
315-
const doSelectTab = (state: any, action: AnyAction) => {
320+
const doSelectTab = (state: State, action: AnyAction) => {
316321
return state.map((tab: WorkspaceTabObject, i: number) => {
317322
return { ...tab, isActive: action.index === i ? true : false };
318323
});
@@ -326,7 +331,7 @@ const doSelectTab = (state: any, action: AnyAction) => {
326331
*
327332
* @returns {Array} The new state.
328333
*/
329-
const doChangeActiveSubTab = (state: any, action: AnyAction) => {
334+
const doChangeActiveSubTab = (state: State, action: AnyAction) => {
330335
return state.map((tab: WorkspaceTabObject) => {
331336
const subTab =
332337
action.id === tab.id ? action.activeSubTab : tab.activeSubTab;
@@ -397,7 +402,23 @@ export const createTab = ({
397402
sourceViewOn,
398403
query,
399404
aggregation,
400-
}: any): any => ({
405+
}: Pick<
406+
WorkspaceTabObject,
407+
| 'id'
408+
| 'namespace'
409+
| 'isReadonly'
410+
| 'isTimeSeries'
411+
| 'isClustered'
412+
| 'isFLE'
413+
| 'sourceName'
414+
| 'editViewName'
415+
| 'sourceReadonly'
416+
| 'sourceViewOn'
417+
> & {
418+
context: ContextProps;
419+
query?: any; // TODO(COMPASS-6162): type query.
420+
aggregation?: any; // TODO(COMPASS-6162): type aggregation.
421+
}): AnyAction => ({
401422
type: CREATE_TAB,
402423
id,
403424
namespace,
@@ -443,7 +464,21 @@ export const selectNamespace = ({
443464
context,
444465
sourceReadonly,
445466
sourceViewOn,
446-
}: any): any => ({
467+
}: Pick<
468+
WorkspaceTabObject,
469+
| 'id'
470+
| 'namespace'
471+
| 'isReadonly'
472+
| 'isTimeSeries'
473+
| 'isClustered'
474+
| 'isFLE'
475+
| 'sourceName'
476+
| 'editViewName'
477+
| 'sourceReadonly'
478+
| 'sourceViewOn'
479+
> & {
480+
context: ContextProps;
481+
}): AnyAction => ({
447482
type: SELECT_NAMESPACE,
448483
id,
449484
namespace,
@@ -466,8 +501,7 @@ export const selectNamespace = ({
466501
* @returns {Object} The close tab action.
467502
*/
468503
export const closeTab =
469-
(index: number): any =>
470-
(dispatch: any, getState: any) => {
504+
(index: number) => (dispatch: Dispatch, getState: () => RootState) => {
471505
const { tabs } = getState();
472506
if (tabs.length === 1) {
473507
dispatch(appRegistryEmit('all-collection-tabs-closed'));
@@ -604,8 +638,24 @@ export const selectOrCreateTab = ({
604638
sourceReadonly,
605639
sourceViewOn,
606640
sourcePipeline,
607-
}: any): any => {
608-
return (dispatch: any, getState: any) => {
641+
}: Pick<
642+
WorkspaceTabObject,
643+
| 'namespace'
644+
| 'isReadonly'
645+
| 'isTimeSeries'
646+
| 'isClustered'
647+
| 'isFLE'
648+
| 'sourceName'
649+
| 'editViewName'
650+
| 'sourceReadonly'
651+
| 'sourceViewOn'
652+
> & {
653+
sourcePipeline: Document[];
654+
}): ThunkAction<void, RootState, void, AnyAction> => {
655+
return (
656+
dispatch: ThunkDispatch<RootState, void, AnyAction>,
657+
getState: () => RootState
658+
) => {
609659
const state = getState();
610660
if (state.tabs.length === 0) {
611661
dispatch(
@@ -668,8 +718,23 @@ export const createNewTab = ({
668718
sourcePipeline,
669719
query,
670720
aggregation,
671-
}: any): any => {
672-
return (dispatch: any, getState: any) => {
721+
}: Pick<
722+
WorkspaceTabObject,
723+
| 'namespace'
724+
| 'isReadonly'
725+
| 'isTimeSeries'
726+
| 'isClustered'
727+
| 'isFLE'
728+
| 'sourceName'
729+
| 'editViewName'
730+
| 'sourceReadonly'
731+
| 'sourceViewOn'
732+
> & {
733+
sourcePipeline?: Document[];
734+
query?: any; // TODO(COMPASS-6162): type query.
735+
aggregation?: any; // TODO(COMPASS-6162): type aggregation.
736+
}): ThunkAction<void, RootState, void, AnyAction> => {
737+
return (dispatch: Dispatch, getState: () => RootState) => {
673738
const state = getState();
674739
const context = createContext({
675740
state,
@@ -723,8 +788,21 @@ export const replaceTabContent = ({
723788
sourceReadonly,
724789
sourceViewOn,
725790
sourcePipeline,
726-
}: any): any => {
727-
return (dispatch: any, getState: any) => {
791+
}: Pick<
792+
WorkspaceTabObject,
793+
| 'namespace'
794+
| 'isReadonly'
795+
| 'isTimeSeries'
796+
| 'isClustered'
797+
| 'isFLE'
798+
| 'sourceName'
799+
| 'editViewName'
800+
| 'sourceReadonly'
801+
| 'sourceViewOn'
802+
> & {
803+
sourcePipeline?: Document[];
804+
}): ThunkAction<void, RootState, void, AnyAction> => {
805+
return (dispatch: Dispatch, getState: () => RootState) => {
728806
const state = getState();
729807
const context = createContext({
730808
state,

0 commit comments

Comments
 (0)