Skip to content

Commit 3ef6576

Browse files
committed
Show icon button to the right of NavigationItemsFilter
1 parent 452d0f0 commit 3ef6576

File tree

3 files changed

+57
-10
lines changed

3 files changed

+57
-10
lines changed

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

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import {
1212
Button,
1313
Icon,
1414
ButtonVariant,
15+
IconButton,
16+
ConnectedPlugsIcon,
17+
DisconnectedPlugIcon,
18+
Tooltip,
1519
} from '@mongodb-js/compass-components';
1620
import { ConnectionsNavigationTree } from '@mongodb-js/compass-connections-navigation';
1721
import type { MapDispatchToProps, MapStateToProps } from 'react-redux';
@@ -80,11 +84,19 @@ const connectionCountStyles = css({
8084
marginLeft: spacing[100],
8185
});
8286

83-
const searchStyles = css({
87+
const filterContainerStyles = css({
88+
display: 'flex',
89+
flexDirection: 'row',
90+
alignItems: 'center',
91+
gap: spacing[200],
8492
paddingLeft: spacing[400],
8593
paddingRight: spacing[400],
8694
});
8795

96+
const searchFormStyles = css({
97+
flexGrow: 1,
98+
});
99+
88100
const noDeploymentStyles = css({
89101
paddingLeft: spacing[400],
90102
paddingRight: spacing[400],
@@ -112,7 +124,9 @@ type ConnectionsNavigationComponentProps = {
112124
connectionsWithStatus: ReturnType<typeof useConnectionsWithStatus>;
113125
activeWorkspace: WorkspaceTab | null;
114126
filterRegex: RegExp | null;
127+
excludeInactive: boolean;
115128
onFilterChange(regex: RegExp | null): void;
129+
onToggleExcludeInactive(): void;
116130
onConnect(info: ConnectionInfo): void;
117131
onNewConnection(): void;
118132
onEditConnection(info: ConnectionInfo): void;
@@ -154,10 +168,12 @@ const ConnectionsNavigation: React.FC<ConnectionsNavigationProps> = ({
154168
connectionsWithStatus,
155169
activeWorkspace,
156170
filterRegex,
171+
excludeInactive,
157172
instances,
158173
databases,
159174
isPerformanceTabSupported,
160175
onFilterChange,
176+
onToggleExcludeInactive,
161177
onConnect,
162178
onNewConnection,
163179
onEditConnection,
@@ -502,11 +518,37 @@ const ConnectionsNavigation: React.FC<ConnectionsNavigationProps> = ({
502518
</div>
503519
{connections.length > 0 && (
504520
<>
505-
<NavigationItemsFilter
506-
searchInputClassName={searchStyles}
507-
placeholder="Search connections"
508-
onFilterChange={onFilterChange}
509-
/>
521+
<div className={filterContainerStyles}>
522+
<NavigationItemsFilter
523+
className={searchFormStyles}
524+
placeholder="Search connections"
525+
onFilterChange={onFilterChange}
526+
/>
527+
<Tooltip
528+
justify="middle"
529+
align="bottom"
530+
trigger={
531+
<IconButton
532+
onClick={onToggleExcludeInactive}
533+
aria-label={
534+
excludeInactive
535+
? 'Showing active connections'
536+
: 'Showing all connections'
537+
}
538+
>
539+
{excludeInactive ? (
540+
<ConnectedPlugsIcon />
541+
) : (
542+
<DisconnectedPlugIcon />
543+
)}
544+
</IconButton>
545+
}
546+
>
547+
{excludeInactive
548+
? 'Showing active connections'
549+
: 'Showing all connections'}
550+
</Tooltip>
551+
</div>
510552
<ConnectionsNavigationTree
511553
connections={filtered || connections}
512554
activeWorkspace={activeWorkspace}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ export function MultipleConnectionSidebar({
103103
useState<RegExp | null>(null);
104104
const [connectionInfoModalConnectionId, setConnectionInfoModalConnectionId] =
105105
useState<string | undefined>();
106+
const [excludeInactive, setExcludeInactiveConnections] = useState(false);
107+
const toggleExcludeInactiveConnections = useCallback(() => {
108+
setExcludeInactiveConnections((previous) => !previous);
109+
}, []);
106110

107111
const formPreferences = useConnectionFormPreferences();
108112
const maybeProtectConnectionString = useMaybeProtectConnectionString();
@@ -204,7 +208,9 @@ export function MultipleConnectionSidebar({
204208
connectionsWithStatus={connectionsWithStatus}
205209
activeWorkspace={activeWorkspace}
206210
filterRegex={activeConnectionsFilterRegex}
211+
excludeInactive={excludeInactive}
207212
onFilterChange={onActiveConnectionFilterChange}
213+
onToggleExcludeInactive={toggleExcludeInactiveConnections}
208214
onConnect={(connectionInfo) => {
209215
void connect(connectionInfo);
210216
}}

packages/compass-sidebar/src/components/navigation-items-filter.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ export default function NavigationItemsFilter({
66
ariaLabel = 'Search',
77
title = 'Search',
88
onFilterChange,
9-
searchInputClassName,
9+
className,
1010
}: {
1111
placeholder?: string;
1212
ariaLabel?: string;
1313
title?: string;
14-
searchInputClassName?: string;
1514
onFilterChange(regex: RegExp | null): void;
15+
className?: string;
1616
}): React.ReactElement {
1717
const onChange = useCallback(
1818
(event) => {
@@ -37,15 +37,14 @@ export default function NavigationItemsFilter({
3737
}, []);
3838

3939
return (
40-
<form noValidate onSubmit={onSubmit}>
40+
<form noValidate className={className} onSubmit={onSubmit}>
4141
<TextInput
4242
data-testid="sidebar-filter-input"
4343
placeholder={placeholder}
4444
type="search"
4545
aria-label={ariaLabel}
4646
title={title}
4747
onChange={onChange}
48-
className={searchInputClassName}
4948
/>
5049
</form>
5150
);

0 commit comments

Comments
 (0)