Skip to content

Commit 49a4f57

Browse files
Merge remote-tracking branch 'origin/main' into beta-releases
2 parents b313df7 + fb6e702 commit 49a4f57

File tree

16 files changed

+631
-125
lines changed

16 files changed

+631
-125
lines changed

THIRD-PARTY-NOTICES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
The following third-party software is used by and included in **Mongodb Compass**.
2-
This document was automatically generated on Fri Nov 24 2023.
2+
This document was automatically generated on Sun Nov 26 2023.
33

44
## List of dependencies
55

package-lock.json

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import React from 'react';
2+
import { Link } from './leafygreen';
3+
import { css } from '@leafygreen-ui/emotion';
4+
5+
const toastBodyFlexStyles = css({
6+
display: 'flex',
7+
flexDirection: 'row',
8+
});
9+
10+
const toastBodyTextStyles = css({
11+
flexGrow: 1,
12+
});
13+
14+
const toastActionStyles = css({
15+
textTransform: 'uppercase',
16+
flexGrow: 0,
17+
alignSelf: 'center',
18+
19+
// Remove button styles.
20+
border: 'none',
21+
padding: 0,
22+
margin: 0,
23+
background: 'none',
24+
});
25+
26+
export function ToastBody({
27+
statusMessage,
28+
actionHandler,
29+
actionText,
30+
}: {
31+
statusMessage: string;
32+
actionHandler?: () => void;
33+
actionText?: string;
34+
}) {
35+
return (
36+
<div className={toastBodyFlexStyles}>
37+
<p className={toastBodyTextStyles}>{statusMessage}</p>
38+
{!!actionHandler && (
39+
<Link
40+
as="button"
41+
data-testid={`toast-action-${actionText ?? 'none'}`}
42+
onClick={actionHandler}
43+
hideExternalIcon
44+
className={toastActionStyles}
45+
>
46+
{actionText}
47+
</Link>
48+
)}
49+
</div>
50+
);
51+
}

packages/compass-components/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,4 @@ export { usePersistedState } from './hooks/use-persisted-state';
183183
export { GuideCue, GuideCueProvider } from './components/guide-cue/guide-cue';
184184
export type { Cue, GroupCue } from './components/guide-cue/guide-cue';
185185
export { PerformanceSignals } from './components/signals';
186+
export { ToastBody } from './components/toast-body';

packages/compass-connections/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
"@mongodb-js/tsconfig-compass": "^1.0.3",
7676
"@testing-library/react": "^12.1.4",
7777
"@testing-library/react-hooks": "^7.0.2",
78+
"@testing-library/user-event": "^13.5.0",
7879
"@types/chai": "^4.2.21",
7980
"@types/chai-dom": "^0.0.10",
8081
"@types/mocha": "^9.0.0",

packages/compass-connections/src/components/connection-list/connection-list.spec.tsx

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
waitFor,
77
cleanup,
88
} from '@testing-library/react';
9+
import userEvent from '@testing-library/user-event';
910
import { expect } from 'chai';
1011
import sinon from 'sinon';
1112
import type { ConnectionInfo } from '@mongodb-js/connection-storage/renderer';
@@ -113,6 +114,68 @@ describe('ConnectionList Component', function () {
113114
const listItems = screen.getAllByTestId('recent-connection');
114115
expect(listItems.length).to.equal(mockRecents.length);
115116
});
117+
118+
it('does not show the saved connections filter input', function () {
119+
const filter = screen.queryByTestId(
120+
'sidebar-filter-saved-connections-input'
121+
);
122+
expect(filter).to.not.exist;
123+
});
124+
});
125+
126+
describe('with more than 10 favorite connections', function () {
127+
beforeEach(function () {
128+
const favorites = [
129+
...mockFavorites,
130+
...mockFavorites.map((favorite) => ({
131+
...favorite,
132+
id: favorite.id + '__1',
133+
})),
134+
...mockFavorites.map((favorite) => ({
135+
...favorite,
136+
id: favorite.id + '__2',
137+
})),
138+
...mockFavorites.map((favorite) => ({
139+
...favorite,
140+
id: favorite.id + '__3',
141+
})),
142+
];
143+
render(
144+
<ConnectionList
145+
activeConnectionId={mockFavorites[2].id}
146+
favoriteConnections={favorites}
147+
recentConnections={mockRecents}
148+
createNewConnection={createNewConnectionSpy}
149+
setActiveConnectionId={setActiveConnectionIdSpy}
150+
removeAllRecentsConnections={() => true}
151+
onDoubleClick={() => true}
152+
/>
153+
);
154+
});
155+
156+
it('shows the saved connections filter input', function () {
157+
expect(screen.getByTestId('sidebar-filter-saved-connections-input')).to.be
158+
.visible;
159+
expect(
160+
screen.getAllByTestId('favorite-connection-title').length
161+
).to.equal(12);
162+
});
163+
164+
describe('when the saved connections filter input is updated', function () {
165+
beforeEach(function () {
166+
const textInput = screen.getByTestId(
167+
'sidebar-filter-saved-connections-input'
168+
);
169+
170+
userEvent.type(textInput, 'super');
171+
});
172+
173+
it('only shows the partial favorite connections', function () {
174+
expect(
175+
screen.getAllByTestId('favorite-connection-title').length
176+
).to.equal(4);
177+
});
178+
});
116179
});
117180

118181
describe('when new connection is clicked', function () {

packages/compass-connections/src/components/connection-list/connection-list.tsx

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { Fragment } from 'react';
1+
import React, { Fragment, useMemo, useState } from 'react';
22
import {
33
Button,
44
FavoriteIcon,
@@ -18,11 +18,16 @@ import type AppRegistry from 'hadron-app-registry';
1818

1919
import Connection from './connection';
2020
import ConnectionsTitle from './connections-title';
21+
import { TextInput } from '@mongodb-js/compass-components';
2122

2223
const newConnectionButtonContainerStyles = css({
2324
padding: spacing[3],
2425
});
2526

27+
const savedConnectionsFilter = css({
28+
margin: `${spacing[2]}px ${spacing[3]}px`,
29+
});
30+
2631
const newConnectionButtonStyles = css({
2732
width: '100%',
2833
justifyContent: 'center',
@@ -89,6 +94,8 @@ const connectionListStyles = css({
8994
padding: 0,
9095
});
9196

97+
const MIN_FAV_CONNECTIONS_TO_SHOW_FILTER = 10;
98+
9299
function RecentIcon() {
93100
const darkMode = useDarkMode();
94101

@@ -163,6 +170,22 @@ function ConnectionList({
163170
const [recentHoverProps, recentHeaderHover] = useHoverState();
164171
const [favoriteHoverProps, favoriteHeaderHover] = useHoverState();
165172

173+
const [favoriteConnectionsFilter, setSavedConnectionsFilter] = useState('');
174+
175+
const filteredSavedConnections = useMemo(() => {
176+
if (!favoriteConnectionsFilter) {
177+
return favoriteConnections;
178+
}
179+
180+
return favoriteConnections.filter((connection) =>
181+
connection.favorite?.name
182+
?.toLowerCase()
183+
.includes(favoriteConnectionsFilter.toLowerCase())
184+
);
185+
}, [favoriteConnections, favoriteConnectionsFilter]);
186+
const showFilteredSavedConnections =
187+
favoriteConnections.length > MIN_FAV_CONNECTIONS_TO_SHOW_FILTER;
188+
166189
return (
167190
<Fragment>
168191
<ConnectionsTitle
@@ -211,8 +234,24 @@ function ConnectionList({
211234
isVisible={favoriteHeaderHover}
212235
></ItemActionControls>
213236
</div>
237+
{showFilteredSavedConnections && (
238+
<TextInput
239+
data-testid="sidebar-filter-saved-connections-input"
240+
placeholder="Search"
241+
type="search"
242+
aria-label="Saved connections filter"
243+
title="Saved connections filter"
244+
onChange={(e: React.ChangeEvent<HTMLInputElement>) =>
245+
setSavedConnectionsFilter(e.target.value)
246+
}
247+
className={savedConnectionsFilter}
248+
/>
249+
)}
214250
<ul className={connectionListStyles}>
215-
{favoriteConnections.map((connectionInfo, index) => (
251+
{(showFilteredSavedConnections
252+
? filteredSavedConnections
253+
: favoriteConnections
254+
).map((connectionInfo, index) => (
216255
<li
217256
data-testid="favorite-connection"
218257
data-id={`favorite-connection-${

0 commit comments

Comments
 (0)