-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Duplicate connection page UI (#3059)
* Add duplicate connection type page * Add connection type preview to page * Remove table column headings when empty * Reduce vertical padding and hide preview button when open * Update useConnectionType to use useFetchState hook instead * Fix file and folder path names * Update table * Updates to page and table * Updates * Add error state to footer if create fails * Add username to creation and util type changes
- Loading branch information
Showing
17 changed files
with
686 additions
and
4 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
frontend/src/__tests__/cypress/cypress/pages/connectionTypes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { TableRow } from './components/table'; | ||
|
||
class CreateConnectionTypeTableRow extends TableRow { | ||
findSectionHeading() { | ||
return this.find().findByTestId('section-heading'); | ||
} | ||
|
||
findName() { | ||
return this.find().findByTestId('field-name'); | ||
} | ||
|
||
findType() { | ||
return this.find().findByTestId('field-type'); | ||
} | ||
|
||
findDefault() { | ||
return this.find().findByTestId('field-default'); | ||
} | ||
|
||
findEnvVar() { | ||
return this.find().findByTestId('field-env'); | ||
} | ||
|
||
findRequired() { | ||
return this.find().findByTestId('field-required'); | ||
} | ||
} | ||
|
||
class CreateConnectionTypePage { | ||
visitCreatePage() { | ||
cy.visitWithLogin('/connectionTypes/create'); | ||
cy.findAllByText('Create connection type').should('exist'); | ||
} | ||
|
||
visitDuplicatePage(name = 'existing') { | ||
cy.visitWithLogin(`/connectionTypes/duplicate/${name}`); | ||
cy.findAllByText('Create connection type').should('exist'); | ||
} | ||
|
||
findConnectionTypeName() { | ||
return cy.findByTestId('connection-type-name'); | ||
} | ||
|
||
findConnectionTypeDesc() { | ||
return cy.findByTestId('connection-type-description'); | ||
} | ||
|
||
findConnectionTypeEnableCheckbox() { | ||
return cy.findByTestId('connection-type-enable'); | ||
} | ||
|
||
findConnectionTypePreviewToggle() { | ||
return cy.findByTestId('preview-drawer-toggle-button'); | ||
} | ||
|
||
findFieldsTable() { | ||
return cy.findByTestId('connection-type-fields-table'); | ||
} | ||
|
||
findAllFieldsTableRows() { | ||
return this.findFieldsTable().findAllByTestId('row'); | ||
} | ||
|
||
getFieldsTableRow(index: number) { | ||
return new CreateConnectionTypeTableRow(() => this.findAllFieldsTableRows().eq(index)); | ||
} | ||
|
||
findSubmitButton() { | ||
return cy.findByTestId('submit-button'); | ||
} | ||
} | ||
|
||
export const createConnectionTypePage = new CreateConnectionTypePage(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...end/src/__tests__/cypress/cypress/tests/mocked/connectionTypes/createConnectionType.cy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { | ||
mockConnectionTypeConfigMap, | ||
mockConnectionTypeConfigMapObj, | ||
} from '~/__mocks__/mockConnectionType'; | ||
import { createConnectionTypePage } from '~/__tests__/cypress/cypress/pages/connectionTypes'; | ||
import { asClusterAdminUser } from '~/__tests__/cypress/cypress/utils/mockUsers'; | ||
|
||
describe('create', () => { | ||
it('Display base page', () => { | ||
asClusterAdminUser(); | ||
createConnectionTypePage.visitCreatePage(); | ||
|
||
createConnectionTypePage.findConnectionTypeName().should('exist'); | ||
createConnectionTypePage.findConnectionTypeDesc().should('exist'); | ||
createConnectionTypePage.findConnectionTypeEnableCheckbox().should('exist'); | ||
createConnectionTypePage.findConnectionTypePreviewToggle().should('exist'); | ||
}); | ||
|
||
it('Allows create button with valid name', () => { | ||
asClusterAdminUser(); | ||
createConnectionTypePage.visitCreatePage(); | ||
|
||
createConnectionTypePage.findConnectionTypeName().should('have.value', ''); | ||
createConnectionTypePage.findSubmitButton().should('be.disabled'); | ||
|
||
createConnectionTypePage.findConnectionTypeName().type('hello'); | ||
createConnectionTypePage.findSubmitButton().should('be.enabled'); | ||
}); | ||
}); | ||
|
||
describe('duplicate', () => { | ||
const existing = mockConnectionTypeConfigMapObj({ name: 'existing' }); | ||
|
||
beforeEach(() => { | ||
asClusterAdminUser(); | ||
cy.interceptOdh( | ||
'GET /api/connection-types/:name', | ||
{ path: { name: 'existing' } }, | ||
mockConnectionTypeConfigMap({ name: 'existing' }), | ||
); | ||
}); | ||
|
||
it('Prefill details from existing connection', () => { | ||
createConnectionTypePage.visitDuplicatePage('existing'); | ||
|
||
createConnectionTypePage | ||
.findConnectionTypeName() | ||
.should( | ||
'have.value', | ||
`Duplicate of ${existing.metadata.annotations['openshift.io/display-name']}`, | ||
); | ||
createConnectionTypePage | ||
.findConnectionTypeDesc() | ||
.should('have.value', existing.metadata.annotations['openshift.io/description']); | ||
createConnectionTypePage.findConnectionTypeEnableCheckbox().should('be.checked'); | ||
}); | ||
|
||
it('Prefill fields table from existing connection', () => { | ||
createConnectionTypePage.visitDuplicatePage('existing'); | ||
|
||
createConnectionTypePage | ||
.findAllFieldsTableRows() | ||
.should('have.length', existing.data?.fields?.length); | ||
|
||
// Row 0 - Section | ||
const row0 = createConnectionTypePage.getFieldsTableRow(0); | ||
row0.findName().should('contain.text', 'Short text'); | ||
row0.findSectionHeading().should('exist'); | ||
|
||
// Row 1 - Short text field | ||
const row1 = createConnectionTypePage.getFieldsTableRow(1); | ||
row1.findName().should('contain.text', 'Short text 1'); | ||
row1.findType().should('have.text', 'Short text'); | ||
row1.findDefault().should('have.text', '-'); | ||
row1.findRequired().not('be.checked'); | ||
|
||
// Row 2 - Short text field | ||
const row2 = createConnectionTypePage.getFieldsTableRow(2); | ||
row2.findName().should('contain.text', 'Short text 2'); | ||
row2.findType().should('have.text', 'Short text'); | ||
row2.findDefault().should('have.text', 'This is the default value'); | ||
row2.findRequired().should('be.checked'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
frontend/src/concepts/connectionTypes/createConnectionTypeUtils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { ConnectionTypeConfigMapObj, ConnectionTypeField } from '~/concepts/connectionTypes/types'; | ||
|
||
export const extractConnectionTypeFromMap = ( | ||
configMap?: ConnectionTypeConfigMapObj, | ||
): { | ||
k8sName: string; | ||
name: string; | ||
description: string; | ||
enabled: boolean; | ||
fields: ConnectionTypeField[]; | ||
} => ({ | ||
k8sName: configMap?.metadata.name ?? '', | ||
name: configMap?.metadata.annotations['openshift.io/display-name'] ?? '', | ||
description: configMap?.metadata.annotations['openshift.io/description'] ?? '', | ||
enabled: configMap?.metadata.annotations['opendatahub.io/enabled'] === 'true', | ||
fields: configMap?.data?.fields ?? [], | ||
}); | ||
|
||
export const createConnectionTypeObj = ( | ||
k8sName: string, | ||
displayName: string, | ||
description: string, | ||
enabled: boolean, | ||
username: string, | ||
fields: ConnectionTypeField[], | ||
): ConnectionTypeConfigMapObj => ({ | ||
kind: 'ConfigMap', | ||
apiVersion: 'v1', | ||
metadata: { | ||
name: k8sName, | ||
annotations: { | ||
'openshift.io/display-name': displayName, | ||
'openshift.io/description': description, | ||
'opendatahub.io/enabled': enabled ? 'true' : 'false', | ||
'opendatahub.io/username': username, | ||
}, | ||
labels: { 'opendatahub.io/dashboard': 'true', 'opendatahub.io/connection-type': 'true' }, | ||
}, | ||
data: { | ||
fields, | ||
}, | ||
}); |
22 changes: 22 additions & 0 deletions
22
frontend/src/concepts/connectionTypes/useConnectionType.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import * as React from 'react'; | ||
import { ConnectionTypeConfigMapObj } from '~/concepts/connectionTypes/types'; | ||
import { fetchConnectionType } from '~/services/connectionTypesService'; | ||
import useFetchState, { | ||
FetchState, | ||
FetchStateCallbackPromise, | ||
NotReadyError, | ||
} from '~/utilities/useFetchState'; | ||
|
||
export const useConnectionType = ( | ||
name?: string, | ||
): FetchState<ConnectionTypeConfigMapObj | undefined> => { | ||
const fetchData = React.useCallback<FetchStateCallbackPromise<ConnectionTypeConfigMapObj>>(() => { | ||
if (!name) { | ||
return Promise.reject(new NotReadyError('No connection type name')); | ||
} | ||
|
||
return fetchConnectionType(name); | ||
}, [name]); | ||
|
||
return useFetchState(fetchData, undefined); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
frontend/src/pages/connectionTypes/ConnectionTypeRoutes.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import * as React from 'react'; | ||
import { Navigate, Routes, Route } from 'react-router-dom'; | ||
import { CreateConnectionTypePage } from './create/CreateConnectionTypePage'; | ||
import { DuplicateConnectionTypePage } from './create/DuplicateConnectionTypePage'; | ||
import { EditConnectionTypePage } from './create/EditConnectionTypePage'; | ||
|
||
const ConnectionTypeRoutes: React.FC = () => ( | ||
<Routes> | ||
<Route path="/"> | ||
<Route path="create" element={<CreateConnectionTypePage />} /> | ||
<Route path="duplicate/:name" element={<DuplicateConnectionTypePage />} /> | ||
<Route path="edit/:name" element={<EditConnectionTypePage />} /> | ||
<Route path="*" element={<Navigate to="." />} /> | ||
</Route> | ||
</Routes> | ||
); | ||
|
||
export default ConnectionTypeRoutes; |
Oops, something went wrong.