Skip to content

Commit 5a95c13

Browse files
committed
Merge branch 'main' into 1.29-releases
2 parents e91dfb7 + 044b1af commit 5a95c13

File tree

7 files changed

+123
-13
lines changed

7 files changed

+123
-13
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 **compass**.
2-
This document was automatically generated on Fri Dec 03 2021.
2+
This document was automatically generated on Sun Dec 12 2021.
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.

packages/ace-theme-query/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ color: #999999;\
1212
background: #ffffff;\
1313
color: #000;\
1414
}\
15+
.ace-mongodb-query .ace_placeholder {\
16+
font-family: inherit;\
17+
transform: none;\
18+
opacity: 1;\
19+
margin: 0;\
20+
}\
1521
.ace-mongodb-query .ace_keyword {\
1622
color: #999999;\
1723
font-weight: normal;\

packages/compass-home/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"react-dom": "^16.14.0",
8080
"resolve": "^1.15.1",
8181
"rimraf": "^3.0.2",
82+
"sinon": "^8.1.1",
8283
"xvfb-maybe": "^0.2.1"
8384
},
8485
"homepage": "https://github.com/mongodb-js/compass",

packages/compass-home/src/components/home.spec.tsx

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { cleanup, render, screen, waitFor } from '@testing-library/react';
33
import { expect } from 'chai';
44
import AppRegistry from 'hadron-app-registry';
55
import InstanceModel from 'mongodb-instance-model';
6+
import ipc from 'hadron-ipc';
7+
import sinon from 'sinon';
68

79
import AppRegistryContext from '../contexts/app-registry-context';
810
import Home from '.';
@@ -178,9 +180,14 @@ describe('Home [Component]', function () {
178180
});
179181

180182
describe('UI status is complete', function () {
183+
let dataServiceDisconnectedSpy: sinon.SinonSpy;
181184
beforeEach(async function () {
182185
const instance = createInstance();
183-
await renderHome(createDataService(), instance);
186+
dataServiceDisconnectedSpy = sinon.fake.resolves(true);
187+
const dataService = {
188+
disconnect: dataServiceDisconnectedSpy,
189+
};
190+
await renderHome(dataService, instance);
184191
instance.set({ status: 'ready', refreshingStatus: 'ready' });
185192
await waitFor(() => screen.getByTestId('test-Instance.Workspace'));
186193
});
@@ -298,6 +305,72 @@ describe('Home [Component]', function () {
298305
});
299306
});
300307
});
308+
309+
describe('with the new connect form (USE_NEW_CONNECT_FORM=true) and UI status is complete', function () {
310+
let dataServiceDisconnectedSpy: sinon.SinonSpy;
311+
let listenForDisconnectFake: sinon.SinonSpy;
312+
313+
beforeEach(async function () {
314+
process.env.USE_NEW_CONNECT_FORM = 'true';
315+
316+
const instance = createInstance();
317+
listenForDisconnectFake = sinon.fake();
318+
testAppRegistry.on(
319+
'data-service-disconnected',
320+
listenForDisconnectFake
321+
);
322+
dataServiceDisconnectedSpy = sinon.fake.resolves(true);
323+
const dataService = {
324+
disconnect: dataServiceDisconnectedSpy,
325+
};
326+
await renderHome(dataService, instance);
327+
instance.set({ status: 'ready', refreshingStatus: 'ready' });
328+
await waitFor(() => screen.getByTestId('test-Instance.Workspace'));
329+
});
330+
331+
afterEach(function () {
332+
delete process.env.USE_NEW_CONNECT_FORM;
333+
testAppRegistry.removeListener(
334+
'data-service-disconnected',
335+
listenForDisconnectFake
336+
);
337+
sinon.restore();
338+
});
339+
340+
describe('on `app:disconnect`', function () {
341+
// Skip disconnect testing when we're not running in a renderer instance.
342+
// eslint-disable-next-line mocha/no-setup-in-describe
343+
if (!ipc.ipcRenderer) {
344+
// eslint-disable-next-line mocha/no-setup-in-describe
345+
console.warn(
346+
'Skipping "app:disconnect" ipc event tests on non-renderer environment.'
347+
);
348+
return;
349+
}
350+
351+
beforeEach(function () {
352+
ipc.ipcRenderer.emit('app:disconnect');
353+
});
354+
355+
it('calls `data-service-disconnected`', async function () {
356+
await waitFor(() =>
357+
expect(listenForDisconnectFake.callCount).to.equal(1)
358+
);
359+
});
360+
361+
it('renders the new connect form', async function () {
362+
await waitFor(
363+
() => expect(screen.queryByTestId('new-connect-form')).to.be.visible
364+
);
365+
});
366+
367+
it('calls to disconnect the data service', async function () {
368+
await waitFor(() =>
369+
expect(dataServiceDisconnectedSpy.callCount).to.equal(1)
370+
);
371+
});
372+
});
373+
});
301374
});
302375

303376
describe('when rendered', function () {

packages/compass-home/src/components/home.tsx

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { css } from '@emotion/css';
2-
import React, { useCallback, useEffect, useReducer } from 'react';
2+
import React, { useCallback, useEffect, useReducer, useRef } from 'react';
33
import {
44
ConnectionInfo,
55
DataService,
@@ -19,6 +19,7 @@ import {
1919
useAppRegistryRole,
2020
} from '../contexts/app-registry-context';
2121
import updateTitle from '../modules/update-title';
22+
import ipc from 'hadron-ipc';
2223

2324
const homeViewStyles = css({
2425
display: 'flex',
@@ -124,16 +125,14 @@ function reducer(state: State, action: Action): State {
124125
}
125126

126127
function hideCollectionSubMenu() {
127-
void import('hadron-ipc').then(({ ipcRenderer }) => {
128-
if (ipcRenderer) {
129-
ipcRenderer.call('window:hide-collection-submenu');
130-
}
131-
});
128+
void ipc.ipcRenderer?.call('window:hide-collection-submenu');
132129
}
133130

134131
function Home({ appName }: { appName: string }): React.ReactElement | null {
135132
const appRegistry = useAppRegistryContext();
136133
const connectRole = useAppRegistryRole(AppRegistryRoles.APPLICATION_CONNECT);
134+
const connectedDataService = useRef<DataService>();
135+
const showNewConnectForm = process.env.USE_NEW_CONNECT_FORM === 'true';
137136

138137
const [
139138
{
@@ -152,6 +151,7 @@ function Home({ appName }: { appName: string }): React.ReactElement | null {
152151
ds: DataService,
153152
connectionInfo: ConnectionInfo
154153
) {
154+
connectedDataService.current = ds;
155155
dispatch({
156156
type: 'connected',
157157
connectionTitle: getConnectionTitle(connectionInfo) || '',
@@ -282,7 +282,37 @@ function Home({ appName }: { appName: string }): React.ReactElement | null {
282282
}, [isConnected, appName, connectionTitle, namespace]);
283283

284284
useEffect(() => {
285-
// Setup listeners.
285+
async function handleDisconnectClicked() {
286+
if (!connectedDataService.current) {
287+
// We aren't connected.
288+
return;
289+
}
290+
291+
await connectedDataService.current.disconnect();
292+
connectedDataService.current = undefined;
293+
294+
appRegistry.emit('data-service-disconnected');
295+
}
296+
297+
function onDisconnect() {
298+
void handleDisconnectClicked();
299+
}
300+
301+
// TODO: Once we merge https://jira.mongodb.org/browse/COMPASS-5302
302+
// we can remove this check and handle the disconnect event here by default.
303+
if (showNewConnectForm) {
304+
// Setup ipc listener.
305+
ipc.ipcRenderer?.on('app:disconnect', onDisconnect);
306+
307+
return () => {
308+
// Clean up the ipc listener.
309+
ipc.ipcRenderer?.removeListener('app:disconnect', onDisconnect);
310+
};
311+
}
312+
}, [appRegistry, showNewConnectForm, onDataServiceDisconnected]);
313+
314+
useEffect(() => {
315+
// Setup app registry listeners.
286316
appRegistry.on('instance-created', onInstanceCreated);
287317
appRegistry.on('data-service-connected', onDataServiceConnected);
288318
appRegistry.on('data-service-disconnected', onDataServiceDisconnected);
@@ -293,7 +323,7 @@ function Home({ appName }: { appName: string }): React.ReactElement | null {
293323
appRegistry.on('all-collection-tabs-closed', onAllTabsClosed);
294324

295325
return () => {
296-
// Clean up the listeners.
326+
// Clean up the app registry listeners.
297327
appRegistry.removeListener('instance-created', onInstanceCreated);
298328
appRegistry.removeListener(
299329
'data-service-connected',
@@ -325,8 +355,6 @@ function Home({ appName }: { appName: string }): React.ReactElement | null {
325355
);
326356
}
327357

328-
const showNewConnectForm = process.env.USE_NEW_CONNECT_FORM === 'true';
329-
330358
if (showNewConnectForm) {
331359
return (
332360
<div className={homeViewStyles} data-test-id="home-view">

packages/connect-form/src/connect-form.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function ConnectForm({
5959
);
6060

6161
return (
62-
<div className={formContainerStyles}>
62+
<div className={formContainerStyles} data-testid="new-connect-form">
6363
<Card className={formCardStyles}>
6464
<div className={formContentContainerStyles}>
6565
<H3>New Connection</H3>

0 commit comments

Comments
 (0)