Skip to content

Conversation

nvs119
Copy link
Contributor

@nvs119 nvs119 commented Sep 2, 2025

Description

Make feature flag to gate user queries. Once this is merged we will use this feature flag in the implementation PR

Checklist

  • New tests and/or benchmarks are included
  • Documentation is changed or added
  • If this change updates the UI, screenshots/videos are added and a design review is requested
  • I have signed the MongoDB Contributor License Agreement (https://www.mongodb.com/legal/contributor-agreement)

Motivation and Context

  • Bugfix
  • New feature
  • Dependency update
  • Misc

Open Questions

Dependents

Types of changes

  • Backport Needed
  • Patch (non-breaking change which fixes an issue)
  • Minor (non-breaking change which adds functionality)
  • Major (fix or feature that would cause existing functionality to change)

@Copilot Copilot AI review requested due to automatic review settings September 2, 2025 03:28
@nvs119 nvs119 requested a review from a team as a code owner September 2, 2025 03:28
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a feature flag MY_QUERIES_DATA_EXPLORER to control access to user query data features. The feature flag gates functionality related to saved queries, aggregations, recent queries autocomplete, and favorite queries/aggregations.

  • Adds the new feature flag to preferences schema and default configurations
  • Creates a dedicated hook useMyQueriesFeature for checking feature availability
  • Integrates the feature flag into UI components to conditionally enable My Queries functionality

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/compass-web/src/preferences.tsx Sets default value for MY_QUERIES_DATA_EXPLORER feature flag to false
packages/compass-web/src/hooks/use-my-queries-feature.ts Creates new hook to check if My Queries feature is enabled
packages/compass-web/src/entrypoint.tsx Imports and uses the new feature flag hook (for future implementation)
packages/compass-web/sandbox/index.tsx Adds feature flag configuration to sandbox environment
packages/compass-sidebar/src/components/multiple-connections/navigation/navigation.tsx Gates My Queries navigation item based on feature flag
packages/compass-query-bar/src/components/query-bar.tsx Conditionally enables saved queries functionality based on feature flag
packages/compass-preferences-model/src/preferences-schema.tsx Adds MY_QUERIES_DATA_EXPLORER to preferences type definitions and schema validation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

onDebug,
});
const preferencesAccess = useCompassWebPreferences(initialPreferences);
const isMyQueriesEnabled = useMyQueriesFeature();
Copy link
Collaborator

Choose a reason for hiding this comment

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

lint will complain about unused variables, you can just leave this commented out together with the todo. we also try to add ticket numbers to todos, I don't think it'll be forgotten in this instance but it's a good habit

export function useMyQueriesFeature(): boolean {
const cloudFeatureRolloutAccess = usePreference('cloudFeatureRolloutAccess');
return cloudFeatureRolloutAccess?.MY_QUERIES_DATA_EXPLORER ?? false;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

compass-web is not the best place for the hook, check out the compass-preferences-model package. there are similar hooks in the utils.

Copy link
Collaborator

Choose a reason for hiding this comment

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

once moved, you can use the hook in the sidebar and query bar

enableDataModeling: true,
cloudFeatureRolloutAccess: {
MY_QUERIES_DATA_EXPLORER: false, // Disabled by default
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

this shouldn't be necessary

@nvs119 nvs119 requested a review from paula-stacho September 4, 2025 00:46
@paula-stacho
Copy link
Collaborator

paula-stacho commented Sep 4, 2025

What happened, where did the changes in compass-preferences-model go? We might need a section on this in the Compass Dev Guide 😅
You'll need to register your new setting in the preferences-schema.tsx. If I'm getting it right and you want a gradual rollout in web, see editable preferences in compass-web-preferences-access.ts.
Additionally, I noticed that the My Queries plugin is actually not included in compass-web at the moment, so you'll need to add it. Search for <WorkspacesProvider, you'll find two versions, the web one is missing My Queries.

In the end, you can test your changes locally with npm run start-web.

Feel free to hit me on slack or schedule a pairing session

description: {
short: 'Save and manage favorite queries and aggregations',
},
},
Copy link
Collaborator

@paula-stacho paula-stacho Sep 4, 2025

Choose a reason for hiding this comment

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

so this part is a bit confusing, but this configuration and feature flags relate to compass, not DE. so adding it here with stage: 'development' adds it to these "feature preview" flags that we have in Compass. They are also turned off by default, which we don't want here.

Image

So instead of adding it to FeatureFlags, let's add it to the "other" section in UserConfigurablePreferences and storedUserPreferencesProps. Example you can follow is enableImportExport (make sure to use default true, you can still override that for compass-web, but the default compass setting for this feature is on).

@nvs119 nvs119 requested a review from paula-stacho September 4, 2025 19:57
</div>
</CollectionTabsProvider>
</WorkspacesProvider>
<PipelineStorageProvider value={pipelineStorage}>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

placeholder until the implementation PR goes in (COMPASS-9565)

Copy link
Contributor Author

@nvs119 nvs119 Sep 4, 2025

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Let's add a TODO or note? Also fine as is as I doubt anyone else will be touching it.

Giving this some thought, we are constructing the file storage items here, it could lead to some unintended errors or something if we change the file storage implementation. Similarly compassFavoriteQueryStorageAccess is only exported for testing. Should we leave these out until we have the web storage? Is there something we want them for now?

Slightly related, a total nit, and not something we follow in many places of Compass really:
https://react.dev/reference/react/useRef#avoiding-recreating-the-ref-contents

We could instead write the creation as:

// Create a simple pipeline storage instance for sandbox.
const pipelineStorageRef = useRef<CompassPipelineStorage | null>(null);
if (pipelineStorageRef.current === null) {
  pipelineStorageRef.current = new CompassPipelineStorage();
}

to avoid calling the constructor of CompassPipelineStorage on each render.

// TODO: remove direct check for storage existing, breaks single source of
// truth rule and exposes services to UI, this breaks the rules for locators
const isSavingAggregationsEnabled = !!usePipelineStorage();
const pipelineStorageAvailable = !!usePipelineStorage();
Copy link
Collaborator

Choose a reason for hiding this comment

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

if I'm not mistaken we can now replace this check with the new flag. tagging @gribnoysup to confirm that the check was for compass-web and not some other case.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep, should replace this with a preference if we have one now

// TODO: remove direct check for storage existing, breaks single source of
// truth rule and exposes services to UI, this breaks the rules for locators
const enableSavedAggregationsQueries = !!usePipelineStorage();
const pipelineStorageAvailable = !!usePipelineStorage();
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as above

RecentQueryStorageProvider,
PipelineStorageProvider,
} from './provider';

Copy link
Collaborator

@paula-stacho paula-stacho Sep 5, 2025

Choose a reason for hiding this comment

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

The provider being exported separately is actually intentional, this is to have a clear separation between the service and the provider (we even have a rule that restricts direct use of the service).
You can import these from @mongodb-js/my-queries-storage/provider

@nvs119 nvs119 requested a review from gribnoysup September 8, 2025 05:20
Copy link
Member

@Anemy Anemy left a comment

Choose a reason for hiding this comment

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

Changes look good, left a couple small comments/questions

"@mongodb-js/connection-info": "^0.18.0",
"@mongodb-js/mongodb-constants": "^0.14.0",
"bson": "^6.10.1",
"bson": "^6.10.4",
Copy link
Member

Choose a reason for hiding this comment

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

Is this related?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops taken out now

"@mongodb-js/compass-utils": "^0.9.12",
"write-file-atomic": "^5.0.1",
"zod": "^3.25.17"
"zod": "^3.25.76"
Copy link
Member

Choose a reason for hiding this comment

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

Same q as the bson dep, totally for my own understanding, happy to have drive by updates in prs, although it can make it easier if we have them in a separate one to make things simple if we ever need to revert.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops taken out now

Body,
css,
openToast,
resetGlobalCSS,
Copy link
Member

Choose a reason for hiding this comment

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

Alphabetical 🙌 big fan.

</div>
</CollectionTabsProvider>
</WorkspacesProvider>
<PipelineStorageProvider value={pipelineStorage}>
Copy link
Member

Choose a reason for hiding this comment

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

Let's add a TODO or note? Also fine as is as I doubt anyone else will be touching it.

Giving this some thought, we are constructing the file storage items here, it could lead to some unintended errors or something if we change the file storage implementation. Similarly compassFavoriteQueryStorageAccess is only exported for testing. Should we leave these out until we have the web storage? Is there something we want them for now?

Slightly related, a total nit, and not something we follow in many places of Compass really:
https://react.dev/reference/react/useRef#avoiding-recreating-the-ref-contents

We could instead write the creation as:

// Create a simple pipeline storage instance for sandbox.
const pipelineStorageRef = useRef<CompassPipelineStorage | null>(null);
if (pipelineStorageRef.current === null) {
  pipelineStorageRef.current = new CompassPipelineStorage();
}

to avoid calling the constructor of CompassPipelineStorage on each render.

@nvs119 nvs119 requested a review from Anemy September 9, 2025 19:51
Copy link
Member

@Anemy Anemy left a comment

Choose a reason for hiding this comment

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

lgtm 1 (once tests pass) !

@nvs119 nvs119 merged commit a09702c into main Sep 9, 2025
54 of 55 checks passed
@nvs119 nvs119 deleted the user-data-feature-flag branch September 9, 2025 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants