From 3164fb17c7352a6760e7e156142892623858b39a Mon Sep 17 00:00:00 2001 From: Ashley McEntee Date: Tue, 13 Aug 2024 11:49:16 -0400 Subject: [PATCH] add delete connection type --- .../connectionTypes/connectionTypes.cy.ts | 9 ++- .../src/concepts/connectionTypes/types.ts | 3 + frontend/src/k8sTypes.ts | 16 ----- .../connectionTypes/ConnectionTypesTable.tsx | 63 +++++++++---------- .../ConnectionTypesTableRow.tsx | 14 ++--- .../DeleteConnectionTypeModal.tsx | 13 ++-- .../src/services/connectionTypeService.ts | 38 ----------- 7 files changed, 52 insertions(+), 104 deletions(-) delete mode 100644 frontend/src/services/connectionTypeService.ts diff --git a/frontend/src/__tests__/cypress/cypress/tests/mocked/connectionTypes/connectionTypes.cy.ts b/frontend/src/__tests__/cypress/cypress/tests/mocked/connectionTypes/connectionTypes.cy.ts index 3fc0a116ad..d9abda0fde 100644 --- a/frontend/src/__tests__/cypress/cypress/tests/mocked/connectionTypes/connectionTypes.cy.ts +++ b/frontend/src/__tests__/cypress/cypress/tests/mocked/connectionTypes/connectionTypes.cy.ts @@ -6,6 +6,7 @@ import { import { connectionTypesPage } from '~/__tests__/cypress/cypress/pages/connectionTypes'; import { mockDashboardConfig } from '~/__mocks__'; import { mockConnectionTypeConfigMap } from '~/__mocks__/mockConnectionType'; +import { deleteModal } from '~/__tests__/cypress/cypress/pages/components/DeleteModal'; it('Connection types should not be available for non product admins', () => { asProjectAdminUser(); @@ -104,9 +105,13 @@ describe('Connection types', () => { row2.findEnableStatus().should('have.text', 'Enabling...'); }); - it.only('should delete connection type', () => { + it('should delete connection type', () => { connectionTypesPage.visit(); connectionTypesPage.shouldHaveConnectionTypes(); - + connectionTypesPage.getConnectionTypeRow('Test display name').findKebabAction('Delete').click(); + deleteModal.findSubmitButton().should('be.disabled'); + deleteModal.findInput().fill('Test display name'); + deleteModal.findSubmitButton().should('be.enabled').click(); + cy.wait('@delete'); }); }); diff --git a/frontend/src/concepts/connectionTypes/types.ts b/frontend/src/concepts/connectionTypes/types.ts index 9e22099fb8..33f2c12623 100644 --- a/frontend/src/concepts/connectionTypes/types.ts +++ b/frontend/src/concepts/connectionTypes/types.ts @@ -99,6 +99,9 @@ export type ConnectionTypeConfigMap = K8sResourceCommon & { // JSON of type ConnectionTypeField fields?: string; }; + spec: { + displayName: string; + }; }; export type ConnectionTypeConfigMapObj = Omit & { diff --git a/frontend/src/k8sTypes.ts b/frontend/src/k8sTypes.ts index 5f28923b7a..5c5b918ffc 100644 --- a/frontend/src/k8sTypes.ts +++ b/frontend/src/k8sTypes.ts @@ -1279,22 +1279,6 @@ export type AcceleratorProfileKind = K8sResourceCommon & { }; }; -export type ConnectionTypeKind = K8sResourceCommon & { - metadata: { - name: string; - annotations?: Partial<{ - 'opendatahub.io/modified-date': string; - }>; - }; - spec: { - displayName: string; - enabled: boolean; - identifier: string; - description?: string; - tolerations?: Toleration[]; - }; -}; - // In the SDK TResource extends from K8sResourceCommon, but both kind and apiVersion are mandatory export type K8sResourceListResult> = { apiVersion: string; diff --git a/frontend/src/pages/connectionTypes/ConnectionTypesTable.tsx b/frontend/src/pages/connectionTypes/ConnectionTypesTable.tsx index 6ab29e91d0..c3688b7cf5 100644 --- a/frontend/src/pages/connectionTypes/ConnectionTypesTable.tsx +++ b/frontend/src/pages/connectionTypes/ConnectionTypesTable.tsx @@ -7,25 +7,21 @@ import ConnectionTypesTableToolbar from '~/pages/connectionTypes/ConnectionTypes import { ConnectionTypeConfigMapObj } from '~/concepts/connectionTypes/types'; import { Table } from '~/components/table'; import DeleteConnectionTypeModal from '~/pages/connectionTypes/DeleteConnectionTypeModal'; -import { ConnectionTypeKind } from '~/k8sTypes'; type ConnectionTypesTableProps = { connectionTypes: ConnectionTypeConfigMapObj[]; onUpdate: () => void; - refreshConnectionTypes: () => void; -} - +}; const ConnectionTypesTable: React.FC = ({ connectionTypes, onUpdate, - refreshConnectionTypes, }) => { const [filterData, setFilterData] = React.useState(initialFilterData); const onClearFilters = React.useCallback(() => setFilterData(initialFilterData), [setFilterData]); const [deleteConnectionType, setDeleteConnectionType] = React.useState< - ConnectionTypeKind | undefined + ConnectionTypeConfigMapObj | undefined >(); const filteredConnectionTypes = connectionTypes.filter((connectionType) => { @@ -61,42 +57,41 @@ const ConnectionTypesTable: React.FC = ({ return ( <> - ( - setDeleteConnectionType(connectionType)}/> - )} - toolbarContent={ - - } - disableItemCount - emptyTableView={} - id="connectionTypes-list-table" - /> - ( + setDeleteConnectionType(connection)} + /> + )} + toolbarContent={ + + } + disableItemCount + emptyTableView={} + id="connectionTypes-list-table" + /> + { if (deleted) { - refreshConnectionTypes(); + onUpdate(); } setDeleteConnectionType(undefined); }} /> - ); }; diff --git a/frontend/src/pages/connectionTypes/ConnectionTypesTableRow.tsx b/frontend/src/pages/connectionTypes/ConnectionTypesTableRow.tsx index 7c075841d4..78466ffda5 100644 --- a/frontend/src/pages/connectionTypes/ConnectionTypesTableRow.tsx +++ b/frontend/src/pages/connectionTypes/ConnectionTypesTableRow.tsx @@ -15,17 +15,18 @@ import { ExclamationCircleIcon } from '@patternfly/react-icons'; import { ConnectionTypeConfigMapObj } from '~/concepts/connectionTypes/types'; import { relativeTime } from '~/utilities/time'; import { updateConnectionTypeEnabled } from '~/services/connectionTypesService'; -import { ConnectionTypeKind } from '~/k8sTypes'; type ConnectionTypesTableRowProps = { obj: ConnectionTypeConfigMapObj; onUpdate: () => void; - connectionType: ConnectionTypeKind; - handleDelete: (cr: ConnectionTypeKind) => void; + handleDelete: (cr: ConnectionTypeConfigMapObj) => void; }; - -const ConnectionTypesTableRow: React.FC = ({ obj, onUpdate, connectionType, handleDelete })=> { +const ConnectionTypesTableRow: React.FC = ({ + obj, + onUpdate, + handleDelete, +}) => { const [statusMessage, setStatusMessage] = React.useState(); const [errorMessage, setErrorMessage] = React.useState(); const pendingEnabledState = React.useRef<'true' | 'false' | undefined>(); @@ -121,13 +122,12 @@ const ConnectionTypesTableRow: React.FC = ({ obj, items={[ { title: 'Delete', - onClick: () => handleDelete(connectionType), + onClick: () => handleDelete(obj), }, ]} /> - ); }; diff --git a/frontend/src/pages/connectionTypes/DeleteConnectionTypeModal.tsx b/frontend/src/pages/connectionTypes/DeleteConnectionTypeModal.tsx index 3dc75ebfa5..3e82f21f4e 100644 --- a/frontend/src/pages/connectionTypes/DeleteConnectionTypeModal.tsx +++ b/frontend/src/pages/connectionTypes/DeleteConnectionTypeModal.tsx @@ -1,10 +1,10 @@ import React from 'react'; +import { ConnectionTypeConfigMapObj } from '~/concepts/connectionTypes/types'; import DeleteModal from '~/pages/projects/components/DeleteModal'; -import { ConnectionTypeKind } from '~/k8sTypes'; import { deleteConnectionType } from '~/services/connectionTypesService'; type DeleteConnectionTypeModalProps = { - connectionType?: ConnectionTypeKind; + connectionType?: ConnectionTypeConfigMapObj; onClose: (deleted: boolean) => void; }; @@ -21,11 +21,11 @@ const DeleteConnectionTypeModal: React.FC = ({ setError(undefined); }; - const deleteName = connectionType?.spec.displayName || 'this accelerator profile'; + const deleteName = connectionType?.spec.displayName || 'this connection type'; return ( onBeforeClose(false)} submitButtonLabel="Delete" @@ -46,9 +46,8 @@ const DeleteConnectionTypeModal: React.FC = ({ error={error} deleteName={deleteName} > - The {deleteName} accelerator profile will be deleted and will no longer be available - for use with new workbenches and runtimes. Existing resources using this profile will retain - it unless a new profile is selected. + The {deleteName} connection type will be deleted. Existing connections of this type + will not be affected. ); }; diff --git a/frontend/src/services/connectionTypeService.ts b/frontend/src/services/connectionTypeService.ts deleted file mode 100644 index 1ddaa2cbd4..0000000000 --- a/frontend/src/services/connectionTypeService.ts +++ /dev/null @@ -1,38 +0,0 @@ -import axios from '~/utilities/axios'; -import { ConnectionTypeKind } from '~/k8sTypes'; -import { ResponseStatus } from '~/types'; - -export const createConnectionType = ( - connectionType: ConnectionTypeKind['spec'], -): Promise => { - const url = '/api/connection-type'; - return axios - .post(url, connectionType) - .then((response) => response.data) - .catch((e) => { - throw new Error(e.response.data.message); - }); -}; - -export const deleteConnectionType = (name: string): Promise => { - const url = `/api/connection-types/${name}`; - return axios - .delete(url) - .then((response) => response.data) - .catch((e) => { - throw new Error(e.response.data.message); - }); -}; - -export const updateConnectionType = ( - name: string, - spec: Partial, -): Promise => { - const url = `/api/connection-types/${name}`; - return axios - .put(url, spec) - .then((response) => response.data) - .catch((e) => { - throw new Error(e.response.data.message); - }); -};