Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions packages/compass-welcome/src/components/connection-list.tsx
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({
Copy link
Collaborator

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

Kapture 2025-09-15 at 10 11 06

Copy link
Collaborator Author

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 😅

Copy link
Collaborator

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 😅

'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>
);
}
14 changes: 10 additions & 4 deletions packages/compass-welcome/src/components/desktop-welcome-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import {
import { useTelemetry } from '@mongodb-js/compass-telemetry/provider';
import { useConnectionActions } from '@mongodb-js/compass-connections/provider';
import { usePreference } from 'compass-preferences-model/provider';
import { WelcomeTabImage } from './welcome-image';
import { WelcomeTabImage, WelcomePlugImage } from './welcome-image';
import ConnectionList, { useActiveConnectionIds } from './connection-list';

const sectionContainerStyles = css({
margin: 0,
Expand Down Expand Up @@ -126,12 +127,16 @@ export default function DesktopWelcomeTab() {
'enableCreatingNewConnections'
);

const activeConnectionIds = useActiveConnectionIds();

return (
<div className={welcomeTabStyles}>
<WelcomeTabImage />
{(activeConnectionIds.length && <WelcomePlugImage />) || (
<WelcomeTabImage />
)}
<div>
<H3>Welcome to MongoDB Compass</H3>
{enableCreatingNewConnections && (
{(!activeConnectionIds.length && enableCreatingNewConnections && (
<>
<Body>To get started, connect to an existing server or</Body>
<Button
Expand All @@ -145,7 +150,8 @@ export default function DesktopWelcomeTab() {
</Button>
<AtlasHelpSection />
</>
)}
)) ||
(activeConnectionIds.length && <ConnectionList />)}
</div>
</div>
);
Expand Down
62 changes: 35 additions & 27 deletions packages/compass-welcome/src/components/web-welcome-tab.tsx
Copy link
Collaborator

Choose a reason for hiding this comment

The 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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
Link,
} from '@mongodb-js/compass-components';
import { useConnectionIds } from '@mongodb-js/compass-connections/provider';
import { WelcomeTabImage } from './welcome-image';
import { WelcomePlugImage, WelcomeTabImage } from './welcome-image';
import ConnectionList, { useActiveConnectionIds } from './connection-list';

const welcomeTabStyles = css({
display: 'flex',
Expand All @@ -28,36 +29,43 @@ const contentBodyStyles = css({

export default function WebWelcomeTab() {
const numConnections = useConnectionIds().length;
const activeConnectionIds = useActiveConnectionIds();

return (
<div className={welcomeTabStyles}>
<WelcomeTabImage />
{(activeConnectionIds.length && <WelcomePlugImage />) || (
<WelcomeTabImage />
)}
<div>
<H3>Welcome! Explore your data</H3>
<div className={contentBodyStyles}>
<Body>
{numConnections === 0
? 'To get started, create your first MongoDB Cluster.'
: 'To get started, connect to an existing cluster.'}
</Body>
{numConnections === 0 && (
<>
<Button
as={Link}
data-testid="add-new-atlas-cluster-button"
variant={ButtonVariant.Primary}
href={'#/clusters/starterTemplates'}
>
Create a Cluster
</Button>
<Body>
Need more help?{' '}
<Link href="https://www.mongodb.com/docs/atlas/create-connect-deployments/">
View documentation
</Link>
</Body>
</>
)}
</div>
{!activeConnectionIds.length && (
<div className={contentBodyStyles}>
<Body>
{numConnections === 0
? 'To get started, create your first MongoDB Cluster.'
: 'To get started, connect to an existing cluster.'}
</Body>
{numConnections === 0 && (
<>
<Button
as={Link}
data-testid="add-new-atlas-cluster-button"
variant={ButtonVariant.Primary}
href={'#/clusters/starterTemplates'}
>
Create a Cluster
</Button>
<Body>
Need more help?{' '}
<Link href="https://www.mongodb.com/docs/atlas/create-connect-deployments/">
View documentation
</Link>
</Body>
</>
)}
</div>
)}
{activeConnectionIds.length > 0 && <ConnectionList />}
</div>
</div>
);
Expand Down
Loading
Loading