Skip to content

Commit 16f97f8

Browse files
authored
feat(ws): Add "Connect" column to workspace table and display popup with workspace endpoints. (#161)
* feat(ws): Add Connect column to workspace table and popup with workspace endpoints Signed-off-by: Yael <fishel.yael@gmail.com> * feat(ws): Split the Connect button, such that clicking it opens the default (main) endpoint Signed-off-by: Yael <fishel.yael@gmail.com> --------- Signed-off-by: Yael <fishel.yael@gmail.com>
1 parent 055150b commit 16f97f8

File tree

3 files changed

+102
-0
lines changed

3 files changed

+102
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import React from 'react';
2+
import {
3+
Dropdown,
4+
DropdownItem,
5+
DropdownList,
6+
MenuToggle,
7+
MenuToggleElement,
8+
MenuToggleAction,
9+
} from '@patternfly/react-core';
10+
import { Workspace, WorkspaceState } from '~/shared/types';
11+
12+
type WorkspaceConnectActionProps = {
13+
workspace: Workspace;
14+
};
15+
16+
export const WorkspaceConnectAction: React.FunctionComponent<WorkspaceConnectActionProps> = ({
17+
workspace,
18+
}) => {
19+
const [open, setIsOpen] = React.useState(false);
20+
21+
const onToggleClick = () => {
22+
setIsOpen(!open);
23+
};
24+
25+
const onSelect = (
26+
_event: React.MouseEvent<Element, MouseEvent> | undefined,
27+
value: string | number | undefined,
28+
) => {
29+
setIsOpen(false);
30+
if (typeof value === 'string') {
31+
openEndpoint(value);
32+
}
33+
};
34+
35+
const onClickConnect = () => {
36+
openEndpoint(workspace.podTemplate.endpoints[0].port);
37+
};
38+
39+
const openEndpoint = (port: string) => {
40+
window.open(`workspace/${workspace.namespace}/${workspace.name}/${port}`, '_blank');
41+
};
42+
43+
return (
44+
<Dropdown
45+
isOpen={open}
46+
onSelect={onSelect}
47+
onOpenChange={(isOpen: boolean) => setIsOpen(isOpen)}
48+
toggle={(toggleRef: React.Ref<MenuToggleElement>) => (
49+
<MenuToggle
50+
ref={toggleRef}
51+
onClick={onToggleClick}
52+
isExpanded={open}
53+
isFullWidth
54+
isDisabled={workspace.status.state !== WorkspaceState.Running}
55+
splitButtonItems={[
56+
<MenuToggleAction
57+
id="connect-endpoint-button"
58+
key="connect-endpoint-button"
59+
onClick={onClickConnect}
60+
>
61+
Connect
62+
</MenuToggleAction>,
63+
]}
64+
/>
65+
)}
66+
ouiaId="BasicDropdown"
67+
shouldFocusToggleOnSelect
68+
>
69+
<DropdownList>
70+
{workspace.podTemplate.endpoints.map((endpoint) => (
71+
<DropdownItem value={endpoint.port} key={`${workspace.name}-${endpoint.port}`}>
72+
{endpoint.displayName}
73+
</DropdownItem>
74+
))}
75+
</DropdownList>
76+
</Dropdown>
77+
);
78+
};

workspaces/frontend/src/app/pages/Workspaces/Workspaces.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { ExpandedWorkspaceRow } from '~/app/pages/Workspaces/ExpandedWorkspaceRo
3333
import DeleteModal from '~/shared/components/DeleteModal';
3434
import { buildKindLogoDictionary } from '~/app/actions/WorkspaceKindsActions';
3535
import useWorkspaceKinds from '~/app/hooks/useWorkspaceKinds';
36+
import { WorkspaceConnectAction } from '~/app/pages/Workspaces/WorkspaceConnectAction';
3637
import Filter, { FilteredColumn } from 'shared/components/Filter';
3738
import { formatRam } from 'shared/utilities/WorkspaceResources';
3839

@@ -67,6 +68,12 @@ export const Workspaces: React.FunctionComponent = () => {
6768
},
6869
],
6970
},
71+
endpoints: [
72+
{
73+
displayName: 'JupyterLab',
74+
port: '7777',
75+
},
76+
],
7077
},
7178
options: {
7279
imageConfig: 'jupyterlab_scipy_180',
@@ -112,6 +119,16 @@ export const Workspaces: React.FunctionComponent = () => {
112119
},
113120
],
114121
},
122+
endpoints: [
123+
{
124+
displayName: 'JupyterLab',
125+
port: '8888',
126+
},
127+
{
128+
displayName: 'Spark Master',
129+
port: '9999',
130+
},
131+
],
115132
},
116133
options: {
117134
imageConfig: 'jupyterlab_scipy_180',
@@ -461,6 +478,9 @@ export const Workspaces: React.FunctionComponent = () => {
461478
1 hour ago
462479
</Timestamp>
463480
</Td>
481+
<Td>
482+
<WorkspaceConnectAction workspace={workspace} />
483+
</Td>
464484
<Td isActionCell data-testid="action-column">
465485
<ActionsColumn
466486
items={defaultActions(workspace).map((action) => ({

workspaces/frontend/src/shared/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ export interface Workspace {
116116
readOnly: boolean;
117117
}[];
118118
};
119+
endpoints: {
120+
displayName: string;
121+
port: string;
122+
}[];
119123
};
120124
options: {
121125
imageConfig: string;

0 commit comments

Comments
 (0)