Skip to content

Commit 920f572

Browse files
committed
refactor
1 parent 8908793 commit 920f572

File tree

2 files changed

+11
-27
lines changed

2 files changed

+11
-27
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
selectNextTab,
2828
selectPrevTab,
2929
selectTab,
30-
restoreTabs,
30+
restoreWorkspaces,
3131
} from '../stores/workspaces';
3232
import { useWorkspacePlugins } from './workspaces-provider';
3333
import type { ConnectionInfo } from '@mongodb-js/compass-connections/provider';
@@ -335,6 +335,6 @@ export default connect(
335335
onCloseTab: closeTab,
336336
onCloseAllOtherTabs: closeAllOtherTabs,
337337
onNamespaceNotFound: openFallbackWorkspace,
338-
onRestoreTabs: restoreTabs,
338+
onRestoreTabs: restoreWorkspaces,
339339
}
340340
)(CompassWorkspaces);

packages/compass-workspaces/src/stores/workspaces.ts

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export enum WorkspacesActions {
5555
SelectNextTab = 'compass-workspaces/SelectNextTab',
5656
MoveTab = 'compass-workspaces/MoveTab',
5757
OpenTabFromCurrentActive = 'compass-workspaces/OpenTabFromCurrentActive',
58-
RestoreTabs = 'compass-workspaces/RestoreTabs',
58+
RestoreWorkspaces = 'compass-workspaces/RestoreWorkspaces',
5959
DuplicateTab = 'compass-workspaces/DuplicateTab',
6060
CloseTabs = 'compass-workspaces/CloseTabs',
6161
CollectionRenamed = 'compass-workspaces/CollectionRenamed',
@@ -279,7 +279,6 @@ const reducer: Reducer<WorkspacesState, Action> = (
279279
state = getInitialState(),
280280
action
281281
) => {
282-
// TODO: basically just add code here to make sure userData is updated
283282
if (isAction<OpenWorkspaceAction>(action, WorkspacesActions.OpenWorkspace)) {
284283
const currentActiveTab = getActiveTab(state);
285284
const newTab = getInitialTabState(action.workspace);
@@ -349,21 +348,9 @@ const reducer: Reducer<WorkspacesState, Action> = (
349348
};
350349
}
351350

352-
if (isAction<RestoreTabs>(action, WorkspacesActions.RestoreTabs)) {
353-
// TODO: catch exceptions here? e.g. what if the tab doesn't exist?
354-
// Currently, the tabs just aren't visible until the connections are connected, and then
355-
// all of a sudden they show up.
356-
// So, invalid tabs likely just remain invisible. Is this okay? Do we want to
357-
// filter for only the ones that will be visible?
358-
// e.g. if the connection no longer exists, we can probably get rid of it.
359-
360-
// Also if the tab is welcome tab, do we wanna just replace it? That's the default behavior right now.
361-
// However, handle the case where the initial tab opens *after* the restored tabs. Is this even possible?
362-
// This isn't possible since the initial tabs are literally used to configure the store.
363-
364-
// Lastly, figure out which tab should be the active tab in the end.
365-
366-
// console.log('Restoring tabs to state', ...(action.tabs.map(getInitialTabState)));
351+
if (
352+
isAction<RestoreWorkspaces>(action, WorkspacesActions.RestoreWorkspaces)
353+
) {
367354
return {
368355
...state,
369356
tabs: [...state.tabs, ...action.tabs.map(getInitialTabState)],
@@ -876,9 +863,8 @@ type OpenTabFromCurrentActiveAction = {
876863
defaultTab: OpenWorkspaceOptions;
877864
};
878865

879-
// TODO
880-
type RestoreTabs = {
881-
type: WorkspacesActions.RestoreTabs;
866+
type RestoreWorkspaces = {
867+
type: WorkspacesActions.RestoreWorkspaces;
882868
tabs: OpenWorkspaceOptions[];
883869
};
884870

@@ -1002,14 +988,12 @@ type DatabaseRemovedAction = {
1002988
namespace: string;
1003989
};
1004990

1005-
export const restoreTabs = (
991+
export const restoreWorkspaces = (
1006992
tabs: OpenWorkspaceOptions[]
1007-
): WorkspacesThunkAction<void, RestoreTabs> => {
993+
): WorkspacesThunkAction<void, RestoreWorkspaces> => {
1008994
return (dispatch) => {
1009-
// TODO: maybe I dispatch connecting to connections first here?
1010-
console.log('Dispatching restore tabs with tabs:', tabs);
1011995
dispatch({
1012-
type: WorkspacesActions.RestoreTabs,
996+
type: WorkspacesActions.RestoreWorkspaces,
1013997
tabs,
1014998
});
1015999
};

0 commit comments

Comments
 (0)