Skip to content

Commit

Permalink
Delete connection ref from notebooks when connection is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-phillips-18 committed Nov 4, 2024
1 parent 217787a commit 66922ff
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 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

0 comments on commit 66922ff

Please sign in to comment.