Skip to content

Commit

Permalink
add delete connection type
Browse files Browse the repository at this point in the history
  • Loading branch information
ashley-o0o committed Aug 13, 2024
1 parent 6c270e4 commit 3164fb1
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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');
});
});
3 changes: 3 additions & 0 deletions frontend/src/concepts/connectionTypes/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ export type ConnectionTypeConfigMap = K8sResourceCommon & {
// JSON of type ConnectionTypeField
fields?: string;
};
spec: {
displayName: string;
};
};

export type ConnectionTypeConfigMapObj = Omit<ConnectionTypeConfigMap, 'data'> & {
Expand Down
16 changes: 0 additions & 16 deletions frontend/src/k8sTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TResource extends Partial<K8sResourceCommon>> = {
apiVersion: string;
Expand Down
63 changes: 29 additions & 34 deletions frontend/src/pages/connectionTypes/ConnectionTypesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConnectionTypesTableProps> = ({
connectionTypes,
onUpdate,
refreshConnectionTypes,
}) => {
const [filterData, setFilterData] = React.useState<FilterDataType>(initialFilterData);
const onClearFilters = React.useCallback(() => setFilterData(initialFilterData), [setFilterData]);

const [deleteConnectionType, setDeleteConnectionType] = React.useState<
ConnectionTypeKind | undefined
ConnectionTypeConfigMapObj | undefined
>();

const filteredConnectionTypes = connectionTypes.filter((connectionType) => {
Expand Down Expand Up @@ -61,42 +57,41 @@ const ConnectionTypesTable: React.FC<ConnectionTypesTableProps> = ({

return (
<>
<Table
variant="compact"
data={filteredConnectionTypes}
columns={connectionTypeColumns}
defaultSortColumn={0}
data-testid="connection-types-table"
rowRenderer={(connectionType) => (
<ConnectionTypesTableRow
key={connectionType.metadata.name}
obj={connectionType}
onUpdate={onUpdate}
connectionType={connectionType}
handleDelete={(connectionType) => setDeleteConnectionType(connectionType)}/>
)}
toolbarContent={
<ConnectionTypesTableToolbar
filterData={filterData}
setFilterData={setFilterData}
onClearFilters={onClearFilters}
/>
}
disableItemCount
emptyTableView={<DashboardEmptyTableView onClearFilters={resetFilters} />}
id="connectionTypes-list-table"
/>
<DeleteConnectionTypeModal
<Table
variant="compact"
data={filteredConnectionTypes}
columns={connectionTypeColumns}
defaultSortColumn={0}
data-testid="connection-types-table"
rowRenderer={(connectionType) => (
<ConnectionTypesTableRow
key={connectionType.metadata.name}
obj={connectionType}
onUpdate={onUpdate}
handleDelete={(connection) => setDeleteConnectionType(connection)}
/>
)}
toolbarContent={
<ConnectionTypesTableToolbar
filterData={filterData}
setFilterData={setFilterData}
onClearFilters={onClearFilters}
/>
}
disableItemCount
emptyTableView={<DashboardEmptyTableView onClearFilters={resetFilters} />}
id="connectionTypes-list-table"
/>
<DeleteConnectionTypeModal
connectionType={deleteConnectionType}
onClose={(deleted) => {
if (deleted) {
refreshConnectionTypes();
onUpdate();
}
setDeleteConnectionType(undefined);
}}
/>
</>

);
};

Expand Down
14 changes: 7 additions & 7 deletions frontend/src/pages/connectionTypes/ConnectionTypesTableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConnectionTypesTableRowProps> = ({ obj, onUpdate, connectionType, handleDelete })=> {
const ConnectionTypesTableRow: React.FC<ConnectionTypesTableRowProps> = ({
obj,
onUpdate,
handleDelete,
}) => {
const [statusMessage, setStatusMessage] = React.useState<string | undefined>();
const [errorMessage, setErrorMessage] = React.useState<string | undefined>();
const pendingEnabledState = React.useRef<'true' | 'false' | undefined>();
Expand Down Expand Up @@ -121,13 +122,12 @@ const ConnectionTypesTableRow: React.FC<ConnectionTypesTableRowProps> = ({ obj,
items={[
{
title: 'Delete',
onClick: () => handleDelete(connectionType),
onClick: () => handleDelete(obj),
},
]}
/>
</Td>
</Tr>

);
};

Expand Down
13 changes: 6 additions & 7 deletions frontend/src/pages/connectionTypes/DeleteConnectionTypeModal.tsx
Original file line number Diff line number Diff line change
@@ -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;
};

Expand All @@ -21,11 +21,11 @@ const DeleteConnectionTypeModal: React.FC<DeleteConnectionTypeModalProps> = ({
setError(undefined);
};

const deleteName = connectionType?.spec.displayName || 'this accelerator profile';
const deleteName = connectionType?.spec.displayName || 'this connection type';

return (
<DeleteModal
title="Delete accelerator profile?"
title="Delete connection type?"
isOpen={!!connectionType}
onClose={() => onBeforeClose(false)}
submitButtonLabel="Delete"
Expand All @@ -46,9 +46,8 @@ const DeleteConnectionTypeModal: React.FC<DeleteConnectionTypeModalProps> = ({
error={error}
deleteName={deleteName}
>
The <b>{deleteName}</b> 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 <b>{deleteName}</b> connection type will be deleted. Existing connections of this type
will not be affected.
</DeleteModal>
);
};
Expand Down
38 changes: 0 additions & 38 deletions frontend/src/services/connectionTypeService.ts

This file was deleted.

0 comments on commit 3164fb1

Please sign in to comment.