Skip to content

Commit 19f4e9a

Browse files
committed
feat(ws): Split the Connect button, such that clicking it opens the default (main) endpoint
Signed-off-by: Yael <[email protected]>
1 parent a933edc commit 19f4e9a

File tree

2 files changed

+38
-22
lines changed

2 files changed

+38
-22
lines changed
Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,67 @@
1-
import React from "react";
1+
import React from 'react';
22
import {
33
Dropdown,
44
DropdownItem,
55
DropdownList,
66
MenuToggle,
77
MenuToggleElement,
8-
} from "@patternfly/react-core";
9-
import { Workspace, WorkspaceState } from "~/shared/types";
8+
MenuToggleAction,
9+
} from '@patternfly/react-core';
10+
import { Workspace, WorkspaceState } from '~/shared/types';
1011

1112
type EndpointsDropdownProps = {
1213
workspace: Workspace;
1314
};
1415

15-
export const EndpointsDropdown: React.FunctionComponent<EndpointsDropdownProps> = ({workspace}) => {
16-
const [isOpen, setIsOpen] = React.useState(false);
16+
export const EndpointsDropdown: React.FunctionComponent<EndpointsDropdownProps> = ({
17+
workspace,
18+
}) => {
19+
const [open, setIsOpen] = React.useState(false);
1720

1821
const onToggleClick = () => {
19-
setIsOpen(!isOpen);
22+
setIsOpen(!open);
2023
};
2124

2225
const onSelect = (
2326
_event: React.MouseEvent<Element, MouseEvent> | undefined,
24-
value: string | number | undefined) => {
27+
value: string | number | undefined,
28+
) => {
2529
setIsOpen(false);
26-
if (typeof value === 'string'){
30+
if (typeof value === 'string') {
2731
openEndpoint(value);
2832
}
2933
};
3034

35+
const onClickConnect = () => {
36+
openEndpoint(workspace.podTemplate.endpoints[0].port);
37+
};
38+
3139
const openEndpoint = (port: string) => {
32-
window.open(`workspace/${workspace.namespace}/${workspace.name}/${port}`, '_blank');
40+
window.open(`workspace/${workspace.namespace}/${workspace.name}/${port}`, '_blank');
3341
};
3442

3543
return (
3644
<Dropdown
37-
isOpen={isOpen}
45+
isOpen={open}
3846
onSelect={onSelect}
3947
onOpenChange={(isOpen: boolean) => setIsOpen(isOpen)}
4048
toggle={(toggleRef: React.Ref<MenuToggleElement>) => (
4149
<MenuToggle
4250
ref={toggleRef}
4351
onClick={onToggleClick}
44-
isExpanded={isOpen}
45-
isFullWidth={true}
46-
isDisabled={workspace.status.state != WorkspaceState.Running}
47-
>Connect
48-
</MenuToggle>
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+
/>
4965
)}
5066
ouiaId="BasicDropdown"
5167
shouldFocusToggleOnSelect
@@ -59,4 +75,4 @@ export const EndpointsDropdown: React.FunctionComponent<EndpointsDropdownProps>
5975
</DropdownList>
6076
</Dropdown>
6177
);
62-
};
78+
};

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ import { Workspace, WorkspacesColumnNames, WorkspaceState } from '~/shared/types
2828
import { WorkspaceDetails } from '~/app/pages/Workspaces/Details/WorkspaceDetails';
2929
import { ExpandedWorkspaceRow } from '~/app/pages/Workspaces/ExpandedWorkspaceRow';
3030
import DeleteModal from '~/shared/components/DeleteModal';
31+
import { EndpointsDropdown } from '~/app/pages/Workspaces/WorkspaceEndpoints';
3132
import Filter, { FilteredColumn } from 'shared/components/Filter';
3233
import { formatRam } from 'shared/utilities/WorkspaceResources';
33-
import { EndpointsDropdown } from '~/app/pages/Workspaces/WorkspaceEndpoints';
3434

3535
export const Workspaces: React.FunctionComponent = () => {
3636
/* Mocked workspaces, to be removed after fetching info from backend */
@@ -66,8 +66,8 @@ export const Workspaces: React.FunctionComponent = () => {
6666
endpoints: [
6767
{
6868
displayName: 'JupyterLab',
69-
port: '7777'
70-
}
69+
port: '7777',
70+
},
7171
],
7272
},
7373
options: {
@@ -117,11 +117,11 @@ export const Workspaces: React.FunctionComponent = () => {
117117
endpoints: [
118118
{
119119
displayName: 'JupyterLab',
120-
port: '8888'
120+
port: '8888',
121121
},
122122
{
123123
displayName: 'Spark Master',
124-
port: '9999'
124+
port: '9999',
125125
},
126126
],
127127
},
@@ -456,7 +456,7 @@ export const Workspaces: React.FunctionComponent = () => {
456456
</Timestamp>
457457
</Td>
458458
<Td>
459-
<EndpointsDropdown workspace={workspace}/>
459+
<EndpointsDropdown workspace={workspace} />
460460
</Td>
461461
<Td isActionCell data-testid="action-column">
462462
<ActionsColumn

0 commit comments

Comments
 (0)