Skip to content

Commit 2d7ff73

Browse files
authored
chore(connections-navigation): disable sidebar right-caret on disconnected connections (#6499)
* Add and use disable prop on ExpandButton * Pass functional Item component directly * Pass and call a memoized toggle callback * Prevent propagation of clicks on the ExpandButton * Revert "Pass functional Item component directly" This reverts commit a2c3f42.
1 parent 0f249c3 commit 2d7ff73

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

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

+7-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type NavigationBaseItemProps = {
2828
actions: NavigationItemActions;
2929
onAction: (action: Actions) => void;
3030
};
31-
onExpand: (toggle: boolean) => void;
31+
toggleExpand: () => void;
3232
};
3333

3434
const menuStyles = css({
@@ -98,7 +98,7 @@ export const NavigationBaseItem: React.FC<NavigationBaseItemProps> = ({
9898
isExpanded,
9999
isFocused,
100100
hasDefaultAction,
101-
onExpand,
101+
toggleExpand,
102102
children,
103103
}) => {
104104
const [hoverProps, isHovered] = useHoverState();
@@ -114,12 +114,13 @@ export const NavigationBaseItem: React.FC<NavigationBaseItemProps> = ({
114114
<div className={cx('item-wrapper', itemWrapperStyles)} style={style}>
115115
{isExpandVisible && (
116116
<ExpandButton
117-
onClick={(evt) => {
118-
if (isExpandDisabled) return;
119-
evt.stopPropagation();
120-
onExpand(!isExpanded);
117+
onClick={(event) => {
118+
// Prevent the click from propagating to the `TreeItem`, triggering the default action
119+
event.stopPropagation();
120+
toggleExpand();
121121
}}
122122
isExpanded={isExpanded}
123+
disabled={isExpandDisabled}
123124
></ExpandButton>
124125
)}
125126
<div className={labelAndIconWrapperStyles}>

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,12 @@ export function NavigationItem({
242242
return actions;
243243
}, [item, isDarkMode]);
244244

245+
const toggleExpand = useCallback(() => {
246+
if (item.type !== 'placeholder') {
247+
onItemExpand(item, !item.isExpanded);
248+
}
249+
}, [onItemExpand, item]);
250+
245251
return (
246252
<StyledNavigationItem item={item}>
247253
{item.type === 'placeholder' ? (
@@ -262,9 +268,7 @@ export function NavigationItem({
262268
isExpandDisabled={
263269
item.type === 'connection' && item.connectionStatus !== 'connected'
264270
}
265-
onExpand={(isExpanded: boolean) => {
266-
onItemExpand(item, isExpanded);
267-
}}
271+
toggleExpand={toggleExpand}
268272
actionProps={actionProps}
269273
>
270274
{!!connectionStaticActions.length && (

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

+12-6
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ const expandButton = css({
1313
display: 'flex',
1414
transition: 'transform .16s linear',
1515
transform: 'rotate(0deg)',
16-
'&:hover': {
17-
cursor: 'pointer',
18-
},
1916
// we're sizing the icon down below but we still want the button to take up
2017
// 16px so that the grid lines up
2118
minWidth: spacing[400],
@@ -24,18 +21,23 @@ const expandButton = css({
2421
justifyContent: 'center',
2522
});
2623

27-
const expanded = css({
24+
const expandedStyles = css({
2825
transform: 'rotate(90deg)',
2926
});
3027

28+
const enabledStyles = css({
29+
cursor: 'pointer',
30+
});
31+
3132
export type VirtualListItemProps = {
3233
style?: CSSProperties;
3334
};
3435

3536
export const ExpandButton: React.FunctionComponent<{
3637
onClick: React.MouseEventHandler<HTMLButtonElement>;
3738
isExpanded: boolean;
38-
}> = ({ onClick, isExpanded }) => {
39+
disabled?: boolean;
40+
}> = ({ onClick, isExpanded, disabled = false }) => {
3941
return (
4042
<button
4143
type="button"
@@ -46,7 +48,11 @@ export const ExpandButton: React.FunctionComponent<{
4648
// using a mouse
4749
tabIndex={-1}
4850
onClick={onClick}
49-
className={cx(buttonReset, expandButton, isExpanded && expanded)}
51+
className={cx(buttonReset, expandButton, {
52+
[expandedStyles]: isExpanded,
53+
[enabledStyles]: !disabled,
54+
})}
55+
disabled={disabled}
5056
>
5157
<Icon width={14} height={14} glyph="CaretRight" size="small"></Icon>
5258
</button>

0 commit comments

Comments
 (0)