diff --git a/packages/compass-data-modeling/src/components/new-diagram-form.spec.tsx b/packages/compass-data-modeling/src/components/new-diagram-form.spec.tsx index 571c377db0c..72794bd1ed3 100644 --- a/packages/compass-data-modeling/src/components/new-diagram-form.spec.tsx +++ b/packages/compass-data-modeling/src/components/new-diagram-form.spec.tsx @@ -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; @@ -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; @@ -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', { @@ -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', { @@ -190,7 +194,7 @@ describe('NewDiagramForm', function () { }); } - userEvent.click(screen.getByTestId('new-diagram-database-selector')); + userEvent.click(getComboboxByTestId('new-diagram-database-selector')); expect(screen.getByText('berlin')).to.exist; expect(screen.getByText('sample_airbnb')).to.exist; @@ -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', { @@ -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', { @@ -309,7 +313,7 @@ describe('NewDiagramForm', function () { { // Navigate to select colls - userEvent.click(screen.getByTestId('new-diagram-database-selector')); + userEvent.click(getComboboxByTestId('new-diagram-database-selector')); userEvent.click(screen.getByText('sample_airbnb')); userEvent.click( screen.getByRole('button', { @@ -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', { @@ -405,7 +409,7 @@ describe('NewDiagramForm', function () { { // Navigate to collections - userEvent.click(screen.getByTestId('new-diagram-database-selector')); + userEvent.click(getComboboxByTestId('new-diagram-database-selector')); userEvent.click(screen.getByText('sample_airbnb')); userEvent.click( screen.getByRole('button', { diff --git a/packages/compass-data-modeling/src/components/new-diagram-form.tsx b/packages/compass-data-modeling/src/components/new-diagram-form.tsx index 31512f5d90d..e01db893d4d 100644 --- a/packages/compass-data-modeling/src/components/new-diagram-form.tsx +++ b/packages/compass-data-modeling/src/components/new-diagram-form.tsx @@ -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({ @@ -238,6 +238,18 @@ const NewDiagramForm: React.FunctionComponent = ({ 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, @@ -333,22 +345,40 @@ const NewDiagramForm: React.FunctionComponent = ({ case 'select-connection': return ( - + {connections.length === 0 && ( You do not have any connections, create a new connection first @@ -359,21 +389,23 @@ const NewDiagramForm: React.FunctionComponent = ({ case 'select-database': return ( - + ); case 'select-collections': @@ -386,8 +418,9 @@ const NewDiagramForm: React.FunctionComponent = ({ ); } }, [ + activeConnections, collections, - connections, + connections.length, currentStep, databases, diagramName, @@ -395,6 +428,7 @@ const NewDiagramForm: React.FunctionComponent = ({ onConnectionSelect, onDatabaseSelect, onNameChange, + otherConnections, selectedCollections, selectedConnectionId, selectedDatabase, diff --git a/packages/compass-e2e-tests/helpers/commands/select-option.ts b/packages/compass-e2e-tests/helpers/commands/select-option.ts index f9fb12ca4c6..daa3dbde13c 100644 --- a/packages/compass-e2e-tests/helpers/commands/select-option.ts +++ b/packages/compass-e2e-tests/helpers/commands/select-option.ts @@ -8,13 +8,19 @@ export async function selectOption( optionText: string ): Promise { // click the field's button - const selectButton = browser.$(selector); + const selectButton = browser.$(`${selector}`); await selectButton.waitForDisplayed(); await selectButton.click(); - const controlledMenuId: string = await selectButton.getAttribute( - 'aria-controls' - ); + let controlledMenuId = await selectButton.getAttribute('aria-controls'); + // In leafygreen combobox we usually not immediately targeting the element + // that controls the listbox, so if we haven't find it, try to look in the + // element we selected + if (!controlledMenuId) { + controlledMenuId = await selectButton + .$('[aria-controls]') + .getAttribute('aria-controls'); + } // wait for the list to pop up const selectList = browser.$(`[id="${controlledMenuId}"][role="listbox"]`); await selectList.waitForDisplayed();