Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -11,6 +11,10 @@ import { changeName, createNewDiagram } from '../store/generate-diagram-wizard';
import { renderWithStore } from '../../test/setup-store';
import type { DataModelingStore } from '../../test/setup-store';

function getComboboxByTestId(testId: string) {
return within(screen.getByTestId(testId)).getByRole('combobox');
}

describe('NewDiagramForm', function () {
context('enter-name step', function () {
let store: DataModelingStore;
Expand Down Expand Up @@ -87,7 +91,7 @@ describe('NewDiagramForm', function () {
);
}

userEvent.click(screen.getByTestId('new-diagram-connection-selector'));
userEvent.click(getComboboxByTestId('new-diagram-connection-selector'));
expect(screen.getByText('Conn1')).to.exist;
expect(screen.getByText('Conn2')).to.exist;

Expand Down Expand Up @@ -143,7 +147,7 @@ describe('NewDiagramForm', function () {
);
}

userEvent.click(screen.getByTestId('new-diagram-connection-selector'));
userEvent.click(getComboboxByTestId('new-diagram-connection-selector'));
userEvent.click(screen.getByText('Conn2'));
userEvent.click(
screen.getByRole('button', {
Expand Down Expand Up @@ -176,7 +180,7 @@ describe('NewDiagramForm', function () {

{
// Navigate to select db
userEvent.click(screen.getByTestId('new-diagram-connection-selector'));
userEvent.click(getComboboxByTestId('new-diagram-connection-selector'));
userEvent.click(screen.getByText('Conn2'));
userEvent.click(
screen.getByRole('button', {
Expand Down Expand Up @@ -253,7 +257,7 @@ describe('NewDiagramForm', function () {
);
}

userEvent.click(screen.getByTestId('new-diagram-connection-selector'));
userEvent.click(getComboboxByTestId('new-diagram-connection-selector'));
userEvent.click(screen.getByText('Conn2'));
userEvent.click(
screen.getByRole('button', {
Expand Down Expand Up @@ -293,7 +297,7 @@ describe('NewDiagramForm', function () {

{
// Navigate to select db
userEvent.click(screen.getByTestId('new-diagram-connection-selector'));
userEvent.click(getComboboxByTestId('new-diagram-connection-selector'));
userEvent.click(screen.getByText('Conn2'));
userEvent.click(
screen.getByRole('button', {
Expand Down Expand Up @@ -389,7 +393,7 @@ describe('NewDiagramForm', function () {

{
// Navigate to databases list
userEvent.click(screen.getByTestId('new-diagram-connection-selector'));
userEvent.click(getComboboxByTestId('new-diagram-connection-selector'));
userEvent.click(screen.getByText('Conn2'));
userEvent.click(
screen.getByRole('button', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ import {
ModalBody,
ModalFooter,
ModalHeader,
Option,
Select,
SelectList,
spacing,
SpinLoader,
Body,
TextInput,
SearchInput,
Combobox,
ComboboxOption,
} from '@mongodb-js/compass-components';

const footerStyles = css({
Expand Down Expand Up @@ -238,6 +238,18 @@ const NewDiagramForm: React.FunctionComponent<NewDiagramFormProps> = ({
onCollectionsSelectionConfirm,
}) => {
const connections = useConnectionsList();
const [activeConnections, otherConnections] = useMemo(() => {
const active = [];
const other = [];
for (const connection of connections) {
if (connection.status === 'connected') {
active.push(connection);
} else {
other.push(connection);
}
}
return [active, other];
}, [connections]);
const {
title,
description,
Expand Down Expand Up @@ -333,22 +345,40 @@ const NewDiagramForm: React.FunctionComponent<NewDiagramFormProps> = ({
case 'select-connection':
return (
<FormFieldContainer className={formContainerStyles}>
<Select
<Combobox
label=""
aria-label="Select connection"
value={selectedConnectionId ?? ''}
data-testid="new-diagram-connection-selector"
onChange={onConnectionSelect}
onChange={(connectionId) => {
if (connectionId) {
onConnectionSelect(connectionId);
}
}}
clearable={false}
multiselect={false}
disabled={connections.length === 0}
>
{connections.map((connection) => {
{activeConnections.map((connection) => {
return (
<ComboboxOption
key={connection.info.id}
value={connection.info.id}
displayName={connection.title}
description="Active"
></ComboboxOption>
);
})}
{otherConnections.map((connection) => {
return (
<Option key={connection.info.id} value={connection.info.id}>
{connection.title}
</Option>
<ComboboxOption
key={connection.info.id}
value={connection.info.id}
displayName={connection.title}
></ComboboxOption>
);
})}
</Select>
</Combobox>
{connections.length === 0 && (
<Banner variant="warning">
You do not have any connections, create a new connection first
Expand All @@ -359,21 +389,23 @@ const NewDiagramForm: React.FunctionComponent<NewDiagramFormProps> = ({
case 'select-database':
return (
<FormFieldContainer>
<Select
<Combobox
label=""
aria-label="Select database"
value={selectedDatabase ?? ''}
data-testid="new-diagram-database-selector"
onChange={onDatabaseSelect}
onChange={(databaseName) => {
if (databaseName) {
onDatabaseSelect(databaseName);
}
}}
clearable={false}
multiselect={false}
>
{databases.map((db) => {
return (
<Option key={db} value={db}>
{db}
</Option>
);
return <ComboboxOption key={db} value={db}></ComboboxOption>;
})}
</Select>
</Combobox>
</FormFieldContainer>
);
case 'select-collections':
Expand All @@ -386,15 +418,17 @@ const NewDiagramForm: React.FunctionComponent<NewDiagramFormProps> = ({
);
}
}, [
activeConnections,
collections,
connections,
connections.length,
currentStep,
databases,
diagramName,
onCollectionsSelect,
onConnectionSelect,
onDatabaseSelect,
onNameChange,
otherConnections,
selectedCollections,
selectedConnectionId,
selectedDatabase,
Expand Down