Skip to content

Commit fc3f50c

Browse files
committed
ef
1 parent a9ea81e commit fc3f50c

File tree

5 files changed

+49
-38
lines changed

5 files changed

+49
-38
lines changed

packages/compass-web/src/entrypoint.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ function CompassWorkspace({
204204
className={connectedContainerStyles}
205205
>
206206
<WorkspacesPlugin
207+
//TODO:
208+
// savedWorkspacesPromise={savedTabs}
207209
initialWorkspaceTabs={initialWorkspaceTabs}
208210
openOnEmptyWorkspace={{ type: 'Welcome' }}
209211
onActiveWorkspaceTabChange={onActiveWorkspaceTabChange}

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

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useRef } from 'react';
1+
import React, { useEffect, useRef, useState } from 'react';
22
import { css, cx, palette, useDarkMode } from '@mongodb-js/compass-components';
33
import type { CollectionTabInfo } from '../stores/workspaces';
44
import {
@@ -54,6 +54,8 @@ type WorkspacesWithSidebarProps = {
5454
* actions from service locator context
5555
*/
5656
renderModals?: () => React.ReactElement | null;
57+
58+
savedWorkspacesPromise?: Promise<any>;
5759
};
5860

5961
const containerLightThemeStyles = css({
@@ -84,6 +86,31 @@ const sidebarStyles = css({
8486
minHeight: 0,
8587
});
8688

89+
// function usePromise(promise) {
90+
// const [state, setState] = useState({
91+
// data: null,
92+
// error: null,
93+
// loading: true
94+
// });
95+
96+
// useEffect(() => {
97+
// if (!promise) return;
98+
99+
// setState({ data: null, error: null, loading: true });
100+
101+
// promise
102+
// .then(data => {
103+
// // Only update if this is still the current promise
104+
// setState({ data, error: null, loading: false });
105+
// })
106+
// .catch(error => {
107+
// setState({ data: null, error, loading: false });
108+
// });
109+
// }, [promise]);
110+
111+
// return state;
112+
// }
113+
87114
const WorkspacesWithSidebar: React.FunctionComponent<
88115
WorkspacesWithSidebarProps
89116
> = ({
@@ -94,12 +121,22 @@ const WorkspacesWithSidebar: React.FunctionComponent<
94121
renderSidebar,
95122
renderModals,
96123
}) => {
124+
console.log('Loadaweswsf');
97125
const darkMode = useDarkMode();
98126
const onChange = useRef(onActiveWorkspaceTabChange);
99127
onChange.current = onActiveWorkspaceTabChange;
100128
useEffect(() => {
101129
onChange.current(activeTab, activeTabCollectionInfo);
102130
}, [activeTab, activeTabCollectionInfo]);
131+
132+
console.log('Loadawef');
133+
134+
// const { data: savedTabs, loading, error } = usePromise(savedWorkspacesPromise);
135+
// if (loading) return <div>Loading...</div>;
136+
// if (error) return <div>Error: {error.message}</div>;
137+
138+
// console.log("Loaded saved tabs in workspace with sidebar", savedTabs);
139+
103140
return (
104141
<WorkspacesServiceProvider>
105142
<div

packages/compass-workspaces/src/index.ts

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,12 @@ import workspacesReducer, {
1616
connectionDisconnected,
1717
updateDatabaseInfo,
1818
updateCollectionInfo,
19+
loadAndRestoreWorkspaceState,
1920
} from './stores/workspaces';
2021
import Workspaces from './components';
2122
import { applyMiddleware, createStore } from 'redux';
2223
import thunk from 'redux-thunk';
23-
import {
24-
workspacesStateChangeMiddleware,
25-
loadWorkspaceStateFromUserData,
26-
convertSavedStateToInitialTabs,
27-
} from './stores/workspaces-middleware';
24+
import { workspacesStateChangeMiddleware } from './stores/workspaces-middleware';
2825
import type { MongoDBInstance } from '@mongodb-js/compass-app-stores/provider';
2926
import { mongoDBInstancesManagerLocator } from '@mongodb-js/compass-app-stores/provider';
3027
import type Collection from 'mongodb-collection-model';
@@ -80,38 +77,6 @@ export function configureStore(
8077
return store;
8178
}
8279

83-
/**
84-
* Configures the store with optional state restoration from UserData
85-
*/
86-
export async function configureStoreWithStateRestoration(
87-
initialWorkspaceTabs: OpenWorkspaceOptions[] | undefined | null,
88-
services: WorkspacesServices,
89-
restoreFromUserData = false
90-
) {
91-
let tabsToUse = initialWorkspaceTabs;
92-
93-
// If restoration is enabled and no initial tabs provided, try to restore from UserData
94-
if (
95-
restoreFromUserData &&
96-
(!initialWorkspaceTabs || initialWorkspaceTabs.length === 0)
97-
) {
98-
try {
99-
const savedState = await loadWorkspaceStateFromUserData();
100-
if (savedState && savedState.tabs.length > 0) {
101-
// Convert saved state back to initial tabs format
102-
tabsToUse = convertSavedStateToInitialTabs(
103-
savedState
104-
) as OpenWorkspaceOptions[];
105-
}
106-
} catch (error) {
107-
services.logger?.debug('Workspace State Restoration', { error });
108-
// Continue with original initialWorkspaceTabs (empty or provided)
109-
}
110-
}
111-
112-
return configureStore(tabsToUse, services);
113-
}
114-
11580
export function activateWorkspacePlugin(
11681
{
11782
initialWorkspaceTabs,
@@ -281,6 +246,8 @@ const WorkspacesPlugin = registerCompassPlugin(
281246

282247
export default WorkspacesPlugin;
283248
export { WorkspacesProvider } from './components/workspaces-provider';
249+
export { loadAndRestoreWorkspaceState } from './stores/workspaces';
250+
export { loadWorkspaceStateFromUserData } from './stores/workspaces-middleware';
284251
export type { OpenWorkspaceOptions, CollectionTabInfo };
285252
export type {
286253
WelcomeWorkspace,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export const workspacesStateChangeMiddleware: Middleware<
2525
Record<string, never>,
2626
WorkspacesState
2727
> = (store) => (next) => (action: AnyAction) => {
28+
console.log('WOKRSPEF');
2829
const prevState = store.getState();
2930
const result = next(action);
3031
const nextState = store.getState();
@@ -153,6 +154,7 @@ export async function loadWorkspaceStateFromUserData(): Promise<WorkspacesStateD
153154
const savedState = await workspacesUserData.readOne('current-workspace', {
154155
ignoreErrors: true,
155156
});
157+
console.log('Loaded saved state', savedState);
156158
return savedState || null;
157159
} catch (error) {
158160
// eslint-disable-next-line no-console

packages/compass/src/app/components/workspace.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import type {
99
CollectionTabInfo,
1010
} from '@mongodb-js/compass-workspaces';
1111

12+
import loadWorkspaceStateFromUserData from '@mongodb-js/compass-workspaces';
13+
1214
import WorkspacesPlugin, {
1315
WorkspacesProvider,
1416
} from '@mongodb-js/compass-workspaces';
@@ -115,6 +117,7 @@ export default function Workspace({
115117
<CompassAssistantDrawer />
116118
</>
117119
)}
120+
savedWorkspacesPromise={loadWorkspaceStateFromUserData()}
118121
></WorkspacesPlugin>
119122
</CollectionTabsProvider>
120123
</WorkspacesProvider>

0 commit comments

Comments
 (0)