Skip to content

Commit 529a71d

Browse files
authored
feat(connection-form): allow editing connected connections, but only the name, colour and favorite checkbox COMPASS-8160 (#6336)
allow editing connected connections, but only the name, colour and favorite.
1 parent 4474f17 commit 529a71d

File tree

10 files changed

+219
-57
lines changed

10 files changed

+219
-57
lines changed

packages/compass-connections-navigation/src/item-actions.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@ export type NavigationItemActions = (ItemAction<Actions> | ItemSeparator)[];
77

88
export const notConnectedConnectionItemActions = ({
99
connectionInfo,
10-
hideEditConnect = false,
1110
}: {
1211
connectionInfo: ConnectionInfo;
13-
hideEditConnect?: boolean;
1412
}): NavigationItemActions => {
1513
const isAtlas = !!connectionInfo.atlasMetadata;
1614
const actions: (ItemAction<Actions> | ItemSeparator | null)[] = [
17-
hideEditConnect || isAtlas
15+
isAtlas
1816
? null
1917
: {
2018
action: 'edit-connection',
@@ -85,8 +83,6 @@ export const connectedConnectionItemActions = ({
8583
const isAtlas = !!connectionInfo.atlasMetadata;
8684
const connectionManagementActions = notConnectedConnectionItemActions({
8785
connectionInfo,
88-
// for connected connections we don't show connect action
89-
hideEditConnect: true,
9086
});
9187
const actions: (ItemAction<Actions> | ItemSeparator | null)[] = [
9288
hasWriteActionsDisabled

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ export function MultipleConnectionSidebar({
228228
/>
229229
{editingConnectionInfo && (
230230
<ConnectionFormModal
231+
disableEditingConnectedConnection={
232+
!!findActiveConnection(editingConnectionInfo.id)
233+
}
234+
onDisconnectClicked={() => disconnect(editingConnectionInfo.id)}
231235
isOpen={isEditingConnectionInfoModalOpen}
232236
setOpen={(newOpen) => {
233237
// This is how leafygreen propagates `X` button click

packages/connection-form/src/components/advanced-options-tabs/csfle-tab/csfle-tab.spec.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,9 @@ describe('In-Use Encryption', function () {
381381

382382
const selector = within(card).getByTestId('csfle-kms-card-name');
383383
userEvent.clear(selector);
384-
userEvent.type(selector, value);
384+
if (value !== '') {
385+
userEvent.type(selector, value);
386+
}
385387
userEvent.keyboard('{enter}');
386388
}
387389

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ describe('<ConnectionFormModalActions />', function () {
4646

4747
expect(onSaveAndConnectSpy).to.have.been.calledOnce;
4848
});
49+
50+
it('should hide "connect" button if there is no callback', function () {
51+
render(
52+
<ConnectionFormModalActions
53+
errors={[]}
54+
warnings={[]}
55+
></ConnectionFormModalActions>
56+
);
57+
expect(screen.queryByRole('button', { name: 'Connect' })).to.not.exist;
58+
});
4959
});
5060

5161
describe('Save Button', function () {

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export type ConnectionFormModalActionsProps = {
4444

4545
onCancel?(): void;
4646
onSave?(): void;
47-
onSaveAndConnect(): void;
47+
onSaveAndConnect?(): void;
4848
};
4949

5050
export function ConnectionFormModalActions({
@@ -89,7 +89,11 @@ export function ConnectionFormModalActions({
8989
<div className={saveAndConnectStyles}>
9090
<Button
9191
data-testid="save-button"
92-
variant={ButtonVariant.PrimaryOutline}
92+
variant={
93+
onSaveAndConnect
94+
? ButtonVariant.PrimaryOutline
95+
: ButtonVariant.Primary
96+
}
9397
disabled={false}
9498
onClick={onSave}
9599
>
@@ -98,13 +102,15 @@ export function ConnectionFormModalActions({
98102
</div>
99103
)}
100104

101-
<Button
102-
data-testid="connect-button"
103-
variant={ButtonVariant.Primary}
104-
onClick={onSaveAndConnect}
105-
>
106-
{saveAndConnectLabel}
107-
</Button>
105+
{onSaveAndConnect && (
106+
<Button
107+
data-testid="connect-button"
108+
variant={ButtonVariant.Primary}
109+
onClick={onSaveAndConnect}
110+
>
111+
{saveAndConnectLabel}
112+
</Button>
113+
)}
108114
</div>
109115
</div>
110116
);

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

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,71 @@ describe('ConnectionForm Component', function () {
7777
sandbox.restore();
7878
});
7979

80+
context('when disableEditingConnectedConnection==true', function () {
81+
it('renders a banner, disables the connection string and removes advanced connection options + connect button', function () {
82+
const onDisconnectClicked = Sinon.spy();
83+
const onSaveClicked = Sinon.spy();
84+
const onSaveAndConnectClicked = Sinon.spy();
85+
86+
renderForm({
87+
disableEditingConnectedConnection: true,
88+
onDisconnectClicked,
89+
onSaveClicked,
90+
onSaveAndConnectClicked,
91+
});
92+
93+
expect(
94+
screen.getByTestId('disabled-connected-connection-banner')
95+
).to.exist;
96+
expect(screen.getByRole('button', { name: 'Disconnect' })).to.exist;
97+
expect(() =>
98+
screen.getByTestId('toggle-edit-connection-string')
99+
).to.throw;
100+
expect(() =>
101+
screen.getByTestId('advanced-connection-options')
102+
).to.throw;
103+
expect(() => screen.getByRole('button', { name: 'Connect' })).to.throw;
104+
105+
// pressing enter calls onSubmit which saves
106+
fireEvent.submit(screen.getByRole('form'));
107+
expect(onSaveClicked.callCount).to.equal(1);
108+
expect(onSaveAndConnectClicked.callCount).to.equal(0);
109+
110+
fireEvent.click(screen.getByRole('button', { name: 'Disconnect' }));
111+
expect(onDisconnectClicked.callCount).to.equal(1);
112+
});
113+
});
114+
115+
context('when disableEditingConnectedConnection==false', function () {
116+
it('leaves the connection string, advanced connection options and connect button intact, does not render a banner', function () {
117+
const onDisconnectClicked = Sinon.spy();
118+
const onSaveClicked = Sinon.spy();
119+
const onSaveAndConnectClicked = Sinon.spy();
120+
121+
renderForm({
122+
disableEditingConnectedConnection: false,
123+
onDisconnectClicked,
124+
onSaveClicked,
125+
onSaveAndConnectClicked,
126+
});
127+
128+
expect(() =>
129+
screen.getByTestId('disabled-connected-connection-banner')
130+
).to.throw;
131+
expect(() =>
132+
screen.getByRole('button', { name: 'Disconnect' })
133+
).to.throw;
134+
expect(screen.getByTestId('toggle-edit-connection-string')).to.exist;
135+
expect(screen.getByTestId('advanced-connection-options')).to.exist;
136+
expect(screen.getByRole('button', { name: 'Connect' })).to.exist;
137+
138+
// pressing enter calls onSubmit which saves and connects (the default)
139+
fireEvent.submit(screen.getByRole('form'));
140+
expect(onSaveClicked.callCount).to.equal(0);
141+
expect(onSaveAndConnectClicked.callCount).to.equal(1);
142+
});
143+
});
144+
80145
context(
81146
'when preferences.protectConnectionStringsForNewConnections === true',
82147
function () {

0 commit comments

Comments
 (0)