Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(compass-saved-aggregation-queries): refactor of "My Queries" to support multiple connections COMPASS-7915 #5794

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

himanshusinghs
Copy link
Contributor

@himanshusinghs himanshusinghs commented May 8, 2024

Description

This PR makes "My Queries" plugin work now with ConnectionsManager and InstancesManager instead of DataService and MongoDBInstance. Additionally, now, we don't rely anymore on singleConnectionConnectionInfo that we introduced at some point to render "My Queries" plugin. Instead, we have taken a more optimistic route which is to use useActiveConnections hook to get a hold of current active connections and work with the very first connection that we find, to render "CompassSidebar", "CompassShell" and interaction in "My Queries" plugin for single connection mode.

Checklist

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)

@himanshusinghs himanshusinghs force-pushed the COMPASS-7915-my-queries-refactor branch from 9006f41 to dca37ed Compare May 8, 2024 11:43
@himanshusinghs himanshusinghs marked this pull request as ready for review May 8, 2024 13:37
@himanshusinghs himanshusinghs force-pushed the COMPASS-7915-my-queries-refactor branch from dca37ed to 4d29557 Compare May 10, 2024 14:10
@paula-stacho
Copy link
Contributor

I don't see the activeConnections being initialized when 'My Queries' is open - or is the store initialized when the plugin is included and not when 'My Queries' is open?

@paula-stacho
Copy link
Contributor

In general I wonder if we could have a central place to fetch the active connections, instead of the plugins maintaining their own list. We have the useActiveConnections hook, which needs to be refactored and probably isn't of much use as it is, but perhaps we could work towards a reusable solution

@paula-stacho
Copy link
Contributor

Also regarding the way we deal with single connection -> perhaps all these three questions are leading to the same -> could we use the same approach as in useActiveConnections? Get all connections from repository and use ConnectionsManager to filter for the connected ones? If I'm not mistaken, this should work for the initial state (when 'My Queries' is open), single connection.. and perhaps there is a way to make this reusable.

@himanshusinghs
Copy link
Contributor Author

The active connections are getting initialised currently when we create the store, by listening to ConnectionsManager's events.

Regarding having some central place - Yea I think what we're looking for will be provided by compass-connections once we convert that to plugin and expose a service interface to provide the internals like activeConnections. That is surely the end goal.

@himanshusinghs himanshusinghs force-pushed the COMPASS-7915-my-queries-refactor branch from 4d29557 to 0af9f54 Compare May 13, 2024 10:28
@himanshusinghs
Copy link
Contributor Author

himanshusinghs commented May 13, 2024

I removed the activeConnections from the store given that the connectionRepository won't setup multiple subscriptions anymore (thanks to #5796). Will be using the hook in my next PR to address the connection selector. This one should be ready to go.
Reverted this because I realised we'd need to have some other thunk way to access activeConnections list and it would have ended up in ConnectionsManager which probably won't be nice.

@himanshusinghs himanshusinghs force-pushed the COMPASS-7915-my-queries-refactor branch from 93a8698 to 5c600cb Compare May 13, 2024 12:55
@himanshusinghs himanshusinghs force-pushed the COMPASS-7915-my-queries-refactor branch from 5c600cb to ea5519e Compare May 13, 2024 18:11
@himanshusinghs
Copy link
Contributor Author

Please check the updated description in the PR for the most recent update on this.


const dataService =
connectionsManager.getDataServiceForConnection(connection);
if (!dataService) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I asked in another PR and I feel like it's worth asking again: do we ever expect in the code not to get data service back and handle it by not throwing an error when using manager in actions? Should this logic be part of the method if we always throw if data service is not returned? Same for instance model

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea I am literally doing this if not throw everywhere, will definitely make this part of the getDataService interface. Thank you 👍

Comment on lines +410 to +413
if (!multiConnectionsEnabled) {
// In single connections mode, we only expect one connections to be here
// in the list of active connections.
const [activeConnection] = activeConnections;
Copy link
Contributor

Choose a reason for hiding this comment

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

Unsure why we need the switch on the feature flag here, this should be the same logic for both multi and single connection mode (with other auto-resolving logic):

Suggested change
if (!multiConnectionsEnabled) {
// In single connections mode, we only expect one connections to be here
// in the list of active connections.
const [activeConnection] = activeConnections;
if (activeConnections.length === 1) {
// If there is only one connection, try to resolve collection name to open the saved item without prompting for input
const activeConnection = activeConnections[0];

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea sorry for misdirection here - after our conversation I totally forgot to update / close this PR and left the work for the new modals and this branching in my other branch. I probably will close this one and will just raise one PR having both the changes.

Comment on lines +417 to +419
if (error) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

That's kind of an unexpected pattern, if you really want to use the action to get those values, you can throw right in the get method, no need to return an error to re-throw it, but also see my other comment: every place where we get those, we throw if value is not available, I feel like we should just make the getter method account for that so that we don't need to check everywhere

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.

None yet

3 participants