Skip to content

Commit f900d70

Browse files
authored
feat(connect-form): Add connection string input COMPASS-4902 (#2544)
1 parent 947980a commit f900d70

File tree

15 files changed

+949
-80
lines changed

15 files changed

+949
-80
lines changed

package-lock.json

Lines changed: 326 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-components/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,19 @@
3636
"dependencies": {
3737
"@leafygreen-ui/badge": "^4.0.4",
3838
"@leafygreen-ui/banner": "^3.0.8",
39-
"@leafygreen-ui/button": "^12.0.3",
39+
"@leafygreen-ui/button": "^12.0.5",
4040
"@leafygreen-ui/card": "^5.1.3",
4141
"@leafygreen-ui/checkbox": "^6.0.5",
4242
"@leafygreen-ui/confirmation-modal": "^2.2.1",
4343
"@leafygreen-ui/icon": "^11.4.0",
4444
"@leafygreen-ui/icon-button": "^9.1.5",
4545
"@leafygreen-ui/leafygreen-provider": "^2.1.2",
46-
"@leafygreen-ui/logo": "^5.0.0",
46+
"@leafygreen-ui/logo": "^6.1.0",
47+
"@leafygreen-ui/palette": "^3.2.2",
4748
"@leafygreen-ui/portal": "^3.1.3",
4849
"@leafygreen-ui/select": "^3.0.4",
4950
"@leafygreen-ui/tabs": "^5.1.3",
51+
"@leafygreen-ui/text-area": "^4.0.3",
5052
"@leafygreen-ui/text-input": "^6.0.3",
5153
"@leafygreen-ui/toggle": "^7.0.4",
5254
"@leafygreen-ui/tokens": "^0.5.3",

packages/compass-components/src/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,20 @@ export { default as Checkbox } from '@leafygreen-ui/checkbox';
1919
export { default as Icon } from '@leafygreen-ui/icon';
2020
export { default as IconButton } from '@leafygreen-ui/icon-button';
2121
export { default as LeafyGreenProvider } from '@leafygreen-ui/leafygreen-provider';
22-
export { AtlasLogoMark, LogoMark } from '@leafygreen-ui/logo';
22+
export {
23+
AtlasLogoMark,
24+
MongoDBLogoMark,
25+
MongoDBLogo,
26+
} from '@leafygreen-ui/logo';
27+
export { uiColors } from '@leafygreen-ui/palette';
2328
export { default as Portal } from '@leafygreen-ui/portal';
2429
export { Select, Option, Size as SelectSize } from '@leafygreen-ui/select';
2530
export { Tabs, Tab } from '@leafygreen-ui/tabs';
31+
export { default as TextArea } from '@leafygreen-ui/text-area';
2632
export { default as TextInput } from '@leafygreen-ui/text-input';
2733
export { default as Toggle } from '@leafygreen-ui/toggle';
2834
export { spacing } from '@leafygreen-ui/tokens';
2935
export { default as Tooltip } from '@leafygreen-ui/tooltip';
30-
export { H2, Link } from '@leafygreen-ui/typography';
36+
export { H3, Link, Description, Label } from '@leafygreen-ui/typography';
3137

3238
export { CancelLoader, ConfirmationModal, ResizeHandle, ResizeDirection };

packages/compass-connect/src/components/connect.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
44
import React from 'react';
55
import { Link } from '@mongodb-js/compass-components';
66
import ConnectForm from '@mongodb-js/connect-form';
7+
import { convertConnectionModelToInfo } from 'mongodb-data-service';
78

89
import Actions from '../actions';
910
import Sidebar from './sidebar';
@@ -145,13 +146,15 @@ class Connect extends React.Component {
145146
className={classnames(styles.page, styles.connect)}
146147
>
147148
<Sidebar {...this.props} />
148-
<div className={classnames(styles['form-container'])}>
149+
<div className={styles['form-container']}>
149150
{showNewConnectForm && <ConnectForm
151+
key={this.props.connectionModel._id}
152+
initialConnectionInfo={convertConnectionModelToInfo(this.props.connectionModel)}
150153
onConnectClicked={() => Actions.onConnectClicked()}
151154
/>}
152155
{!showNewConnectForm && (
153156
<div
154-
className={classnames(styles['connect-container'])}
157+
className={styles['connect-container']}
155158
onMouseMove={this.handleMouseMove.bind(this)}
156159
>
157160
{this.renderHeader()}

packages/compass-connect/src/components/connect.module.less

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,6 @@
1111
}
1212

1313
.connect {
14-
form {
15-
display: block;
16-
margin-top: 0em;
17-
background-color: white;
18-
box-shadow: 0 2px 10px 0 rgba(0, 0, 0, 0.075);
19-
padding: 15px 0;
20-
}
21-
22-
label {
23-
display: inline-block;
24-
max-width: 100%;
25-
margin-bottom: 5px;
26-
font-weight: bold;
27-
}
28-
2914
&-atlas {
3015
background: @compass-sidebar-atlas-background-color;
3116
display: flex;
@@ -103,6 +88,21 @@
10388
min-width: 360px;
10489
max-width: 800px;
10590

91+
form {
92+
display: block;
93+
margin-top: 0em;
94+
background-color: white;
95+
box-shadow: 0 2px 10px 0 rgba(0, 0, 0, 0.075);
96+
padding: 15px 0;
97+
}
98+
99+
label {
100+
display: inline-block;
101+
max-width: 100%;
102+
margin-bottom: 5px;
103+
font-weight: bold;
104+
}
105+
106106
.connect-string {
107107
margin: 10px;
108108

packages/compass-sidebar/src/components/sidebar-title/sidebar-title.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
33
import classnames from 'classnames';
44
import { connect } from 'react-redux';
55
import {
6-
LogoMark
6+
MongoDBLogoMark
77
} from '@mongodb-js/compass-components';
88

99
import {
@@ -54,7 +54,7 @@ class SidebarTitle extends PureComponent {
5454
} : {}}
5555
className={styles['sidebar-title-logo']}
5656
>
57-
<LogoMark
57+
<MongoDBLogoMark
5858
darkMode
5959
knockout
6060
/>

packages/connect-form/.depcheckrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ ignores:
33
- "@mongodb-js/tsconfig-compass"
44
- "@types/chai"
55
- "@types/sinon-chai"
6-
- "sinon"
76
- "@types/chai-dom"
87
- "@types/react"
98
- "@types/react-dom"

packages/connect-form/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"react-dom": "*"
5353
},
5454
"dependencies": {
55+
"mongodb-connection-string-url": "^2.1.0",
5556
"react": "^16.14.0",
5657
"react-dom": "^16.14.0"
5758
},
@@ -74,6 +75,7 @@
7475
"eslint": "^7.25.0",
7576
"gen-esm-wrapper": "^1.1.0",
7677
"mocha": "^8.4.0",
78+
"mongodb-data-service": "^21.12.0",
7779
"nyc": "^15.1.0",
7880
"prettier": "2.3.2",
7981
"sinon": "^9.2.3",
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import React from 'react';
2+
import { cleanup, render, screen, fireEvent } from '@testing-library/react';
3+
import { expect } from 'chai';
4+
import sinon from 'sinon';
5+
6+
import ConfirmEditConnectionStringModal from './confirm-edit-connection-string';
7+
8+
function renderModal(onCancel: () => void, onConfirm: () => void) {
9+
return render(
10+
<ConfirmEditConnectionStringModal
11+
onCancel={onCancel}
12+
onConfirm={onConfirm}
13+
open
14+
/>
15+
);
16+
}
17+
18+
describe('ConfirmationModal Component', function () {
19+
let onConfirmSpy;
20+
let onCancelSpy;
21+
beforeEach(function () {
22+
onConfirmSpy = sinon.spy();
23+
onCancelSpy = sinon.spy();
24+
25+
renderModal(onCancelSpy, onConfirmSpy);
26+
});
27+
28+
afterEach(function () {
29+
onConfirmSpy = null;
30+
onCancelSpy = null;
31+
cleanup(); // Modals can sometimes leave behind animations and focus traps.
32+
});
33+
34+
it('should show the modal heading', function () {
35+
expect(screen.getByRole('heading')).to.have.text(
36+
'Are you sure you want to edit your connection string?'
37+
);
38+
});
39+
40+
it('should show the modal button', function () {
41+
const button = screen.getByText('Confirm').closest('button');
42+
expect(button).to.not.match('disabled');
43+
});
44+
45+
it('should show the modal content', function () {
46+
const innerContent = screen.getByTestId('edit-uri-note');
47+
expect(innerContent).to.have.text(
48+
'Editing this connection string will reveal your credentials.'
49+
);
50+
expect(innerContent).to.be.visible;
51+
});
52+
53+
it('calls the onConfirm prop when confirm is clicked', function () {
54+
const button = screen.getByText('Confirm').closest('button');
55+
56+
expect(onConfirmSpy.called).to.equal(false);
57+
58+
fireEvent(
59+
button,
60+
new MouseEvent('click', {
61+
bubbles: true,
62+
cancelable: true,
63+
})
64+
);
65+
66+
expect(onConfirmSpy.called).to.equal(true);
67+
expect(onCancelSpy.called).to.equal(false);
68+
});
69+
70+
it('calls the onCancel prop when close is clicked', function () {
71+
const button = screen.getByText('Cancel').closest('button');
72+
73+
expect(onCancelSpy.called).to.equal(false);
74+
75+
fireEvent(
76+
button,
77+
new MouseEvent('click', {
78+
bubbles: true,
79+
cancelable: true,
80+
})
81+
);
82+
83+
expect(onCancelSpy.called).to.equal(true);
84+
expect(onConfirmSpy.called).to.equal(false);
85+
});
86+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from 'react';
2+
import { ConfirmationModal } from '@mongodb-js/compass-components';
3+
4+
function ConfirmEditConnectionString({
5+
onCancel,
6+
onConfirm,
7+
open,
8+
}: {
9+
onCancel: () => void;
10+
onConfirm: () => void;
11+
open: boolean;
12+
}): React.ReactElement {
13+
return (
14+
<ConfirmationModal
15+
title="Are you sure you want to edit your connection string?"
16+
open={open}
17+
onConfirm={onConfirm}
18+
onCancel={onCancel}
19+
buttonText="Confirm"
20+
>
21+
<div data-testid="edit-uri-note">
22+
Editing this connection string will reveal your credentials.
23+
</div>
24+
</ConfirmationModal>
25+
);
26+
}
27+
28+
export default ConfirmEditConnectionString;

0 commit comments

Comments
 (0)