Skip to content
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
e04e887
feat(save-user-data): create a user data abstract class
myang1220 Jul 10, 2025
6e7876b
fix: rm defaults and add semaphore to FileUserData
myang1220 Jul 10, 2025
b28596b
feat(save-user-data): push for help
myang1220 Jul 15, 2025
669f626
feat(save-user-data): comment out nulls
myang1220 Jul 15, 2025
c00749f
feat(save-user-data): create a user data abstract class
myang1220 Jul 10, 2025
c41114e
fix: rm defaults and add semaphore to FileUserData
myang1220 Jul 10, 2025
10b0bc1
feat(save-user-data): push for help
myang1220 Jul 15, 2025
d22cebc
potentital org and group id retrieval
myang1220 Jul 17, 2025
eb9c0c2
minor fixes
myang1220 Jul 17, 2025
b3612a7
unit testing
myang1220 Jul 18, 2025
0e9d6dc
package-lock.json
myang1220 Jul 18, 2025
6a3f59d
fix: parse one by one in readAll
myang1220 Jul 21, 2025
4c6bb7c
fix: change updateAttributes return type to boolean
myang1220 Jul 21, 2025
817d4c5
stricter typing for type param and fix update tests
myang1220 Jul 22, 2025
f0db6d0
add getResourceUrl and change groupId to projectId
myang1220 Jul 22, 2025
d18cd15
put data type in IUserData class
myang1220 Jul 23, 2025
6161d84
fix(user-data): add datatype to IUserData abstract class & tests
myang1220 Jul 24, 2025
6bd8634
fix(user-data): make create and update return type to be boolean, lik…
myang1220 Jul 24, 2025
e397192
fix(compass-aggregations): fix method typing
myang1220 Jul 24, 2025
e9850ba
feat: building demo for saving user data project
myang1220 Jul 29, 2025
d678af0
path segment and method binding
myang1220 Jul 30, 2025
dd868db
working demo
myang1220 Jul 31, 2025
ed227d6
restore again
nvs119 Aug 15, 2025
2c69698
make it work on dev
nvs119 Sep 2, 2025
2020afa
test fixes
nvs119 Sep 2, 2025
ae63fac
save progress
nvs119 Sep 3, 2025
194430d
everything working WITH feature flag
nvs119 Sep 4, 2025
8c8519f
Fix compass-sidebar dependency issue by moving useMyQueriesFeature to…
nvs119 Sep 8, 2025
ad739f5
some fixes
nvs119 Sep 8, 2025
1986cca
post rebase
nvs119 Sep 8, 2025
663f992
fix dangling participles
nvs119 Sep 8, 2025
7809ed8
fix tests
nvs119 Sep 8, 2025
d99d1b1
fix some stuff for test
nvs119 Sep 9, 2025
f1c3ac1
merge
nvs119 Sep 16, 2025
834454f
recents and favorites but aggs not work
nvs119 Sep 16, 2025
953fa73
checks and stuff
nvs119 Sep 16, 2025
0c38299
change aggs to uuid and remove response.ok checks
nvs119 Sep 17, 2025
fc98fd8
service accessed through locator
nvs119 Sep 17, 2025
18c3f4a
Working with build time impls
nvs119 Sep 18, 2025
f57e87c
redone code
nvs119 Sep 18, 2025
860bbae
tests
nvs119 Sep 18, 2025
110ee91
no credentials: include
nvs119 Sep 18, 2025
3176131
fixes
nvs119 Sep 18, 2025
412c700
fix my queries storage package check
nvs119 Sep 18, 2025
08c9f20
test fixes
nvs119 Sep 18, 2025
765c77e
Merge branch 'main' into use-atlas-user-data
nvs119 Sep 18, 2025
6bc78e2
fix saved aggregations unit test
nvs119 Sep 18, 2025
c406f40
check
nvs119 Sep 18, 2025
7b79c0a
db coll testS
nvs119 Sep 18, 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
2 changes: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 11 additions & 5 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(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be coming from the config property

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! I was going to do this in a followup PR for this ticket: https://jira.mongodb.org/browse/COMPASS-9663

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super small nit for the future, if you already have a TODO like that in mind, it's super helpful to add it in the code to clarify that something is out of scope for the particular change being up for review 🙂

path
)}`;
}
driverProxyEndpoint(path?: string): string {
return `${this.config.ccsBaseUrl}${normalizePath(path)}`;
}
Expand All @@ -91,13 +96,14 @@ export class AtlasService {
{ url }
);
try {
const headers = {
...this.options?.defaultHeaders,
...(shouldAddCSRFHeaders(init?.method) && getCSRFHeaders()),
...init?.headers,
};
const res = await fetch(url, {
...init,
headers: {
...this.options?.defaultHeaders,
...(shouldAddCSRFHeaders(init?.method) && getCSRFHeaders()),
...init?.headers,
},
headers,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Hard to leave a comment about this in more relevant place) Because we now doing cross origin authenticated requests through AtlasService, we need to allow fetch to include cookies in the request when possible. This is how you do it:

Suggested change
headers,
headers,
credentials: 'include',

But we should probably do this only for authenticatedFetch below

});
this.logger.log.info(
this.logger.mongoLogId(1_001_000_309),
Expand Down
2 changes: 1 addition & 1 deletion packages/atlas-service/src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const AtlasServiceProvider: React.FC<{
);
});

function useAtlasServiceContext(): AtlasService {
export function useAtlasServiceContext(): AtlasService {
const service = useContext(AtlasServiceContext);
if (!service) {
throw new Error('No AtlasService available in this context');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('PipelineToolbar', function () {
/>,
{ pipeline: [{ $match: { _id: 1 } }] },
undefined,
{ pipelineStorage: new CompassPipelineStorage() }
{ pipelineStorage: { getStorage: () => new CompassPipelineStorage() } }
);
toolbar = screen.getByTestId('pipeline-toolbar');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('PipelineHeader', function () {
/>,
undefined,
undefined,
{ pipelineStorage: new CompassPipelineStorage() }
{ pipelineStorage: { getStorage: () => new CompassPipelineStorage() } }
);
container = screen.getByTestId('pipeline-header');
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { connect } from 'react-redux';
import { Button, css, Icon, spacing } from '@mongodb-js/compass-components';
import { Button, Icon, css, spacing } from '@mongodb-js/compass-components';
import { exportToLanguage } from '../../../modules/export-to-language';
import { SaveMenu } from './pipeline-menus';
import PipelineName from './pipeline-name';
Expand Down
6 changes: 3 additions & 3 deletions packages/compass-aggregations/src/stores/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import type { CollectionTabPluginMetadata } from '@mongodb-js/compass-collection
import type { PreferencesAccess } from 'compass-preferences-model';
import type { Logger } from '@mongodb-js/compass-logging/provider';
import type { AtlasAiService } from '@mongodb-js/compass-generative-ai/provider';
import type { PipelineStorage } from '@mongodb-js/my-queries-storage/provider';
import type { PipelineStorageAccess } from '@mongodb-js/my-queries-storage/provider';
import { maxTimeMSChanged } from '../modules/max-time-ms';
import type {
ConnectionInfoRef,
Expand Down Expand Up @@ -80,7 +80,7 @@ export type AggregationsPluginServices = {
logger: Logger;
track: TrackFunction;
atlasAiService: AtlasAiService;
pipelineStorage?: PipelineStorage;
pipelineStorage?: PipelineStorageAccess;
connectionInfoRef: ConnectionInfoRef;
connectionScopedAppRegistry: ConnectionScopedAppRegistry<'open-export'>;
collection: Collection;
Expand Down Expand Up @@ -178,7 +178,7 @@ export function activateAggregationsPlugin(
globalAppRegistry,
localAppRegistry,
pipelineBuilder,
pipelineStorage,
pipelineStorage: pipelineStorage?.getStorage(),
workspaces,
instance,
preferences,
Expand Down
23 changes: 11 additions & 12 deletions packages/compass-preferences-model/src/preferences-schema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -852,18 +852,6 @@ export const storedUserPreferencesProps: Required<{
type: 'boolean',
},

enableMyQueries: {
ui: true,
cli: true,
global: true,
description: {
short:
'Enable My Queries feature to save and manage favorite queries and aggregations',
},
validator: z.boolean().default(true),
type: 'boolean',
},

enableAggregationBuilderRunPipeline: {
ui: true,
cli: true,
Expand Down Expand Up @@ -1032,6 +1020,17 @@ export const storedUserPreferencesProps: Required<{
validator: z.boolean().default(true),
type: 'boolean',
},
enableMyQueries: {
ui: true,
cli: true,
global: true,
description: {
short:
'Enable My Queries feature to save and manage favorite queries and aggregations',
},
validator: z.boolean().default(true),
type: 'boolean',
},

inferNamespacesFromPrivileges: {
ui: true,
Expand Down
14 changes: 14 additions & 0 deletions packages/compass-preferences-model/src/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,17 @@ export function withPreferences<
return createElement(component, { ...prefs, ...props });
};
}

/**
* Hook to check if the My Queries Data Explorer feature is enabled.
* This controls access to:
* - Saved queries and aggregations
* - Recent queries autocomplete
* - Favorite queries/aggregations
*/
export function useMyQueriesFeature(): boolean {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not used anywhere?

const enableMyQueries = usePreference('enableMyQueries');

// Default to true to match the preference schema default
return enableMyQueries ?? true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ describe('queryBarReducer', function () {
.deep.eq(appliedQuery);

// updateAttributes is called in saveRecentAsFavorite and updateFavoriteQuery
expect(updateAttributesStub).to.have.been.calledTwice;
expect(updateAttributesStub).to.have.been.calledOnce;
expect(saveQueriesStub).not.to.have.been.calledTwice;
});
});
Expand Down
40 changes: 33 additions & 7 deletions packages/compass-query-bar/src/stores/query-bar-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,20 @@ export const fetchRecents = (): QueryBarThunkAction<
return async (
dispatch,
_getState,
{ recentQueryStorage, logger: { debug } }
{ recentQueryStorage, logger: { debug }, preferences }
) => {
try {
// Check if My Queries feature is enabled
const { enableMyQueries } = preferences.getPreferences();
if (!enableMyQueries) {
// If feature is disabled, dispatch empty array
dispatch({
type: QueryBarActions.RecentQueriesFetched,
recents: [],
});
return;
}

const {
queryBar: { namespace },
} = _getState();
Expand All @@ -286,7 +297,14 @@ export const fetchRecents = (): QueryBarThunkAction<
};

export const fetchSavedQueries = (): QueryBarThunkAction<void> => {
return (dispatch) => {
return (dispatch, _getState, { preferences }) => {
// Check if My Queries feature is enabled
const { enableMyQueries } = preferences.getPreferences();
if (!enableMyQueries) {
// If feature is disabled, don't fetch anything
return;
}

void dispatch(fetchRecents());
void dispatch(fetchFavorites());
};
Expand All @@ -303,9 +321,20 @@ export const fetchFavorites = (): QueryBarThunkAction<
return async (
dispatch,
_getState,
{ favoriteQueryStorage, logger: { debug } }
{ favoriteQueryStorage, logger: { debug }, preferences }
) => {
try {
// Check if My Queries feature is enabled
const { enableMyQueries } = preferences.getPreferences();
if (!enableMyQueries) {
// If feature is disabled, dispatch empty array
dispatch({
type: QueryBarActions.FavoriteQueriesFetched,
favorites: [],
});
return;
}

const {
queryBar: { namespace },
} = _getState();
Expand Down Expand Up @@ -356,10 +385,7 @@ export const saveRecentAsFavorite = (
};

// add it in the favorite
await favoriteQueryStorage?.updateAttributes(
favoriteQuery._id,
favoriteQuery
);
await favoriteQueryStorage?.saveQuery(favoriteQuery, favoriteQuery._id);

// update favorites
void dispatch(fetchFavorites());
Expand Down
1 change: 1 addition & 0 deletions packages/compass-query-bar/src/stores/query-bar-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export function activatePlugin(

const favoriteQueryStorage = favoriteQueryStorageAccess?.getStorage();
const recentQueryStorage = recentQueryStorageAccess?.getStorage();

const store = configureStore(
{
namespace: namespace ?? '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type { Logger } from '@mongodb-js/compass-logging/provider';
import type { workspacesServiceLocator } from '@mongodb-js/compass-workspaces/provider';
import type {
FavoriteQueryStorageAccess,
PipelineStorageAccess,
PipelineStorage,
FavoriteQueryStorage,
} from '@mongodb-js/my-queries-storage/provider';
Expand All @@ -25,7 +26,7 @@ type MyQueriesServices = {
globalAppRegistry: AppRegistry;
logger: Logger;
track: TrackFunction;
pipelineStorage?: PipelineStorage;
pipelineStorage?: PipelineStorageAccess;
workspaces: ReturnType<typeof workspacesServiceLocator>;
favoriteQueryStorageAccess?: FavoriteQueryStorageAccess;
};
Expand Down Expand Up @@ -55,7 +56,7 @@ export function configureStore({
preferencesAccess,
logger,
track,
pipelineStorage,
pipelineStorage: pipelineStorage?.getStorage(),
queryStorage: favoriteQueryStorageAccess?.getStorage(),
workspaces,
})
Expand All @@ -69,9 +70,10 @@ export type RootState = ReturnType<

type SavedQueryAggregationExtraArgs = Omit<
MyQueriesServices,
'locateFavoriteQueryStorage'
'favoriteQueryStorageAccess' | 'pipelineStorage'
> & {
queryStorage?: FavoriteQueryStorage;
pipelineStorage?: PipelineStorage;
};

export type SavedQueryAggregationThunkAction<
Expand Down
Loading
Loading