Skip to content

Commit 403e8e3

Browse files
authored
feature: adapt the connection form component to the new design guidelines COMPASS-7652 (#5514)
* new design * chore: put the new color palette under the feature toggle * chore: interact with the form * chore: use glyphs on the option * chore: checking why it resets * chore: fixed wierd behaviour of useReducer * chore: can save connections * chore: add test to reducer * chore: fix the connect button * chore: add todo marker * chore: add tests to the form * chore: linting issues * chore: linting issues * chore: fix typing issues * chore: add tests to color names * chore: remove exclusive test * chore: linting issues * chore: package.json merge conflict * chore: update package-lock * chore: fix tests * chore: beware of race conditions * chore: fix tests * chore: be pretty * chore: move to inner scope * chore: fix copy
1 parent 2a270bd commit 403e8e3

File tree

10 files changed

+733
-64
lines changed

10 files changed

+733
-64
lines changed

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-components/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ export {
136136
} from './components/content-with-fallback';
137137
export { InlineDefinition } from './components/inline-definition';
138138
import type { glyphs } from '@leafygreen-ui/icon';
139+
export { createGlyphComponent, createIconComponent } from '@leafygreen-ui/icon';
139140
export {
140141
SignalPopover,
141142
SignalHooksProvider,

packages/connection-form/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"peerDependencies": {
5050
"@mongodb-js/compass-components": "^1.22.1",
5151
"@mongodb-js/compass-editor": "^0.21.1",
52+
"compass-preferences-model": "^2.11.1",
5253
"react": "^17.0.2"
5354
},
5455
"dependencies": {

packages/connection-form/src/components/connection-form-actions.tsx

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,71 @@ function ConnectFormActions({
118118
);
119119
}
120120

121+
export type ConnectionFormModalActionsProps = {
122+
errors: ConnectionFormError[];
123+
warnings: ConnectionFormWarning[];
124+
125+
onCancel(): void;
126+
onSave(): void;
127+
onConnect(): void;
128+
};
129+
130+
export function ConnectionFormModalActions({
131+
errors,
132+
warnings,
133+
onCancel,
134+
onSave,
135+
onConnect,
136+
}: ConnectionFormModalActionsProps): React.ReactElement {
137+
return (
138+
<div className={cx(formActionStyles)}>
139+
{warnings.length > 0 && (
140+
<div className={formActionItemStyles}>
141+
<WarningSummary
142+
data-testid="connection-warnings-summary"
143+
warnings={warnings.map((warning) => warning.message)}
144+
/>
145+
</div>
146+
)}
147+
{errors.length > 0 && (
148+
<div className={formActionItemStyles}>
149+
<ErrorSummary
150+
data-testid="connection-error-summary"
151+
errors={errors.map((error) => error.message)}
152+
/>
153+
</div>
154+
)}
155+
<div className={cx(formActionItemStyles, formActionButtonsStyles)}>
156+
<Button
157+
data-testid="save-connection-button"
158+
variant={ButtonVariant.Default}
159+
disabled={false}
160+
onClick={onCancel}
161+
>
162+
Cancel
163+
</Button>
164+
165+
<div className={saveAndConnectStyles}>
166+
<Button
167+
data-testid="save-and-connect-button"
168+
variant={ButtonVariant.PrimaryOutline}
169+
disabled={false}
170+
onClick={onSave}
171+
>
172+
Save
173+
</Button>
174+
</div>
175+
176+
<Button
177+
data-testid="connect-button"
178+
variant={ButtonVariant.Primary}
179+
onClick={onConnect}
180+
>
181+
Connect
182+
</Button>
183+
</div>
184+
</div>
185+
);
186+
}
187+
121188
export default ConnectFormActions;

packages/connection-form/src/components/connection-form.spec.tsx

Lines changed: 97 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ import {
55
cleanup,
66
fireEvent,
77
getByText,
8+
waitFor,
89
} from '@testing-library/react';
10+
import userEvent from '@testing-library/user-event';
911
import { expect } from 'chai';
10-
12+
import type { PreferencesAccess } from 'compass-preferences-model';
13+
import { createSandboxFromDefaultPreferences } from 'compass-preferences-model';
14+
import { PreferencesProvider } from 'compass-preferences-model/provider';
1115
import ConnectionForm from './connection-form';
1216
import type { ConnectionFormProps } from './connection-form';
1317
import Sinon from 'sinon';
@@ -28,23 +32,31 @@ const noop = (): any => {
2832
const saveAndConnectText = 'Save & Connect';
2933
const favoriteText = 'FAVORITE';
3034

31-
function renderForm(props: Partial<ConnectionFormProps> = {}) {
32-
return render(
33-
<ConnectionForm
34-
onConnectClicked={noop}
35-
initialConnectionInfo={{
36-
id: 'test',
37-
connectionOptions: {
38-
connectionString: 'mongodb://pineapple:orangutans@localhost:27019',
39-
},
40-
}}
41-
onSaveConnectionClicked={noop}
42-
{...props}
43-
/>
44-
);
45-
}
46-
4735
describe('ConnectionForm Component', function () {
36+
let preferences: PreferencesAccess;
37+
function renderForm(props: Partial<ConnectionFormProps> = {}) {
38+
return render(
39+
<PreferencesProvider value={preferences}>
40+
<ConnectionForm
41+
onConnectClicked={noop}
42+
initialConnectionInfo={{
43+
id: 'test',
44+
connectionOptions: {
45+
connectionString:
46+
'mongodb://pineapple:orangutans@localhost:27019',
47+
},
48+
}}
49+
onSaveConnectionClicked={noop}
50+
{...props}
51+
/>
52+
</PreferencesProvider>
53+
);
54+
}
55+
56+
beforeEach(async function () {
57+
preferences = await createSandboxFromDefaultPreferences();
58+
});
59+
4860
afterEach(function () {
4961
cleanup();
5062
});
@@ -363,4 +375,72 @@ describe('ConnectionForm Component', function () {
363375

364376
expect(() => screen.getByText(saveAndConnectText)).to.throw;
365377
});
378+
379+
context('when multiple connection management is enabled', function () {
380+
beforeEach(async function () {
381+
await preferences.savePreferences({
382+
enableNewMultipleConnectionSystem: true,
383+
});
384+
renderForm({
385+
initialConnectionInfo: DEFAULT_CONNECTION,
386+
preferences: {
387+
protectConnectionStringsForNewConnections: false,
388+
protectConnectionStrings: false,
389+
},
390+
});
391+
});
392+
393+
it('should not show the old favorite button', function () {
394+
expect(screen.queryByTestId('edit-favorite-icon-button')).to.be.null;
395+
});
396+
397+
describe('name input', function () {
398+
it('should sync with the href of the connection string unless it has been edited', async function () {
399+
const connectionString = screen.getByTestId('connectionString');
400+
userEvent.clear(connectionString);
401+
402+
await waitFor(() => expect(connectionString.value).to.equal(''));
403+
404+
userEvent.paste(connectionString, 'mongodb://myserver:27017/');
405+
406+
await waitFor(() =>
407+
expect(connectionString.value).to.equal('mongodb://myserver:27017/')
408+
);
409+
410+
const personalizationName = screen.getByTestId(
411+
'personalization-name-input'
412+
);
413+
expect(personalizationName.value).to.equal('myserver:27017');
414+
});
415+
416+
it('should not sync with the href of the connection string when it has been edited', async function () {
417+
const connectionString = screen.getByTestId('connectionString');
418+
const personalizationName = screen.getByTestId(
419+
'personalization-name-input'
420+
);
421+
422+
userEvent.clear(personalizationName);
423+
userEvent.clear(connectionString);
424+
425+
await waitFor(() => {
426+
expect(personalizationName.value).to.equal('');
427+
expect(connectionString.value).to.equal('');
428+
});
429+
430+
userEvent.paste(personalizationName, 'my happy name');
431+
432+
await waitFor(() =>
433+
expect(personalizationName.value).to.equal('my happy name')
434+
);
435+
436+
userEvent.paste(connectionString, 'mongodb://webscale:27017/');
437+
438+
await waitFor(() =>
439+
expect(connectionString.value).to.equal('mongodb://webscale:27017/')
440+
);
441+
442+
expect(personalizationName.value).to.equal('my happy name');
443+
});
444+
});
445+
});
366446
});

0 commit comments

Comments
 (0)