Skip to content

Commit

Permalink
Delete connection ref from notebooks when connection is deleted (#3428)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-phillips-18 authored Nov 4, 2024
1 parent fdcdd51 commit 3c44cac
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const ConnectedResources: React.FC<Props> = ({ connection }) => {
return <Spinner size="sm" />;
}

if (!connectedNotebooks.length) {
if (!connectedNotebooks.length && !connectedModels.length) {
return '-';
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import { K8sStatus } from '@openshift/dynamic-plugin-sdk-utils';
import {
Badge,
Bullseye,
Expand All @@ -20,19 +19,18 @@ import {
import { useNotebooksStates } from '~/pages/projects/notebook/useNotebooksStates';
import { NotebookKind } from '~/k8sTypes';
import { useInferenceServicesForConnection } from '~/pages/projects/useInferenceServicesForConnection';
import { deleteSecret, removeNotebookSecret } from '~/api';

type Props = {
namespace: string;
deleteConnection: Connection;
onClose: (deleted?: boolean) => void;
onDelete: () => Promise<K8sStatus>;
};

export const ConnectionsDeleteModal: React.FC<Props> = ({
namespace,
deleteConnection,
onClose,
onDelete,
}) => {
const [isDeleting, setIsDeleting] = React.useState(false);
const [error, setError] = React.useState<Error>();
Expand Down Expand Up @@ -61,8 +59,18 @@ export const ConnectionsDeleteModal: React.FC<Props> = ({
onDelete={() => {
setIsDeleting(true);
setError(undefined);

onDelete()
Promise.all(
connectedNotebooks.map((notebook) =>
removeNotebookSecret(
notebook.metadata.name,
notebook.metadata.namespace,
deleteConnection.metadata.name,
),
),
)
.then(() =>
deleteSecret(deleteConnection.metadata.namespace, deleteConnection.metadata.name),
)
.then(() => {
onClose(true);
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as React from 'react';
import { Connection, ConnectionTypeConfigMapObj } from '~/concepts/connectionTypes/types';
import { deleteSecret } from '~/api';
import { Table } from '~/components/table';
import ConnectionsTableRow from './ConnectionsTableRow';
import { getColumns } from './connectionsTableColumns';
Expand Down Expand Up @@ -65,9 +64,6 @@ const ConnectionsTable: React.FC<ConnectionsTableProps> = ({
refreshConnections();
}
}}
onDelete={() =>
deleteSecret(deleteConnection.metadata.namespace, deleteConnection.metadata.name)
}
/>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const mockNotebooks = [
mockNotebookK8sResource({ name: 'another-notebook', displayName: 'Another notebook' }),
];
describe('Delete connection modal', () => {
const onDelete = jest.fn();
const onClose = jest.fn();

beforeEach(() => {
Expand Down Expand Up @@ -68,7 +67,6 @@ describe('Delete connection modal', () => {
namespace={deleteConnection.metadata.namespace}
deleteConnection={deleteConnection}
onClose={onClose}
onDelete={onDelete}
/>,
);

Expand Down Expand Up @@ -104,7 +102,6 @@ describe('Delete connection modal', () => {
namespace={deleteConnection.metadata.namespace}
deleteConnection={deleteConnection}
onClose={onClose}
onDelete={onDelete}
/>,
);

Expand Down

0 comments on commit 3c44cac

Please sign in to comment.