Skip to content

Commit c81c44e

Browse files
author
Elay Aharoni (EXT-Nokia)
committed
Workspace Data Vol column popup add
Signed-off-by: Elay Aharoni (EXT-Nokia) <[email protected]>
1 parent 346a74e commit c81c44e

File tree

1 file changed

+84
-13
lines changed

1 file changed

+84
-13
lines changed

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

Lines changed: 84 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
Button,
2323
PaginationVariant,
2424
Pagination,
25+
Content,
2526
} from '@patternfly/react-core';
2627
import {
2728
Table,
@@ -33,8 +34,9 @@ import {
3334
ThProps,
3435
ActionsColumn,
3536
IActions,
37+
ExpandableRowContent,
3638
} from '@patternfly/react-table';
37-
import { FilterIcon } from '@patternfly/react-icons';
39+
import { FilterIcon, LockedIcon } from '@patternfly/react-icons';
3840
import { Workspace, WorkspaceState } from '~/shared/types';
3941

4042
export const Workspaces: React.FunctionComponent = () => {
@@ -51,7 +53,12 @@ export const Workspaces: React.FunctionComponent = () => {
5153
home: '/home',
5254
data: [
5355
{
54-
pvcName: 'data',
56+
pvcName: 'Volume-1',
57+
mountPath: '/data',
58+
readOnly: true,
59+
},
60+
{
61+
pvcName: 'Volume-2',
5562
mountPath: '/data',
5663
readOnly: false,
5764
},
@@ -128,7 +135,6 @@ export const Workspaces: React.FunctionComponent = () => {
128135
podConfig: 'Pod Config',
129136
state: 'State',
130137
homeVol: 'Home Vol',
131-
dataVol: 'Data Vol',
132138
lastActivity: 'Last Activity',
133139
};
134140

@@ -140,6 +146,18 @@ export const Workspaces: React.FunctionComponent = () => {
140146
const attributeContainerRef = React.useRef<HTMLDivElement | null>(null);
141147

142148
const [searchValue, setSearchValue] = React.useState('');
149+
const [expandedWorkspacesNames, setExpandedWorkspacesNames] = React.useState<string[]>([]);
150+
151+
const setWorkspaceExpanded = (workspace: Workspace, isExpanding = true) =>
152+
setExpandedWorkspacesNames((prevExpanded) => {
153+
const newExpandedWorkspacesNames = prevExpanded.filter((wsName) => wsName !== workspace.name);
154+
return isExpanding
155+
? [...newExpandedWorkspacesNames, workspace.name]
156+
: newExpandedWorkspacesNames;
157+
});
158+
159+
const isWorkspaceExpanded = (workspace: Workspace) =>
160+
expandedWorkspacesNames.includes(workspace.name);
143161

144162
const searchInput = (
145163
<SearchInput
@@ -421,6 +439,54 @@ export const Workspaces: React.FunctionComponent = () => {
421439
setPage(newPage);
422440
};
423441

442+
const workspaceDataVolRender = (workspace: Workspace) => {
443+
const workspaceDataVol = workspace.podTemplate.volumes.data;
444+
console.log(workspaceDataVol);
445+
return (
446+
<>
447+
<Content component="h3">Data Volumes:</Content>
448+
{workspaceDataVol.map((data, index) => (
449+
<Content key={`data-vol-${index}`} component="blockquote">
450+
<div>
451+
<div>
452+
<Content component="h5">{data.pvcName}</Content>
453+
</div>
454+
<div>
455+
<Content component="small">
456+
mount path: {data.mountPath}
457+
{data.readOnly && (
458+
<Content component="small">
459+
Data is readonly
460+
<LockedIcon style={{ marginLeft: '3px' }} />
461+
</Content>
462+
)}
463+
</Content>
464+
</div>
465+
</div>
466+
</Content>
467+
))}
468+
</>
469+
);
470+
};
471+
472+
const expandedRowRenderer = (workspace: Workspace) => (
473+
<Tr>
474+
<Td />
475+
{Object.keys(columnNames).map((colName) => {
476+
switch (colName) {
477+
case 'name':
478+
return (
479+
<Td noPadding colSpan={1}>
480+
<ExpandableRowContent>{workspaceDataVolRender(workspace)}</ExpandableRowContent>
481+
</Td>
482+
);
483+
default:
484+
return <Td />;
485+
}
486+
})}
487+
</Tr>
488+
);
489+
424490
return (
425491
<PageSection>
426492
<Title headingLevel="h1">Kubeflow Workspaces</Title>
@@ -429,20 +495,27 @@ export const Workspaces: React.FunctionComponent = () => {
429495
<Table aria-label="Sortable table" ouiaId="SortableTable">
430496
<Thead>
431497
<Tr>
498+
<Th />
432499
<Th sort={getSortParams(0)}>{columnNames.name}</Th>
433500
<Th sort={getSortParams(1)}>{columnNames.kind}</Th>
434501
<Th sort={getSortParams(2)}>{columnNames.image}</Th>
435502
<Th sort={getSortParams(3)}>{columnNames.podConfig}</Th>
436503
<Th sort={getSortParams(4)}>{columnNames.state}</Th>
437504
<Th sort={getSortParams(5)}>{columnNames.homeVol}</Th>
438-
<Th sort={getSortParams(6)}>{columnNames.dataVol}</Th>
439-
<Th sort={getSortParams(7)}>{columnNames.lastActivity}</Th>
505+
<Th sort={getSortParams(6)}>{columnNames.lastActivity}</Th>
440506
<Th screenReaderText="Primary action" />
441507
</Tr>
442508
</Thead>
443-
<Tbody>
444-
{sortedWorkspaces.map((workspace, rowIndex) => (
445-
<Tr key={rowIndex}>
509+
{sortedWorkspaces.map((workspace, rowIndex) => (
510+
<Tbody key={rowIndex} isExpanded={isWorkspaceExpanded(workspace)}>
511+
<Tr>
512+
<Td
513+
expand={{
514+
rowIndex,
515+
isExpanded: isWorkspaceExpanded(workspace),
516+
onToggle: () => setWorkspaceExpanded(workspace, !isWorkspaceExpanded(workspace)),
517+
}}
518+
/>
446519
<Td dataLabel={columnNames.name}>{workspace.name}</Td>
447520
<Td dataLabel={columnNames.kind}>{workspace.kind}</Td>
448521
<Td dataLabel={columnNames.image}>{workspace.options.imageConfig}</Td>
@@ -453,9 +526,6 @@ export const Workspaces: React.FunctionComponent = () => {
453526
</Label>
454527
</Td>
455528
<Td dataLabel={columnNames.homeVol}>{workspace.podTemplate.volumes.home}</Td>
456-
<Td dataLabel={columnNames.dataVol}>
457-
{workspace.podTemplate.volumes.data[0].pvcName || ''}
458-
</Td>
459529
<Td dataLabel={columnNames.lastActivity}>
460530
<Timestamp
461531
date={new Date(workspace.status.activity.lastActivity)}
@@ -468,8 +538,9 @@ export const Workspaces: React.FunctionComponent = () => {
468538
<ActionsColumn items={defaultActions(workspace)} />
469539
</Td>
470540
</Tr>
471-
))}
472-
</Tbody>
541+
{isWorkspaceExpanded(workspace) && expandedRowRenderer(workspace)}
542+
</Tbody>
543+
))}
473544
</Table>
474545
<Pagination
475546
itemCount={333}

0 commit comments

Comments
 (0)