Skip to content

Commit f0e5322

Browse files
authored
chore(connections-navigation): add connect button to connections in sidebar COMPASS-8381 (#6449)
* Add connect action to connections in sidebar * Disable pointer cursor and connect on click for disconnected connections * Add "button" representation for the connect button * Update e2e tests * Invert sidebar test
1 parent 7f1fec5 commit f0e5322

File tree

8 files changed

+76
-34
lines changed

8 files changed

+76
-34
lines changed

packages/compass-components/src/components/item-action-controls.tsx

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export type ItemAction<Action extends string> = {
2929
disabledDescription?: string;
3030
tooltip?: string;
3131
actionButtonClassName?: string;
32+
/** How to show the item when not collapsed into the menu */
33+
expandedPresentation?: 'icon' | 'button';
3234
};
3335

3436
export type ItemSeparator = { separator: true };
@@ -343,26 +345,42 @@ export function ItemActionGroup<Action extends string>({
343345
tooltip,
344346
tooltipProps,
345347
actionButtonClassName,
348+
expandedPresentation = 'icon',
346349
} = menuItem;
347-
const button = (
348-
<ItemActionButton
349-
key={action}
350-
glyph={icon}
351-
label={label}
352-
title={!tooltip ? label : undefined}
353-
size={iconSize}
354-
data-action={action}
355-
data-testid={actionTestId<Action>(dataTestId, action)}
356-
onClick={onClick}
357-
className={cx(
358-
actionGroupButtonStyle,
359-
iconClassName,
360-
actionButtonClassName
361-
)}
362-
style={iconStyle}
363-
disabled={isDisabled}
364-
/>
365-
);
350+
const button =
351+
expandedPresentation === 'icon' ? (
352+
<ItemActionButton
353+
key={action}
354+
glyph={icon}
355+
label={label}
356+
title={!tooltip ? label : undefined}
357+
size={iconSize}
358+
data-action={action}
359+
data-testid={actionTestId<Action>(dataTestId, action)}
360+
onClick={onClick}
361+
className={cx(
362+
actionGroupButtonStyle,
363+
iconClassName,
364+
actionButtonClassName
365+
)}
366+
style={iconStyle}
367+
disabled={isDisabled}
368+
/>
369+
) : (
370+
<Button
371+
key={action}
372+
title={!tooltip ? label : undefined}
373+
size={iconSize}
374+
data-action={action}
375+
data-testid={actionTestId<Action>(dataTestId, action)}
376+
onClick={onClick}
377+
className={actionButtonClassName}
378+
style={iconStyle}
379+
disabled={isDisabled}
380+
>
381+
{label}
382+
</Button>
383+
);
366384

367385
if (tooltip) {
368386
return (

packages/compass-connections-navigation/src/base-navigation-item.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type NavigationBaseItemProps = {
1717
isExpandDisabled: boolean;
1818
isExpanded: boolean;
1919
isFocused: boolean;
20+
hasDefaultAction: boolean;
2021
icon: React.ReactNode;
2122
style: React.CSSProperties;
2223

@@ -37,7 +38,6 @@ const menuStyles = css({
3738
});
3839

3940
const itemContainerStyles = css({
40-
cursor: 'pointer',
4141
color: 'var(--item-color)',
4242
backgroundColor: 'var(--item-bg-color)',
4343
'&[data-is-active="true"] .item-wrapper': {
@@ -53,6 +53,10 @@ const itemContainerStyles = css({
5353
},
5454
});
5555

56+
const itemContainerWithActionStyles = css({
57+
cursor: 'pointer',
58+
});
59+
5660
const itemWrapperStyles = css({
5761
display: 'flex',
5862
height: ROW_HEIGHT,
@@ -93,14 +97,17 @@ export const NavigationBaseItem: React.FC<NavigationBaseItemProps> = ({
9397
isExpandDisabled,
9498
isExpanded,
9599
isFocused,
100+
hasDefaultAction,
96101
onExpand,
97102
children,
98103
}) => {
99104
const [hoverProps, isHovered] = useHoverState();
100105
return (
101106
<div
102107
data-testid="base-navigation-item"
103-
className={itemContainerStyles}
108+
className={cx(itemContainerStyles, {
109+
[itemContainerWithActionStyles]: hasDefaultAction,
110+
})}
104111
{...hoverProps}
105112
{...dataAttributes}
106113
>

packages/compass-connections-navigation/src/connections-navigation-tree.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ const ConnectionsNavigationTree: React.FunctionComponent<
8787
if (item.type === 'connection') {
8888
if (item.connectionStatus === 'connected') {
8989
onItemAction(item, 'select-connection');
90-
} else {
91-
onItemAction(item, 'connection-connect');
9290
}
9391
} else if (item.type === 'database') {
9492
onItemAction(item, 'select-database');
@@ -187,7 +185,7 @@ const ConnectionsNavigationTree: React.FunctionComponent<
187185
connectionInfo: item.connectionInfo,
188186
}),
189187
config: {
190-
collapseAfter: 0,
188+
collapseAfter: 1,
191189
},
192190
};
193191
}

packages/compass-connections-navigation/src/item-actions.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { type ItemSeparator } from '@mongodb-js/compass-components';
55

66
export type NavigationItemActions = (ItemAction<Actions> | ItemSeparator)[];
77

8-
export const notConnectedConnectionItemActions = ({
8+
export const commonConnectionItemActions = ({
99
connectionInfo,
1010
}: {
1111
connectionInfo: ConnectionInfo;
@@ -81,7 +81,7 @@ export const connectedConnectionItemActions = ({
8181
isShellEnabled: boolean;
8282
}): NavigationItemActions => {
8383
const isAtlas = !!connectionInfo.atlasMetadata;
84-
const connectionManagementActions = notConnectedConnectionItemActions({
84+
const connectionManagementActions = commonConnectionItemActions({
8585
connectionInfo,
8686
});
8787
const actions: (ItemAction<Actions> | ItemSeparator | null)[] = [
@@ -135,6 +135,23 @@ export const connectedConnectionItemActions = ({
135135
});
136136
};
137137

138+
export const notConnectedConnectionItemActions = ({
139+
connectionInfo,
140+
}: {
141+
connectionInfo: ConnectionInfo;
142+
}): NavigationItemActions => {
143+
const commonActions = commonConnectionItemActions({ connectionInfo });
144+
return [
145+
{
146+
action: 'connection-connect',
147+
label: 'Connect',
148+
icon: 'Connect',
149+
expandedPresentation: 'button',
150+
},
151+
...commonActions,
152+
];
153+
};
154+
138155
export const databaseItemActions = ({
139156
hasWriteActionsDisabled,
140157
}: {

packages/compass-connections-navigation/src/navigation-item.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ export function NavigationItem({
251251
isActive={isActive}
252252
isFocused={isFocused}
253253
isExpanded={!!item.isExpanded}
254+
hasDefaultAction={
255+
item.type !== 'connection' || item.connectionStatus === 'connected'
256+
}
254257
icon={itemIcon}
255258
name={item.name}
256259
style={style}

packages/compass-e2e-tests/helpers/commands/connect.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ export async function connectByName(
185185
connectionName: string,
186186
options: ConnectionResultOptions = {}
187187
) {
188+
await browser.hover(Selectors.sidebarConnection(connectionName));
188189
await browser.clickVisible(Selectors.sidebarConnectionButton(connectionName));
189190
await browser.waitForConnectionResult(connectionName, options);
190191
}

packages/compass-e2e-tests/helpers/selectors.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ export const Single = {
281281
// Multiple Connections sidebar
282282
export const Multiple = {
283283
ConnectionsTitle: '[data-testid="connections-header"]',
284+
ConnectButton: '[data-action="connection-connect"]',
284285
SidebarNewConnectionButton: '[data-action="add-new-connection"]',
285286
ConnectionMenu: '[data-testid="sidebar-navigation-item-actions"]',
286287
CreateDatabaseButton:
@@ -402,7 +403,7 @@ export const sidebarConnection = (connectionName: string): string => {
402403
};
403404

404405
export const sidebarConnectionButton = (connectionName: string): string => {
405-
return `${sidebarConnection(connectionName)} > div > button`;
406+
return `${sidebarConnection(connectionName)} ${Multiple.ConnectButton}`;
406407
};
407408

408409
export const sidebarConnectionActionButton = (

packages/compass-sidebar/src/components/multiple-connections/sidebar.spec.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -460,18 +460,15 @@ describe('Multiple Connections Sidebar Component', function () {
460460
expect(connectionsStoreActions.disconnect).to.have.been.called;
461461
});
462462

463-
it('should connect when the user tries to expand an inactive connection', async function () {
463+
it('should not connect when the user tries to expand an inactive connection', function () {
464464
const connectionItem = screen.getByTestId(savedRecentConnection.id);
465465

466466
userEvent.click(
467467
within(connectionItem).getByLabelText('Caret Right Icon')
468468
);
469-
470-
await waitFor(() => {
471-
expect(connectionsStoreActions.connect).to.be.calledWith(
472-
savedRecentConnection
473-
);
474-
});
469+
expect(connectionsStoreActions.connect).to.not.be.calledWith(
470+
savedRecentConnection
471+
);
475472
});
476473

477474
it('should open edit connection modal when clicked on edit connection action', function () {

0 commit comments

Comments
 (0)