Skip to content

Commit 2351763

Browse files
committed
refactor
1 parent a5713b4 commit 2351763

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

packages/compass-web/src/entrypoint.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ const WithAtlasProviders: React.FC = ({ children }) => {
8484

8585
type CompassWorkspaceProps = Pick<
8686
React.ComponentProps<typeof WorkspacesPlugin>,
87-
'initialWorkspaceTabs' | 'onActiveWorkspaceTabChange'
87+
| 'initialWorkspaceTabs'
88+
| 'onActiveWorkspaceTabChange'
89+
| 'savedWorkspacesPromise'
8890
> &
8991
Pick<
9092
React.ComponentProps<typeof CompassSidebarPlugin>,
@@ -140,6 +142,13 @@ type CompassWebProps = {
140142
*/
141143
initialPreferences?: Partial<AllPreferences>;
142144

145+
/**
146+
* Optional promise that resolves with saved workspaces state from a
147+
* previous session. If provided, compass-web will restore tabs from that
148+
* state on first render.
149+
*/
150+
savedWorkspacesPromise?: Promise<OpenWorkspaceOptions[] | null>;
151+
143152
/**
144153
* Callback prop called every time any code inside Compass logs something
145154
*/
@@ -173,6 +182,7 @@ function CompassWorkspace({
173182
initialWorkspaceTabs,
174183
onActiveWorkspaceTabChange,
175184
onOpenConnectViaModal,
185+
savedWorkspacesPromise,
176186
}: CompassWorkspaceProps) {
177187
return (
178188
<WorkspacesProvider
@@ -203,10 +213,8 @@ function CompassWorkspace({
203213
data-testid="compass-web-connected"
204214
className={connectedContainerStyles}
205215
>
206-
{/* TODO: only show this after user confirms the confirmation screen*/}
207216
<WorkspacesPlugin
208-
//TODO:
209-
// savedWorkspacesPromise={savedTabs}
217+
savedWorkspacesPromise={savedWorkspacesPromise}
210218
initialWorkspaceTabs={initialWorkspaceTabs}
211219
openOnEmptyWorkspace={{ type: 'Welcome' }}
212220
onActiveWorkspaceTabChange={onActiveWorkspaceTabChange}
@@ -269,6 +277,7 @@ const CompassWeb = ({
269277
darkMode,
270278
initialAutoconnectId,
271279
initialWorkspace,
280+
savedWorkspacesPromise,
272281
onActiveWorkspaceTabChange,
273282
initialPreferences,
274283
onLog,
@@ -425,6 +434,9 @@ const CompassWeb = ({
425434
initialWorkspaceTabs={
426435
initialWorkspaceTabsRef.current
427436
}
437+
savedWorkspacesPromise={
438+
savedWorkspacesPromise
439+
}
428440
onActiveWorkspaceTabChange={
429441
onActiveWorkspaceTabChange
430442
}

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useCallback, useEffect, useMemo, useSelector } from 'react';
1+
import React, { useCallback, useEffect, useMemo, useRef } from 'react';
22
import {
33
DrawerAnchor,
44
ErrorBoundary,
@@ -124,10 +124,11 @@ const CompassWorkspaces: React.FunctionComponent<CompassWorkspacesProps> = ({
124124

125125
const connectionActions = useConnectionActions();
126126
const { getConnectionById } = useConnectionsListRef();
127+
const savedWorkspacesPromiseRef = useRef(savedWorkspacesPromise);
127128

128129
useEffect(() => {
129-
if (savedWorkspacesPromise) {
130-
savedWorkspacesPromise.then(
130+
if (savedWorkspacesPromiseRef.current) {
131+
savedWorkspacesPromiseRef.current.then(
131132
(res) => {
132133
if (res !== null) {
133134
showConfirmation({
@@ -179,17 +180,19 @@ const CompassWorkspaces: React.FunctionComponent<CompassWorkspacesProps> = ({
179180
log.error(
180181
mongoLogId(1_001_000_361),
181182
'Workspaces',
182-
'Failed to restore tabs from previous session',
183+
'Failed to load saved workspaces from previous session',
183184
{ error: err }
184185
);
185186
}
186187
);
187188
}
188189
}, [
189-
savedWorkspacesPromise,
190+
savedWorkspacesPromiseRef,
190191
onRestoreTabs,
191192
connectionActions,
192193
getConnectionById,
194+
log,
195+
mongoLogId,
193196
]);
194197

195198
const workspaceTabs = useMemo(() => {

0 commit comments

Comments
 (0)