-
Notifications
You must be signed in to change notification settings - Fork 230
feat(connections-navigation): connect in new window via connect split-button COMPASS-8473 #6577
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
df3c848
Add dependency on split-button
kraenhansen a78cc06
Make ItemActionControls hidable and use a SplitButton
kraenhansen 81364a7
Fix menu item width
kraenhansen dcffcef
Fix event emitter types on CompassApplication
kraenhansen 070641f
Propagate from connections-navigation action through main process IPC
kraenhansen faa13e5
Add connection-id support to the auto-connect feature
kraenhansen 48879d8
Wire up the ConnectButton
kraenhansen 70b558b
Propagate from main IPC into window manager
kraenhansen 2edd457
Add a test
kraenhansen c77f2a8
Remove an outdated comment
kraenhansen 0a8e142
Apply suggestions from code review
kraenhansen 3804739
Add enableConnectInNewWindow preference controlling connect button
kraenhansen 0c638cb
Add test ensuring the right connect button is displayed
kraenhansen dce2e37
Pin [email protected]
kraenhansen 4be7eb5
Revert use of PolymorphicProps
kraenhansen a2744e4
Fix ConnectMenuItem
kraenhansen 37815b1
Simplify text in the connect menu
kraenhansen d63ab8f
Reset windows after each test
kraenhansen b9d0dc1
Update packages/compass/src/main/window-manager.ts
kraenhansen a4f53be
Add comments mentioning COMPASS-8970
kraenhansen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
packages/compass-connections-navigation/src/connect-button-with-menu.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import React, { | ||
useState, | ||
useEffect, | ||
forwardRef, | ||
type ButtonHTMLAttributes, | ||
} from 'react'; | ||
import { | ||
css, | ||
Icon, | ||
MenuItem, | ||
SplitButton, | ||
type GlyphName, | ||
type ItemComponentProps, | ||
type MenuItemProps, | ||
} from '@mongodb-js/compass-components'; | ||
import type { Actions } from './constants'; | ||
|
||
const menuItemStyles = css({ | ||
minWidth: 'max-content', | ||
}); | ||
|
||
type ConnectMenuItemProps = { | ||
action: Actions; | ||
glyph: GlyphName; | ||
} & Omit< | ||
MenuItemProps & ButtonHTMLAttributes<HTMLButtonElement>, | ||
'glyph' | 'as' | ||
>; | ||
|
||
export const ConnectMenuItem = forwardRef< | ||
HTMLButtonElement, | ||
ConnectMenuItemProps | ||
>(function ConnectMenuItem({ action, glyph, ...rest }, ref) { | ||
return ( | ||
<MenuItem | ||
as="button" | ||
data-action={action} | ||
className={menuItemStyles} | ||
glyph={<Icon glyph={glyph} />} | ||
{...rest} | ||
ref={ref} | ||
/> | ||
); | ||
}); | ||
|
||
// Hack to make SplitButton consider this as a MenuItem | ||
ConnectMenuItem.displayName = 'MenuItem'; | ||
|
||
export function ConnectButtonWithMenu({ | ||
setHidable, | ||
action, | ||
tooltip, | ||
label, | ||
iconSize, | ||
iconStyle, | ||
isDisabled, | ||
onClick, | ||
className, | ||
'data-testid': testId, | ||
}: ItemComponentProps<Actions>) { | ||
const [isOpen, setOpen] = useState(false); | ||
|
||
// Opening the menu should keep it visible | ||
useEffect(() => { | ||
if (setHidable) { | ||
setHidable(!isOpen); | ||
} | ||
}, [setHidable, isOpen]); | ||
|
||
return ( | ||
<SplitButton | ||
key={action} | ||
title={!tooltip ? label : undefined} | ||
label={label} | ||
size={iconSize} | ||
data-action={action} | ||
data-testid={testId} | ||
onClick={onClick} | ||
className={className} | ||
style={iconStyle} | ||
disabled={isDisabled} | ||
renderDarkMenu={false} | ||
darkMode={false} | ||
open={isOpen} | ||
setOpen={setOpen} | ||
triggerAriaLabel="see more connection options" | ||
menuItems={[ | ||
<ConnectMenuItem | ||
key="connection-connect" | ||
action="connection-connect" | ||
glyph="Connect" | ||
onClick={onClick} | ||
> | ||
Here | ||
</ConnectMenuItem>, | ||
<ConnectMenuItem | ||
key="connection-connect-in-new-window" | ||
action="connection-connect-in-new-window" | ||
glyph="OpenNewTab" | ||
onClick={onClick} | ||
> | ||
In New Window | ||
</ConnectMenuItem>, | ||
]} | ||
> | ||
{label} | ||
</SplitButton> | ||
); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Any reason this is pinned now?
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.
Yep. I meant to capture an issue on upgrading this as well, the v16.0.3 release is updating the types of the component, heres a comment on the original LG PR introducing the breaking change: mongodb/leafygreen-ui#2703 (comment)
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.
Do we have a ticket to follow up with a fix for that?
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.
Not yet. I'll create that as part of merging this PR - this is what I meant by:
Uh oh!
There was an error while loading. Please reload this page.
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.
I've created COMPASS-8973 now.