Skip to content
Draft
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
68b9e53
init
syn-zhu Aug 29, 2025
a9ea81e
ef
syn-zhu Aug 29, 2025
fc3f50c
ef
syn-zhu Sep 9, 2025
5932624
ef
syn-zhu Sep 9, 2025
8cd1ac5
ef
syn-zhu Sep 9, 2025
b5c6f66
ef
syn-zhu Sep 10, 2025
b308225
restore connections
syn-zhu Sep 16, 2025
a5713b4
refactor
syn-zhu Sep 17, 2025
2351763
refactor
syn-zhu Sep 17, 2025
619362d
break something
syn-zhu Sep 17, 2025
25cf5e6
break something
syn-zhu Sep 17, 2025
e3876f9
fix imports
syn-zhu Sep 17, 2025
8908793
fix imports
syn-zhu Sep 17, 2025
920f572
refactor
syn-zhu Sep 17, 2025
aa78f68
refactor
syn-zhu Sep 17, 2025
42a15e0
add workspaces state service
syn-zhu Sep 19, 2025
9736436
add dekstop storage
syn-zhu Sep 19, 2025
3fd3b6b
implement web storage provider
syn-zhu Sep 19, 2025
04b30c3
make the services work
syn-zhu Sep 30, 2025
321a649
move effect callbacks to service
syn-zhu Sep 30, 2025
b667dd5
remove comment
syn-zhu Sep 30, 2025
27bae4b
provider remove
syn-zhu Sep 30, 2025
0d14953
remove unused stuff
syn-zhu Sep 30, 2025
2932698
cover decline restore
syn-zhu Oct 1, 2025
88c8435
fix things
syn-zhu Oct 4, 2025
da2be3e
add providers
syn-zhu Oct 4, 2025
b2eb338
fix bug
syn-zhu Oct 4, 2025
9f9bab3
add new files
syn-zhu Oct 4, 2025
b0af4d9
filter out welcome tabs
syn-zhu Oct 4, 2025
992f191
merge
syn-zhu Oct 4, 2025
13e2c7d
refactor storage
syn-zhu Oct 4, 2025
097a002
fix logging
syn-zhu Oct 4, 2025
4f1d184
remove space
syn-zhu Oct 5, 2025
5aeb75d
undo typeof
syn-zhu Oct 5, 2025
ef2d42e
remove accidental changes
syn-zhu Oct 5, 2025
a7df6a5
debounce
syn-zhu Oct 8, 2025
76ae816
typing
syn-zhu Oct 8, 2025
a6d7db9
comments
syn-zhu Oct 11, 2025
139f4f4
merge
syn-zhu Oct 11, 2025
e4f9a7a
feature flag
syn-zhu Oct 11, 2025
dec0e41
pref
syn-zhu Oct 11, 2025
cac3263
Merge branch 'main' into smnzhu/save-tab
syn-zhu Oct 14, 2025
a8c7218
address some comments
syn-zhu Oct 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/atlas-service/src/atlas-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ export class AtlasService {
// https://github.com/10gen/mms/blob/9f858bb987aac6aa80acfb86492dd74c89cbb862/client/packages/project/common/ajaxPrefilter.ts#L34-L49
return this.cloudEndpoint(path);
}
userDataEndpoint(path?: string): string {
return `https://cluster-connection.cloud-dev.mongodb.com/userData${normalizePath(
path
)}`;
}
driverProxyEndpoint(path?: string): string {
return `${this.config.ccsBaseUrl}${normalizePath(path)}`;
}
Expand Down
17 changes: 8 additions & 9 deletions packages/compass-user-data/src/user-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { log, mongoLogId } = createLogger('COMPASS-USER-STORAGE');

type SerializeContent<I> = (content: I) => string;
type DeserializeContent = (content: string) => unknown;
type GetResourceUrl = (path?: string) => Promise<string>;
type GetResourceUrl = (path?: string) => string;
type AuthenticatedFetch = (
url: RequestInfo | URL,
options?: RequestInit
Expand Down Expand Up @@ -65,6 +65,7 @@ export abstract class IUserData<T extends z.Schema> {
abstract write(id: string, content: z.input<T>): Promise<boolean>;
abstract delete(id: string): Promise<boolean>;
abstract readAll(options?: ReadOptions): Promise<ReadAllResult<T>>;
abstract readOne(id: string, options: ReadOptions): Promise<z.output<T>>;
abstract updateAttributes(
id: string,
data: Partial<z.input<T>>
Expand Down Expand Up @@ -295,7 +296,7 @@ export class AtlasUserData<T extends z.Schema> extends IUserData<T> {
}

async write(id: string, content: z.input<T>): Promise<boolean> {
const url = await this.getResourceUrl(
const url = this.getResourceUrl(
`${this.dataType}/${this.orgId}/${this.projectId}`
);

Expand Down Expand Up @@ -331,7 +332,7 @@ export class AtlasUserData<T extends z.Schema> extends IUserData<T> {
}

async delete(id: string): Promise<boolean> {
const url = await this.getResourceUrl(
const url = this.getResourceUrl(
`${this.dataType}/${this.orgId}/${this.projectId}/${id}`
);

Expand Down Expand Up @@ -361,9 +362,7 @@ export class AtlasUserData<T extends z.Schema> extends IUserData<T> {
};
try {
const response = await this.authenticatedFetch(
await this.getResourceUrl(
`${this.dataType}/${this.orgId}/${this.projectId}`
),
this.getResourceUrl(`${this.dataType}/${this.orgId}/${this.projectId}`),
{
method: 'GET',
}
Expand Down Expand Up @@ -396,7 +395,7 @@ export class AtlasUserData<T extends z.Schema> extends IUserData<T> {
};

await this.authenticatedFetch(
await this.getResourceUrl(
this.getResourceUrl(
`${this.dataType}/${this.orgId}/${this.projectId}/${id}`
),
{
Expand All @@ -414,7 +413,7 @@ export class AtlasUserData<T extends z.Schema> extends IUserData<T> {
'Atlas Backend',
'Error updating data',
{
url: await this.getResourceUrl(
url: this.getResourceUrl(
`${this.dataType}/${this.orgId}/${this.projectId}/${id}`
),
error: (error as Error).message,
Expand All @@ -426,7 +425,7 @@ export class AtlasUserData<T extends z.Schema> extends IUserData<T> {

// TODO: change this depending on whether or not updateAttributes can provide all current data
async readOne(id: string): Promise<z.output<T>> {
const url = await this.getResourceUrl(
const url = this.getResourceUrl(
`${this.dataType}/${this.orgId}/${this.projectId}/${id}`
);

Expand Down
32 changes: 26 additions & 6 deletions packages/compass-web/src/entrypoint.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import type { ConnectionInfo } from '@mongodb-js/compass-connections/provider';
import { useConnectionActions } from '@mongodb-js/compass-connections/provider';
import { CompassInstanceStorePlugin } from '@mongodb-js/compass-app-stores';
import type { OpenWorkspaceOptions } from '@mongodb-js/compass-workspaces';
import WorkspacesPlugin, {
import {
WorkspacesWebPlugin,
WorkspacesProvider,
} from '@mongodb-js/compass-workspaces';
import {
DatabasesWorkspaceTab,
CollectionsWorkspaceTab,
} from '@mongodb-js/compass-databases-collections';
import { atlasServiceLocator } from '@mongodb-js/atlas-service/provider';
import { CompassComponentsProvider, css } from '@mongodb-js/compass-components';
import {
WorkspaceTab as CollectionWorkspace,
Expand Down Expand Up @@ -62,6 +64,8 @@ import {
CompassAssistantDrawer,
CompassAssistantProvider,
} from '@mongodb-js/compass-assistant';
import { type IUserData } from '@mongodb-js/compass-user-data';
import type { WorkspacesStateSchema } from '@mongodb-js/compass-workspaces';

export type TrackFunction = (
event: string,
Expand All @@ -83,13 +87,16 @@ const WithAtlasProviders: React.FC = ({ children }) => {
};

type CompassWorkspaceProps = Pick<
React.ComponentProps<typeof WorkspacesPlugin>,
React.ComponentProps<typeof WorkspacesWebPlugin>,
'initialWorkspaceTabs' | 'onActiveWorkspaceTabChange'
> &
Pick<
React.ComponentProps<typeof CompassSidebarPlugin>,
'onOpenConnectViaModal'
>;
> & {
orgId: string;
projectId: string;
};

type CompassWebProps = {
/**
Expand Down Expand Up @@ -132,14 +139,19 @@ type CompassWebProps = {
* sync router with the current active workspace
*/
onActiveWorkspaceTabChange: React.ComponentProps<
typeof WorkspacesPlugin
typeof WorkspacesWebPlugin
>['onActiveWorkspaceTabChange'];

/**
* Set of initial preferences to override default values
*/
initialPreferences?: Partial<AllPreferences>;

/**
* UserData instance to use for persisting workspace state
*/
userData: IUserData<typeof WorkspacesStateSchema>;

/**
* Callback prop called every time any code inside Compass logs something
*/
Expand Down Expand Up @@ -173,7 +185,10 @@ function CompassWorkspace({
initialWorkspaceTabs,
onActiveWorkspaceTabChange,
onOpenConnectViaModal,
orgId,
projectId,
}: CompassWorkspaceProps) {
const atlasService = atlasServiceLocator();
return (
<WorkspacesProvider
value={[
Expand Down Expand Up @@ -203,7 +218,10 @@ function CompassWorkspace({
data-testid="compass-web-connected"
className={connectedContainerStyles}
>
<WorkspacesPlugin
<WorkspacesWebPlugin
orgId={orgId}
projectId={projectId}
atlasService={atlasService}
initialWorkspaceTabs={initialWorkspaceTabs}
openOnEmptyWorkspace={{ type: 'Welcome' }}
onActiveWorkspaceTabChange={onActiveWorkspaceTabChange}
Expand All @@ -226,7 +244,7 @@ function CompassWorkspace({
</>
);
}}
></WorkspacesPlugin>
></WorkspacesWebPlugin>
</div>
</CollectionTabsProvider>
</WorkspacesProvider>
Expand Down Expand Up @@ -419,6 +437,8 @@ const CompassWeb = ({
<FieldStorePlugin>
<WithConnectionsStore>
<CompassWorkspace
orgId={orgId}
projectId={projectId}
initialWorkspaceTabs={
initialWorkspaceTabsRef.current
}
Expand Down
41 changes: 41 additions & 0 deletions packages/compass-workspaces/src/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { WorkspaceTab } from '../types';
import Workspaces from './workspaces';
import { connect } from '../stores/context';
import { WorkspacesServiceProvider } from '../provider';
import type { AtlasService } from '../../../atlas-service/dist/atlas-service';

type WorkspacesWithSidebarProps = {
/**
Expand Down Expand Up @@ -56,6 +57,12 @@ type WorkspacesWithSidebarProps = {
renderModals?: () => React.ReactElement | null;
};

type WorkspacesWithSidebarWebProps = WorkspacesWithSidebarProps & {
atlasService: AtlasService;
orgId: string;
projectId: string;
};

const containerLightThemeStyles = css({
backgroundColor: palette.white,
color: palette.gray.dark2,
Expand Down Expand Up @@ -100,6 +107,7 @@ const WorkspacesWithSidebar: React.FunctionComponent<
useEffect(() => {
onChange.current(activeTab, activeTabCollectionInfo);
}, [activeTab, activeTabCollectionInfo]);

return (
<WorkspacesServiceProvider>
<div
Expand All @@ -118,6 +126,28 @@ const WorkspacesWithSidebar: React.FunctionComponent<
);
};

const WorkspacesWithSidebarWeb: React.FunctionComponent<
WorkspacesWithSidebarWebProps
> = ({
activeTab,
activeTabCollectionInfo,
openOnEmptyWorkspace,
onActiveWorkspaceTabChange,
renderSidebar,
renderModals,
}) => {
return (
<WorkspacesWithSidebar
activeTab={activeTab}
activeTabCollectionInfo={activeTabCollectionInfo}
openOnEmptyWorkspace={openOnEmptyWorkspace}
onActiveWorkspaceTabChange={onActiveWorkspaceTabChange}
renderSidebar={renderSidebar}
renderModals={renderModals}
></WorkspacesWithSidebar>
);
};

export default connect((state: WorkspacesState) => {
const activeTab = getActiveTab(state);
return {
Expand All @@ -128,3 +158,14 @@ export default connect((state: WorkspacesState) => {
: null,
};
})(WorkspacesWithSidebar);

export const WorkspacesWeb = connect((state: WorkspacesState) => {
const activeTab = getActiveTab(state);
return {
activeTab,
activeTabCollectionInfo:
activeTab?.type === 'Collection'
? state.collectionInfo[activeTab.namespace]
: null,
};
})(WorkspacesWithSidebarWeb);
44 changes: 43 additions & 1 deletion packages/compass-workspaces/src/components/workspaces.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React, { useCallback, useMemo } from 'react';
import React, { useCallback, useEffect, useMemo } from 'react';
import {
DrawerAnchor,
ErrorBoundary,
MongoDBLogoMark,
WorkspaceTabs,
css,
showConfirmation,
spacing,
useDarkMode,
type WorkspaceTabCoreProps,
Expand Down Expand Up @@ -33,6 +34,8 @@ import { useLogger } from '@mongodb-js/compass-logging/provider';
import { connect } from '../stores/context';
import { WorkspaceTabContextProvider } from './workspace-tab-context-provider';
import type { WorkspaceTab } from '../types';
import { useLoadWorkspacesRef, useRestoreSavedWorkspaces } from '../provider';
import { rest } from 'lodash';

const emptyWorkspaceStyles = css({
margin: '0 auto',
Expand Down Expand Up @@ -111,6 +114,45 @@ const CompassWorkspaces: React.FunctionComponent<CompassWorkspacesProps> = ({
onCreateTab(openOnEmptyWorkspace);
}, [onCreateTab, openOnEmptyWorkspace]);

const loadWorkspacesRef = useLoadWorkspacesRef();
const restoreSavedWorkspaces = useRestoreSavedWorkspaces();

useEffect(() => {
loadWorkspacesRef.current.then(
(res) => {
if (res !== null) {
showConfirmation({
title: 'Reopen closed tabs?',
description:
'Your connection and tabs were closed, this action will reopen your previous session',
buttonText: 'Reopen tabs',
}).then(
(confirm) => {
if (confirm) {
restoreSavedWorkspaces(res);
} else {
// User declined to restore previous session, save the current
// state to override the previous session
restoreSavedWorkspaces([]);
}
},
(err) => {
throw err;
}
);
}
},
(err) => {
log.error(
mongoLogId(1_001_000_361),
'Workspaces',
'Failed to load saved workspaces from previous session',
{ error: err }
);
}
);
}, [loadWorkspacesRef, restoreSavedWorkspaces, log, mongoLogId]);

const workspaceTabs = useMemo(() => {
return tabs.map((tab) => {
const plugin = getWorkspacePluginByName(tab.type);
Expand Down
Loading