1- import type { AnyAction } from 'redux' ;
1+ import type { AnyAction , Dispatch } from 'redux' ;
2+ import type { ThunkAction , ThunkDispatch } from 'redux-thunk' ;
23import type AppRegistry from 'hadron-app-registry' ;
34import type { Document } from 'mongodb' ;
45import { ObjectId } from 'bson' ;
56import toNS from 'mongodb-ns' ;
67
78import createContext from '../stores/context' ;
9+ import type { ContextProps } from '../stores/context' ;
810import { 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 */
8891export const INITIAL_STATE = [ ] ;
8992
93+ type State = WorkspaceTabObject [ ] ;
94+
9095const 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 */
468503export 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