Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ export type NavigationItemActions = (ItemAction<Actions> | ItemSeparator)[];

export const notConnectedConnectionItemActions = ({
connectionInfo,
hideEditConnect = false,
}: {
connectionInfo: ConnectionInfo;
hideEditConnect?: boolean;
}): NavigationItemActions => {
const isAtlas = !!connectionInfo.atlasMetadata;
const actions: (ItemAction<Actions> | ItemSeparator | null)[] = [
hideEditConnect || isAtlas
isAtlas
? null
: {
action: 'edit-connection',
Expand Down Expand Up @@ -85,8 +83,6 @@ export const connectedConnectionItemActions = ({
const isAtlas = !!connectionInfo.atlasMetadata;
const connectionManagementActions = notConnectedConnectionItemActions({
connectionInfo,
// for connected connections we don't show connect action
hideEditConnect: true,
});
const actions: (ItemAction<Actions> | ItemSeparator | null)[] = [
hasWriteActionsDisabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ export function MultipleConnectionSidebar({
/>
{editingConnectionInfo && (
<ConnectionFormModal
disableEditingConnectedConnection={
!!findActiveConnection(editingConnectionInfo.id)
}
onDisconnectClicked={() => disconnect(editingConnectionInfo.id)}
isOpen={isEditingConnectionInfoModalOpen}
setOpen={(newOpen) => {
// This is how leafygreen propagates `X` button click
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,9 @@ describe('In-Use Encryption', function () {

const selector = within(card).getByTestId('csfle-kms-card-name');
userEvent.clear(selector);
userEvent.type(selector, value);
if (value !== '') {
userEvent.type(selector, value);
}
userEvent.keyboard('{enter}');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ describe('<ConnectionFormModalActions />', function () {

expect(onSaveAndConnectSpy).to.have.been.calledOnce;
});

it('should hide "connect" button if there is no callback', function () {
render(
<ConnectionFormModalActions
errors={[]}
warnings={[]}
></ConnectionFormModalActions>
);
expect(screen.queryByRole('button', { name: 'Connect' })).to.not.exist;
});
});

describe('Save Button', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export type ConnectionFormModalActionsProps = {

onCancel?(): void;
onSave?(): void;
onSaveAndConnect(): void;
onSaveAndConnect?(): void;
};

export function ConnectionFormModalActions({
Expand Down Expand Up @@ -89,7 +89,11 @@ export function ConnectionFormModalActions({
<div className={saveAndConnectStyles}>
<Button
data-testid="save-button"
variant={ButtonVariant.PrimaryOutline}
variant={
onSaveAndConnect
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically: If there is no save&connect button (the Connect button), make the Save button the "default" (ie. solid green) one. type for both are still implicitly "button", though. there is no default. Would be ambiguous anyway because we have a custom onSubmit handler that would have to be kept in sync.

? ButtonVariant.PrimaryOutline
: ButtonVariant.Primary
}
disabled={false}
onClick={onSave}
>
Expand All @@ -98,13 +102,15 @@ export function ConnectionFormModalActions({
</div>
)}

<Button
data-testid="connect-button"
variant={ButtonVariant.Primary}
onClick={onSaveAndConnect}
>
{saveAndConnectLabel}
</Button>
{onSaveAndConnect && (
<Button
data-testid="connect-button"
variant={ButtonVariant.Primary}
onClick={onSaveAndConnect}
>
{saveAndConnectLabel}
</Button>
)}
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,71 @@ describe('ConnectionForm Component', function () {
sandbox.restore();
});

context('when disableEditingConnectedConnection==true', function () {
it('renders a banner, disables the connection string and removes advanced connection options + connect button', function () {
const onDisconnectClicked = Sinon.spy();
const onSaveClicked = Sinon.spy();
const onSaveAndConnectClicked = Sinon.spy();

renderForm({
disableEditingConnectedConnection: true,
onDisconnectClicked,
onSaveClicked,
onSaveAndConnectClicked,
});

expect(
screen.getByTestId('disabled-connected-connection-banner')
).to.exist;
expect(screen.getByRole('button', { name: 'Disconnect' })).to.exist;
expect(() =>
screen.getByTestId('toggle-edit-connection-string')
).to.throw;
expect(() =>
screen.getByTestId('advanced-connection-options')
).to.throw;
expect(() => screen.getByRole('button', { name: 'Connect' })).to.throw;

// pressing enter calls onSubmit which saves
fireEvent.submit(screen.getByRole('form'));
expect(onSaveClicked.callCount).to.equal(1);
expect(onSaveAndConnectClicked.callCount).to.equal(0);

fireEvent.click(screen.getByRole('button', { name: 'Disconnect' }));
expect(onDisconnectClicked.callCount).to.equal(1);
});
});

context('when disableEditingConnectedConnection==false', function () {
it('leaves the connection string, advanced connection options and connect button intact, does not render a banner', function () {
const onDisconnectClicked = Sinon.spy();
const onSaveClicked = Sinon.spy();
const onSaveAndConnectClicked = Sinon.spy();

renderForm({
disableEditingConnectedConnection: false,
onDisconnectClicked,
onSaveClicked,
onSaveAndConnectClicked,
});

expect(() =>
screen.getByTestId('disabled-connected-connection-banner')
).to.throw;
expect(() =>
screen.getByRole('button', { name: 'Disconnect' })
).to.throw;
expect(screen.getByTestId('toggle-edit-connection-string')).to.exist;
expect(screen.getByTestId('advanced-connection-options')).to.exist;
expect(screen.getByRole('button', { name: 'Connect' })).to.exist;

// pressing enter calls onSubmit which saves and connects (the default)
fireEvent.submit(screen.getByRole('form'));
expect(onSaveClicked.callCount).to.equal(0);
expect(onSaveAndConnectClicked.callCount).to.equal(1);
});
});

context(
'when preferences.protectConnectionStringsForNewConnections === true',
function () {
Expand Down
Loading
Loading