Skip to content

Commit a90ac01

Browse files
myang1220nvs119
andauthored
feat(compass-web): add the AtlasUserData class to save user data COMPASS-9565 (#7152)
* feat(save-user-data): create a user data abstract class * fix: rm defaults and add semaphore to FileUserData * feat(save-user-data): push for help * feat(save-user-data): comment out nulls * feat(save-user-data): create a user data abstract class * fix: rm defaults and add semaphore to FileUserData * feat(save-user-data): push for help * potentital org and group id retrieval * minor fixes * unit testing * package-lock.json * fix: parse one by one in readAll * fix: change updateAttributes return type to boolean * stricter typing for type param and fix update tests * add getResourceUrl and change groupId to projectId * put data type in IUserData class * fix(user-data): add datatype to IUserData abstract class & tests * fix(user-data): make create and update return type to be boolean, like queries * fix(compass-aggregations): fix method typing * feat: building demo for saving user data project * path segment and method binding * working demo * restore again * make it work on dev * test fixes * save progress * everything working WITH feature flag * Fix compass-sidebar dependency issue by moving useMyQueriesFeature to compass-preferences-model * some fixes * post rebase * fix dangling participles * fix tests * fix some stuff for test * recents and favorites but aggs not work * checks and stuff * change aggs to uuid and remove response.ok checks * service accessed through locator * Working with build time impls * redone code * tests * no credentials: include * fixes * fix my queries storage package check * test fixes * fix saved aggregations unit test * check * db coll testS --------- Co-authored-by: Niva Vaani Sivakumar <[email protected]>
1 parent 99d4e4c commit a90ac01

File tree

42 files changed

+907
-420
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+907
-420
lines changed

package-lock.json

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/atlas-service/src/atlas-service.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ export class AtlasService {
7878
// https://github.com/10gen/mms/blob/9f858bb987aac6aa80acfb86492dd74c89cbb862/client/packages/project/common/ajaxPrefilter.ts#L34-L49
7979
return this.cloudEndpoint(path);
8080
}
81+
// TODO (COMPASS-9663): these should come from the config property per environment
82+
userDataEndpoint(path?: string): string {
83+
return `https://cluster-connection.cloud-dev.mongodb.com/userData${normalizePath(
84+
path
85+
)}`;
86+
}
8187
driverProxyEndpoint(path?: string): string {
8288
return `${this.config.ccsBaseUrl}${normalizePath(path)}`;
8389
}
@@ -91,13 +97,14 @@ export class AtlasService {
9197
{ url }
9298
);
9399
try {
100+
const headers = {
101+
...this.options?.defaultHeaders,
102+
...(shouldAddCSRFHeaders(init?.method) && getCSRFHeaders()),
103+
...init?.headers,
104+
};
94105
const res = await fetch(url, {
95106
...init,
96-
headers: {
97-
...this.options?.defaultHeaders,
98-
...(shouldAddCSRFHeaders(init?.method) && getCSRFHeaders()),
99-
...init?.headers,
100-
},
107+
headers,
101108
});
102109
this.logger.log.info(
103110
this.logger.mongoLogId(1_001_000_309),
@@ -132,6 +139,7 @@ export class AtlasService {
132139
...init?.headers,
133140
...authHeaders,
134141
},
142+
credentials: 'include',
135143
});
136144
}
137145
async automationAgentRequest(

packages/compass-aggregations/src/components/pipeline-toolbar/index.spec.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
import { expect } from 'chai';
99
import { renderWithStore } from '../../../test/configure-store';
1010
import { PipelineToolbar } from './index';
11-
import { CompassPipelineStorage } from '@mongodb-js/my-queries-storage';
11+
import { createElectronPipelineStorage } from '@mongodb-js/my-queries-storage/electron';
1212

1313
describe('PipelineToolbar', function () {
1414
describe('renders with setting row - visible', function () {
@@ -23,7 +23,12 @@ describe('PipelineToolbar', function () {
2323
/>,
2424
{ pipeline: [{ $match: { _id: 1 } }] },
2525
undefined,
26-
{ pipelineStorage: new CompassPipelineStorage() }
26+
{
27+
pipelineStorage: {
28+
getStorage: () =>
29+
createElectronPipelineStorage({ basepath: '/tmp/test' }),
30+
},
31+
}
2732
);
2833
toolbar = screen.getByTestId('pipeline-toolbar');
2934
});

packages/compass-aggregations/src/components/pipeline-toolbar/pipeline-header/index.spec.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { spy } from 'sinon';
55
import type { SinonSpy } from 'sinon';
66
import { renderWithStore } from '../../../../test/configure-store';
77
import { PipelineHeader } from '.';
8-
import { CompassPipelineStorage } from '@mongodb-js/my-queries-storage';
8+
import { createElectronPipelineStorage } from '@mongodb-js/my-queries-storage/electron';
99

1010
describe('PipelineHeader', function () {
1111
let container: HTMLElement;
@@ -23,7 +23,12 @@ describe('PipelineHeader', function () {
2323
/>,
2424
undefined,
2525
undefined,
26-
{ pipelineStorage: new CompassPipelineStorage() }
26+
{
27+
pipelineStorage: {
28+
getStorage: () =>
29+
createElectronPipelineStorage({ basepath: '/tmp/test' }),
30+
},
31+
}
2732
);
2833
container = screen.getByTestId('pipeline-header');
2934
});

packages/compass-aggregations/src/components/pipeline-toolbar/pipeline-settings/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { connect } from 'react-redux';
3-
import { Button, css, Icon, spacing } from '@mongodb-js/compass-components';
3+
import { Button, Icon, css, spacing } from '@mongodb-js/compass-components';
44
import { exportToLanguage } from '../../../modules/export-to-language';
55
import { SaveMenu } from './pipeline-menus';
66
import PipelineName from './pipeline-name';

packages/compass-aggregations/src/modules/id.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ObjectId } from 'bson';
1+
import { UUID } from 'bson';
22
import type { ClonePipelineAction } from './clone-pipeline';
33
import { CLONE_PIPELINE } from './clone-pipeline';
44
import type { NewPipelineConfirmedAction } from './is-new-pipeline-confirm';
@@ -51,7 +51,7 @@ export default function reducer(
5151
ConfirmNewPipelineActions.NewPipelineConfirmed
5252
)
5353
) {
54-
return new ObjectId().toHexString();
54+
return new UUID().toString();
5555
}
5656
if (isAction<RestorePipelineAction>(action, RESTORE_PIPELINE)) {
5757
return action.storedOptions.id;

packages/compass-aggregations/src/modules/pipeline-builder/stage-editor.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
} from './stage-editor';
2222
import type { StageEditorState, StoreStage, Wizard } from './stage-editor';
2323
import reducer from '../';
24-
import { CompassPipelineStorage } from '@mongodb-js/my-queries-storage';
24+
import { createElectronPipelineStorage } from '@mongodb-js/my-queries-storage/electron';
2525
import Sinon from 'sinon';
2626
import type Stage from './stage';
2727
import { mockDataService } from '../../../test/mocks/data-service';
@@ -130,7 +130,9 @@ function createStore({
130130
localAppRegistry: new AppRegistry(),
131131
atlasAiService: {} as any,
132132
pipelineBuilder,
133-
pipelineStorage: new CompassPipelineStorage(),
133+
pipelineStorage: createElectronPipelineStorage({
134+
basepath: '/tmp/test',
135+
}),
134136
instance: {} as any,
135137
workspaces: {} as any,
136138
preferences,

packages/compass-aggregations/src/modules/pipeline-builder/text-editor-pipeline.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type { PipelineBuilderThunkDispatch } from '..';
1010
import reducer from '..';
1111
import Sinon from 'sinon';
1212
import { toggleAutoPreview } from '../auto-preview';
13-
import { CompassPipelineStorage } from '@mongodb-js/my-queries-storage';
13+
import { createElectronPipelineStorage } from '@mongodb-js/my-queries-storage/electron';
1414
import { mockDataService } from '../../../test/mocks/data-service';
1515

1616
function createStore(
@@ -46,7 +46,9 @@ function createStore(
4646
thunk.withExtraArgument({
4747
atlasAiService: {} as any,
4848
pipelineBuilder,
49-
pipelineStorage: new CompassPipelineStorage(),
49+
pipelineStorage: createElectronPipelineStorage({
50+
basepath: '/tmp/test',
51+
}),
5052
instance: {} as any,
5153
workspaces: {} as any,
5254
preferences: {

packages/compass-aggregations/src/stores/store.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import type { CollectionTabPluginMetadata } from '@mongodb-js/compass-collection
3333
import type { PreferencesAccess } from 'compass-preferences-model';
3434
import type { Logger } from '@mongodb-js/compass-logging/provider';
3535
import type { AtlasAiService } from '@mongodb-js/compass-generative-ai/provider';
36-
import type { PipelineStorage } from '@mongodb-js/my-queries-storage/provider';
36+
import type { PipelineStorageAccess } from '@mongodb-js/my-queries-storage/provider';
3737
import { maxTimeMSChanged } from '../modules/max-time-ms';
3838
import type {
3939
ConnectionInfoRef,
@@ -80,7 +80,7 @@ export type AggregationsPluginServices = {
8080
logger: Logger;
8181
track: TrackFunction;
8282
atlasAiService: AtlasAiService;
83-
pipelineStorage?: PipelineStorage;
83+
pipelineStorage?: PipelineStorageAccess;
8484
connectionInfoRef: ConnectionInfoRef;
8585
connectionScopedAppRegistry: ConnectionScopedAppRegistry<'open-export'>;
8686
collection: Collection;
@@ -178,7 +178,7 @@ export function activateAggregationsPlugin(
178178
globalAppRegistry,
179179
localAppRegistry,
180180
pipelineBuilder,
181-
pipelineStorage,
181+
pipelineStorage: pipelineStorage?.getStorage(),
182182
workspaces,
183183
instance,
184184
preferences,

packages/compass-crud/src/components/bulk-update-modal.spec.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ import {
1111
import BulkUpdateModal from './bulk-update-modal';
1212

1313
import { FavoriteQueryStorageProvider } from '@mongodb-js/my-queries-storage/provider';
14-
import { compassFavoriteQueryStorageAccess } from '@mongodb-js/my-queries-storage';
14+
import { createElectronFavoriteQueryStorage } from '@mongodb-js/my-queries-storage';
15+
16+
// Create mock storage access object for testing
17+
const mockFavoriteQueryStorage = createElectronFavoriteQueryStorage({
18+
basepath: '/tmp/test',
19+
});
20+
const compassFavoriteQueryStorageAccess = {
21+
getStorage: () => mockFavoriteQueryStorage,
22+
};
1523

1624
function renderBulkUpdateModal(
1725
props?: Partial<React.ComponentProps<typeof BulkUpdateModal>>

0 commit comments

Comments
 (0)