-
Notifications
You must be signed in to change notification settings - Fork 239
feat(compass-welcome): show connection progress on welcome COMPASS-9634 #7258
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 all commits
6d3a439
feda6d6
3c23d91
b040d6e
2e29c53
b37868b
fdd49f9
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 |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| import React from 'react'; | ||
| import { | ||
| Icon, | ||
| SpinLoader, | ||
| Description, | ||
| spacing, | ||
| css, | ||
| palette, | ||
| keyframes, | ||
| } from '@mongodb-js/compass-components'; | ||
| import { | ||
| useConnectionIds, | ||
| useConnectionInfoForId, | ||
| useConnectionForId, | ||
| } from '@mongodb-js/compass-connections/provider'; | ||
|
|
||
| /** | ||
| * Returns a list of connection ids for connections that are in an active state | ||
| * (connecting, connected, or failed). This is useful for components that need | ||
| * to show activity status without subscribing to the full connection state. | ||
| */ | ||
| export function useActiveConnectionIds() { | ||
| return useConnectionIds( | ||
| (connection) => | ||
| connection.status === 'connecting' || | ||
| connection.status === 'connected' || | ||
| connection.status === 'failed' | ||
| ); | ||
| } | ||
|
|
||
| const connectionListStyles = css({ | ||
| marginTop: spacing[400], | ||
| listStyle: 'none', | ||
| padding: 0, | ||
| // Save space to avoid jumping | ||
| // items are about: spacing[200] (margin) + ~24px (icon/text height) | ||
| minHeight: `${spacing[200] * 3 + 72}px`, | ||
| }); | ||
|
|
||
| const fadeInFromAbove = keyframes({ | ||
| '0%': { | ||
| opacity: 0, | ||
| transform: `translateY(-${spacing[100]}px)`, | ||
| }, | ||
| '100%': { | ||
| opacity: 1, | ||
| transform: 'translateY(0)', | ||
| }, | ||
| }); | ||
|
|
||
| const connectionItemStyles = css({ | ||
| marginBottom: spacing[200], | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| gap: spacing[200], | ||
| animation: `${fadeInFromAbove} 300ms ease-out`, | ||
| }); | ||
|
|
||
| interface ConnectionStatusProps { | ||
| connectionId: string; | ||
| } | ||
|
|
||
| function ConnectionStatus({ connectionId }: ConnectionStatusProps) { | ||
| const connectionInfo = useConnectionInfoForId(connectionId); | ||
| const connection = useConnectionForId(connectionId); | ||
|
|
||
| if (!connectionInfo || !connection) { | ||
| return null; | ||
| } | ||
|
|
||
| const connectionName = connectionInfo.title; | ||
| const status = connection.status; | ||
|
|
||
| const { icon, statusText } = | ||
| status === 'connected' | ||
| ? { | ||
| icon: ( | ||
| <Icon glyph="Checkmark" size="small" color={palette.green.dark2} /> | ||
| ), | ||
| statusText: `Connected to ${connectionName}`, | ||
| } | ||
| : status === 'failed' | ||
| ? { | ||
| icon: <Icon glyph="X" size="small" color={palette.red.base} />, | ||
| statusText: `Failed to connect to ${connectionName}`, | ||
| } | ||
| : { | ||
| icon: <SpinLoader size={16} />, | ||
| statusText: `Connecting to ${connectionName}`, | ||
| }; | ||
|
|
||
| return ( | ||
| <li className={connectionItemStyles}> | ||
| {icon} | ||
| <Description>{statusText}</Description> | ||
| </li> | ||
| ); | ||
| } | ||
|
|
||
| export default function ConnectionList() { | ||
| const activeConnectionIds = useActiveConnectionIds(); | ||
|
|
||
| if (activeConnectionIds.length === 0) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <ul className={connectionListStyles}> | ||
| {activeConnectionIds.map((connectionId) => ( | ||
| <ConnectionStatus key={connectionId} connectionId={connectionId} /> | ||
| ))} | ||
| </ul> | ||
| ); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this a web only feature? It doesn't rely on anything web specific There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mainly just layout, it is totally doable on desktop but I wasn't sure what to do with the "start a free cluster" and "add a connection" cards that are also on this page, I guess they can just be wholesale replaced. My hesitation comes from how the plug image replacing the cloud image is a bit of a jolt but it works because they're in the same position, when I was running this on desktop, the cloud image is to one side, and the jump to center for the plug seems like buggy almost? I may be overly sensitive and we should just keep it simple and make both work. |
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.
Just FYI: using css animations like that means that every time this tab is shown you are replaying the animation, looks slightly unpolished, but probably not worth spending more time on
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.
Good point, I tried some experimentation but since it unmounts I'd have to track the state outside of the component I think. I think most users will navigate away almost immediately 😅
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.
You can do it by making it a style that applies only as effect after initial render of this view on the newly added items, keeping all the state inside the component, but it is still an overkill for the value we get here for sure 😅