Skip to content

Commit

Permalink
Select connected notebooks when creating and editing data connections (
Browse files Browse the repository at this point in the history
…#837)

* Select connected notebooks when creating and editing data connections

* address comments

* Update promise actions spread
  • Loading branch information
DaoDaoNoCode authored Dec 9, 2022
1 parent 53ece14 commit b90244e
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 195 deletions.
15 changes: 10 additions & 5 deletions frontend/src/pages/projects/notebook/useRelatedNotebooks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { NotebookKind } from '../../../k8sTypes';
import { getNotebookPVCNames, getNotebookSecretNames } from '../pvc/utils';
import * as React from 'react';
import { ProjectDetailsContext } from '../ProjectDetailsContext';
import { DATA_CONNECTION_PREFIX } from '../../../api';
import { getNotebookPVCMountPathMap } from './utils';
Expand All @@ -25,11 +25,11 @@ const useRelatedNotebooks = (
} = React.useContext(ProjectDetailsContext);

const connectedNotebooks = React.useMemo(() => {
if (!resourceName) {
return [];
}
switch (context) {
case ConnectedNotebookContext.EXISTING_PVC:
if (!resourceName) {
return [];
}
return data.reduce<NotebookKind[]>((acc, { notebook }) => {
const relatedPVCNames = getNotebookPVCNames(notebook);
if (!relatedPVCNames.includes(resourceName)) {
Expand All @@ -39,6 +39,9 @@ const useRelatedNotebooks = (
return [...acc, notebook];
}, []);
case ConnectedNotebookContext.REMOVABLE_PVC:
if (!resourceName) {
return [];
}
return data.reduce<NotebookKind[]>((acc, { notebook }) => {
const relatedPVCNames = getNotebookPVCNames(notebook);
if (!relatedPVCNames.includes(resourceName)) {
Expand All @@ -53,6 +56,9 @@ const useRelatedNotebooks = (
return [...acc, notebook];
}, []);
case ConnectedNotebookContext.EXISTING_DATA_CONNECTION:
if (!resourceName) {
return [];
}
return data.reduce<NotebookKind[]>((acc, { notebook }) => {
const relatedSecretNames = getNotebookSecretNames(notebook);
if (!relatedSecretNames.includes(resourceName)) {
Expand All @@ -69,7 +75,6 @@ const useRelatedNotebooks = (
if (relatedSecretNames.length > 0) {
return acc;
}

return [...acc, notebook];
}, []);
default:
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { columns } from './data';
import DataConnectionsTableRow from './DataConnectionsTableRow';
import { getDataConnectionId } from './utils';
import DeleteDataConnectionModal from './DeleteDataConnectionModal';
import ChangeDataConnectionWorkbenchModal from './ChangeDataConnectionWorkbenchModal';
import ManageDataConnectionModal from './ManageDataConnectionModal';

type DataConnectionsTableProps = {
Expand All @@ -22,9 +21,6 @@ const DataConnectionsTable: React.FC<DataConnectionsTableProps> = ({
const [deleteDataConnection, setDeleteDataConnection] = React.useState<
DataConnection | undefined
>();
const [connectExistingWorkbench, setConnectExistingWorkbench] = React.useState<
DataConnection | undefined
>();
const sort = useTableColumnSort<DataConnection>(columns, 1);
const sortedDataConnections = sort.transformData(unsortedDataConnections);

Expand All @@ -47,7 +43,6 @@ const DataConnectionsTable: React.FC<DataConnectionsTableProps> = ({
obj={dataConnection}
onEditDataConnection={setEditDataConnection}
onDeleteDataConnection={setDeleteDataConnection}
onConnectExistingWorkbench={setConnectExistingWorkbench}
/>
))}
</Tbody>
Expand All @@ -62,15 +57,6 @@ const DataConnectionsTable: React.FC<DataConnectionsTableProps> = ({
setEditDataConnection(undefined);
}}
/>
<ChangeDataConnectionWorkbenchModal
dataConnection={connectExistingWorkbench}
onClose={(successfulConnect) => {
if (successfulConnect) {
refreshData();
}
setConnectExistingWorkbench(undefined);
}}
/>
<DeleteDataConnectionModal
dataConnection={deleteDataConnection}
onClose={(deleted) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ type DataConnectionsTableRowProps = {
obj: DataConnection;
onEditDataConnection: (pvc: DataConnection) => void;
onDeleteDataConnection: (dataConnection: DataConnection) => void;
onConnectExistingWorkbench: (dataConnection: DataConnection) => void;
};

const DataConnectionsTableRow: React.FC<DataConnectionsTableRowProps> = ({
obj,
onEditDataConnection,
onDeleteDataConnection,
onConnectExistingWorkbench,
}) => {
return (
<Tr>
Expand Down Expand Up @@ -56,12 +54,6 @@ const DataConnectionsTableRow: React.FC<DataConnectionsTableRowProps> = ({
onEditDataConnection(obj);
},
},
{
title: 'Change connected workbenches',
onClick: () => {
onConnectExistingWorkbench(obj);
},
},
{
title: 'Delete data connection',
onClick: () => {
Expand Down
Loading

0 comments on commit b90244e

Please sign in to comment.