Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ws): Add "Connect" column to workspace table and display popup with workspace endpoints. #161

Merged
merged 2 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import React from 'react';
import {
Dropdown,
DropdownItem,
DropdownList,
MenuToggle,
MenuToggleElement,
MenuToggleAction,
} from '@patternfly/react-core';
import { Workspace, WorkspaceState } from '~/shared/types';

type WorkspaceConnectActionProps = {
workspace: Workspace;
};

export const WorkspaceConnectAction: React.FunctionComponent<WorkspaceConnectActionProps> = ({
workspace,
}) => {
const [open, setIsOpen] = React.useState(false);

const onToggleClick = () => {
setIsOpen(!open);
};

const onSelect = (
_event: React.MouseEvent<Element, MouseEvent> | undefined,
value: string | number | undefined,
) => {
setIsOpen(false);
if (typeof value === 'string') {
openEndpoint(value);
}
};

const onClickConnect = () => {
openEndpoint(workspace.podTemplate.endpoints[0].port);
};

const openEndpoint = (port: string) => {
window.open(`workspace/${workspace.namespace}/${workspace.name}/${port}`, '_blank');
};

return (
<Dropdown
isOpen={open}
onSelect={onSelect}
onOpenChange={(isOpen: boolean) => setIsOpen(isOpen)}
toggle={(toggleRef: React.Ref<MenuToggleElement>) => (
<MenuToggle
ref={toggleRef}
onClick={onToggleClick}
isExpanded={open}
isFullWidth
isDisabled={workspace.status.state !== WorkspaceState.Running}
splitButtonItems={[
<MenuToggleAction
id="connect-endpoint-button"
key="connect-endpoint-button"
onClick={onClickConnect}
>
Connect
</MenuToggleAction>,
]}
/>
)}
ouiaId="BasicDropdown"
shouldFocusToggleOnSelect
>
<DropdownList>
{workspace.podTemplate.endpoints.map((endpoint) => (
<DropdownItem value={endpoint.port} key={`${workspace.name}-${endpoint.port}`}>
{endpoint.displayName}
</DropdownItem>
))}
</DropdownList>
</Dropdown>
);
};
20 changes: 20 additions & 0 deletions workspaces/frontend/src/app/pages/Workspaces/Workspaces.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { ExpandedWorkspaceRow } from '~/app/pages/Workspaces/ExpandedWorkspaceRo
import DeleteModal from '~/shared/components/DeleteModal';
import { buildKindLogoDictionary } from '~/app/actions/WorkspaceKindsActions';
import useWorkspaceKinds from '~/app/hooks/useWorkspaceKinds';
import { WorkspaceConnectAction } from '~/app/pages/Workspaces/WorkspaceConnectAction';
import Filter, { FilteredColumn } from 'shared/components/Filter';
import { formatRam } from 'shared/utilities/WorkspaceResources';

Expand Down Expand Up @@ -67,6 +68,12 @@ export const Workspaces: React.FunctionComponent = () => {
},
],
},
endpoints: [
{
displayName: 'JupyterLab',
port: '7777',
},
],
},
options: {
imageConfig: 'jupyterlab_scipy_180',
Expand Down Expand Up @@ -112,6 +119,16 @@ export const Workspaces: React.FunctionComponent = () => {
},
],
},
endpoints: [
{
displayName: 'JupyterLab',
port: '8888',
},
{
displayName: 'Spark Master',
port: '9999',
},
],
},
options: {
imageConfig: 'jupyterlab_scipy_180',
Expand Down Expand Up @@ -461,6 +478,9 @@ export const Workspaces: React.FunctionComponent = () => {
1 hour ago
</Timestamp>
</Td>
<Td>
<WorkspaceConnectAction workspace={workspace} />
</Td>
<Td isActionCell data-testid="action-column">
<ActionsColumn
items={defaultActions(workspace).map((action) => ({
Expand Down
4 changes: 4 additions & 0 deletions workspaces/frontend/src/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ export interface Workspace {
readOnly: boolean;
}[];
};
endpoints: {
displayName: string;
port: string;
}[];
};
options: {
imageConfig: string;
Expand Down