-
Notifications
You must be signed in to change notification settings - Fork 229
feat(sidebar): context menu to control specific navigation items COMPASS-9393 #7070
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
Conversation
70bc8ad
to
0fb7a1e
Compare
0fb7a1e
to
915e207
Compare
There was a problem hiding this 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 adds context menu support to sidebar navigation items by refactoring base components, introducing a new context‐menu grouping helper, and wiring a cascading getContextMenuGroups
prop through the navigation tree.
- Refactor
NavigationBaseItem
to useforwardRef
so it can receive a context‐menu trigger ref. - Propagate a new
getContextMenuGroups
callback throughVirtualTree
,TreeItem
, andNavigationItem
. - Introduce
splitBySeparator
anditemActionsToContextMenuGroups
utilities (with tests) to layout context menu groups.
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
packages/compass-connections-navigation/src/virtual-list/virtual-list.tsx | Added getContextMenuGroups to virtual list props |
packages/compass-connections-navigation/src/tree-data.ts | Added connectionItem and databaseItem to tree items |
packages/compass-connections-navigation/src/navigation-item.tsx | Wired up useContextMenuGroups and passed getContextMenuGroups |
packages/compass-connections-navigation/src/context-menus.ts | Added itemActionsToContextMenuGroups helper |
packages/compass-connections-navigation/src/connections-navigation-tree.tsx | Implemented cascading getContextMenuGroups logic |
packages/compass-connections-navigation/src/base-navigation-item.tsx | Refactored to forwardRef and attached ref to root div |
packages/compass-components/src/index.ts | Exposed new context-menu types and splitBySeparator |
packages/compass-components/src/components/context-menu.tsxx | Exported ContextMenuItemGroup |
packages/compass-components/src/components/actions/utils.ts | Implemented splitBySeparator and isSeparatorMenuAction |
packages/compass-components/src/components/actions/utils.spec.ts | Added tests for splitBySeparator |
packages/compass-components/src/components/actions/types.ts | Introduced MenuAction and ItemSeparator types |
packages/compass-components/src/components/actions/item-action-menu.tsx | Refactored imports to use shared utils |
packages/compass-components/src/components/actions/item-action-group.tsx | Updated imports to use shared utils |
packages/compass-components/src/components/actions/dropdown-menu-button.tsx | Updated imports to use shared utils |
Comments suppressed due to low confidence (4)
packages/compass-connections-navigation/src/context-menus.ts:1
- [nitpick] Add unit tests for
itemActionsToContextMenuGroups
to verify that actions are correctly split into groups and mapped to menu items.
import {
packages/compass-connections-navigation/src/connections-navigation-tree.tsx:267
- The function
collectionItemActions
is referenced here but not imported. Addimport { collectionItemActions } from './item-actions';
to avoid a runtime/compile error.
collectionItemActions({
packages/compass-connections-navigation/src/navigation-item.tsx:9
- [nitpick] Remove the unused import
ItemAction
since it isn't used in this file to keep the imports clean.
type ItemAction,
packages/compass-connections-navigation/src/connections-navigation-tree.tsx:18
- [nitpick] Only
ContextMenuItemGroup
is actually used here. Consider removing the unusedItemAction
andItemSeparator
imports.
} from '@mongodb-js/compass-components';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code part looks good, but I'm really unsure if stacking menus makes sense here, let's maybe ask design for feedback on that. In particular the list of actions for collection is so big it's somewhat disorienting (but maybe this will be better with a compact version of the menu?), I'm also not sure if showing "open shell" on db or coll will be confusing if it will not open shell with namespace preselected, as this is what the "open shell" buttons we have in other scoped parts of UI do
| SidebarNotConnectedConnectionTreeItem, | ||
action: Actions | ||
) => { | ||
const onItemAction = useCallback( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This refactor was necessary to remove the explicit tie-in with the item type and the actions it can run. This would lead to actions silently being dropped when running i.e. 'open-shell'
with a collection item that has a valid connectionId
, even though it has all the information needed for the action to execute.
Now, the requirements are more explicitly based on the available fields and are tied to the action being run asserting for certain types / fields existing.
packages/compass-sidebar/src/components/multiple-connections/connections-navigation.tsx
Show resolved
Hide resolved
@@ -243,3 +245,192 @@ export const collectionItemActions = ({ | |||
|
|||
return actions; | |||
}; | |||
|
|||
export const databaseContextMenuActions = ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
won't be able to reuse actions in this case since we decided to go a more custom route
{ separator: true }, | ||
isShellEnabled | ||
? { | ||
action: 'open-shell', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right-clicking on db/collection, we should open shell for them, right? if you open shell from db screen, it automatically switches to that db usinguse dbName
. And for collection, it switches and writes a find query.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This behaviour is a bit different to what a user would expect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great point, my solution is going to be to remove this from collection level and making a note of this as a descoped feature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feel free to ignore if its more work: for this action, we already have an item and we can do exactly what we do at other places:
- For dbItem we can add
{initialEvaluate: use ${namespace}}
to the options - For collItem we can add
initialEvaluate
andinitialInput
This way we will have same exact behaviour and also have shell in the menu.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh that seems good!
icon: 'Clone', | ||
}, | ||
isAtlas | ||
? null | ||
: { | ||
action: 'remove-connection', | ||
label: 'Remove', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this does change in both in sidebar and context menu but this creates better consistency in general. We have 'Edit connection'
so one would expect the other actions to also have "connection" in their action name just like they do database, collection etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe we add it for favorite/unfavorite as well then?
45a42df
to
c07aaa7
Compare
Semgrep found 4
Using variable interpolation |
Description
Merging this PR will:
NavigationBaseItem
to use forwardRef, in order for the parent component to attach the context menu (e962c88)getContextMenuGroups
through sidebar navigation component tree, similar to how it's currently done forgetItemActions
(7ee2df8)splitBySeparator
utility function, to split actions into groups by their use of a separator item. Used to construct context menus, where each groups is an array of menu items. (23d4ad7)right-click-navigation-items.mov
Checklist
Motivation and Context
Open Questions
I've decided to include all actions (not just those under "...") but also the actions "above the collapse", which is a deviation from the original design.
I've also followed the pattern of cascading actions, such that:
☝️ this doesn't match the design but was discussed in comments on Figma.
Dependents
Types of changes