-
Notifications
You must be signed in to change notification settings - Fork 246
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
Changes from 1 commit
8b627bb
71b529c
52bb155
6649f4a
3e98e06
915e207
1608175
7aa0f79
2424a9e
d71c4cf
83c5df8
0894ce4
da7c6bd
1e2a63e
aaf80d0
05b8047
aaeb53c
fae6fbe
c07aaa7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -206,6 +206,7 @@ export const collectionItemActions = ({ | |
| } | ||
|
|
||
| if (type === 'view') { | ||
| actions.push({ separator: true }); | ||
| actions.push( | ||
| { | ||
| action: 'drop-collection', | ||
|
|
@@ -228,6 +229,7 @@ export const collectionItemActions = ({ | |
| } | ||
|
|
||
| if (type !== 'timeseries' && isRenameCollectionEnabled) { | ||
| actions.push({ separator: true }); | ||
| actions.push({ | ||
| action: 'rename-collection', | ||
| label: 'Rename collection', | ||
|
|
@@ -243,3 +245,192 @@ export const collectionItemActions = ({ | |
|
|
||
| return actions; | ||
| }; | ||
|
|
||
| export const databaseContextMenuActions = ({ | ||
| hasWriteActionsDisabled, | ||
| isShellEnabled, | ||
| isPerformanceTabAvailable, | ||
| isPerformanceTabSupported, | ||
| isAtlas, | ||
| }: { | ||
| hasWriteActionsDisabled: boolean; | ||
| isShellEnabled: boolean; | ||
| isPerformanceTabAvailable: boolean; | ||
| isPerformanceTabSupported: boolean; | ||
| isAtlas: boolean; | ||
| }): NavigationItemActions => { | ||
| return stripNullActions([ | ||
| // Database-specific actions | ||
| hasWriteActionsDisabled | ||
| ? null | ||
| : { | ||
| action: 'create-collection', | ||
| icon: 'Plus', | ||
| label: 'Create collection', | ||
| }, | ||
| { separator: true }, | ||
| hasWriteActionsDisabled | ||
| ? null | ||
| : { | ||
| action: 'create-database', | ||
| icon: 'Plus', | ||
| label: 'Create database', | ||
| }, | ||
| hasWriteActionsDisabled | ||
| ? null | ||
| : { | ||
| action: 'drop-database', | ||
| icon: 'Trash', | ||
| label: 'Drop database', | ||
| }, | ||
| { separator: true }, | ||
| isShellEnabled | ||
| ? { | ||
| action: 'open-shell', | ||
| icon: 'Shell', | ||
| label: 'Open MongoDB shell', | ||
| } | ||
| : null, | ||
| isPerformanceTabAvailable | ||
| ? { | ||
| action: 'connection-performance-metrics', | ||
| icon: 'Gauge', | ||
| label: 'View performance metrics', | ||
| isDisabled: !isPerformanceTabSupported, | ||
| disabledDescription: 'Not supported', | ||
| } | ||
| : null, | ||
| isAtlas | ||
| ? null | ||
| : { | ||
| action: 'open-connection-info', | ||
| icon: 'InfoWithCircle', | ||
| label: 'Show connection info', | ||
| }, | ||
| { | ||
| action: 'refresh-databases', | ||
| label: 'Refresh databases', | ||
| icon: 'Refresh', | ||
| }, | ||
| { separator: true }, | ||
| { | ||
| action: 'connection-disconnect', | ||
| icon: 'Disconnect', | ||
| label: 'Disconnect', | ||
| variant: 'destructive', | ||
| }, | ||
| ]); | ||
| }; | ||
|
|
||
| export const collectionContextMenuActions = ({ | ||
| hasWriteActionsDisabled, | ||
| type, | ||
| isRenameCollectionEnabled, | ||
| isShellEnabled, | ||
| isPerformanceTabAvailable, | ||
| isPerformanceTabSupported, | ||
| isAtlas, | ||
| }: { | ||
| hasWriteActionsDisabled: boolean; | ||
| type: 'collection' | 'view' | 'timeseries'; | ||
| isRenameCollectionEnabled: boolean; | ||
| isShellEnabled: boolean; | ||
| isPerformanceTabAvailable: boolean; | ||
| isPerformanceTabSupported: boolean; | ||
| isAtlas: boolean; | ||
| }): NavigationItemActions => { | ||
| const actions: NavigationItemActions = [ | ||
| // Collection-specific actions | ||
| { | ||
| action: 'open-in-new-tab', | ||
| label: 'Open in new tab', | ||
| icon: 'OpenNewTab', | ||
| }, | ||
| ]; | ||
|
|
||
| if (!hasWriteActionsDisabled) { | ||
| if (type === 'view') { | ||
| actions.push({ separator: true }); | ||
| // For views: show Duplicate view, Modify view, Drop view | ||
| actions.push( | ||
| { | ||
| action: 'duplicate-view', | ||
| label: 'Duplicate view', | ||
| icon: 'Copy', | ||
| }, | ||
| { | ||
| action: 'modify-view', | ||
| label: 'Modify view', | ||
| icon: 'Edit', | ||
| }, | ||
| { | ||
| action: 'drop-collection', | ||
| label: 'Drop view', | ||
| icon: 'Trash', | ||
| } | ||
| ); | ||
| } else { | ||
| actions.push({ separator: true }); | ||
| // For collections: show Rename collection, Drop collection | ||
| if (type !== 'timeseries' && isRenameCollectionEnabled) { | ||
| actions.push({ | ||
| action: 'rename-collection', | ||
| label: 'Rename collection', | ||
| icon: 'Edit', | ||
| }); | ||
| } | ||
| actions.push({ | ||
| action: 'create-collection', | ||
| icon: 'Plus', | ||
| label: 'Create collection', | ||
| }); | ||
| actions.push({ | ||
| action: 'drop-collection', | ||
| label: 'Drop collection', | ||
| icon: 'Trash', | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| // Add connection-level actions | ||
| const connectionActions = stripNullActions([ | ||
gagik marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { separator: true }, | ||
| isShellEnabled | ||
| ? { | ||
| action: 'open-shell', | ||
|
||
| icon: 'Shell', | ||
| label: 'Open MongoDB shell', | ||
| } | ||
| : null, | ||
| isPerformanceTabAvailable | ||
| ? { | ||
| action: 'connection-performance-metrics', | ||
| icon: 'Gauge', | ||
| label: 'View performance metrics', | ||
| isDisabled: !isPerformanceTabSupported, | ||
| disabledDescription: 'Not supported', | ||
| } | ||
| : null, | ||
| isAtlas | ||
| ? null | ||
| : { | ||
| action: 'open-connection-info', | ||
| icon: 'InfoWithCircle', | ||
| label: 'Show connection info', | ||
| }, | ||
| { | ||
| action: 'refresh-databases', | ||
| label: 'Refresh collection', | ||
| icon: 'Refresh', | ||
| }, | ||
| { separator: true }, | ||
| { | ||
| action: 'connection-disconnect', | ||
| icon: 'Disconnect', | ||
| label: 'Disconnect', | ||
| variant: 'destructive', | ||
| }, | ||
| ]); | ||
|
|
||
| return [...actions, ...connectionActions]; | ||
| }; | ||
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