Skip to content

Commit 7c660e4

Browse files
authored
feat(ws): added namespaces tab to workspace kind details (#406)
Signed-off-by: paulovmr <[email protected]>
1 parent 248c242 commit 7c660e4

File tree

4 files changed

+62
-6
lines changed

4 files changed

+62
-6
lines changed

workspaces/frontend/src/app/hooks/useWorkspaceCountPerKind.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import * as React from 'react';
22
import { useNotebookAPI } from '~/app/hooks/useNotebookAPI';
33
import { Workspace, WorkspaceKind } from '~/shared/api/backendApiTypes';
4-
import { WorkspaceCountPerKindImagePodConfig } from '~/app/types';
4+
import { WorkspaceCountPerOption } from '~/app/types';
55

6-
export type WorkspaceCountPerKind = Record<
7-
WorkspaceKind['name'],
8-
WorkspaceCountPerKindImagePodConfig
9-
>;
6+
export type WorkspaceCountPerKind = Record<WorkspaceKind['name'], WorkspaceCountPerOption>;
107

118
export const useWorkspaceCountPerKind = (): WorkspaceCountPerKind => {
129
const { api } = useNotebookAPI();
@@ -22,6 +19,7 @@ export const useWorkspaceCountPerKind = (): WorkspaceCountPerKind => {
2219
count: 0,
2320
countByImage: {},
2421
countByPodConfig: {},
22+
countByNamespace: {},
2523
};
2624
acc[workspace.workspaceKind.name].count =
2725
(acc[workspace.workspaceKind.name].count || 0) + 1;
@@ -37,6 +35,8 @@ export const useWorkspaceCountPerKind = (): WorkspaceCountPerKind => {
3735
(acc[workspace.workspaceKind.name].countByPodConfig[
3836
workspace.podTemplate.options.podConfig.current.id
3937
] || 0) + 1;
38+
acc[workspace.workspaceKind.name].countByNamespace[workspace.namespace] =
39+
(acc[workspace.workspaceKind.name].countByNamespace[workspace.namespace] || 0) + 1;
4040
return acc;
4141
}, {});
4242
setWorkspaceCountPerKind(countPerKind);

workspaces/frontend/src/app/pages/WorkspaceKinds/details/WorkspaceKindDetails.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
} from '@patternfly/react-core';
1515
import { WorkspaceKind } from '~/shared/api/backendApiTypes';
1616
import { WorkspaceCountPerKind } from '~/app/hooks/useWorkspaceCountPerKind';
17+
import { WorkspaceKindDetailsNamespaces } from '~/app/pages/WorkspaceKinds/details/WorkspaceKindDetailsNamespaces';
1718
import { WorkspaceKindDetailsOverview } from './WorkspaceKindDetailsOverview';
1819
import { WorkspaceKindDetailsImages } from './WorkspaceKindDetailsImages';
1920
import { WorkspaceKindDetailsPodConfigs } from './WorkspaceKindDetailsPodConfigs';
@@ -67,6 +68,12 @@ export const WorkspaceKindDetails: React.FunctionComponent<WorkspaceKindDetailsP
6768
tabContentId="podConfigsTabContent"
6869
aria-label="Pod Configs"
6970
/>
71+
<Tab
72+
eventKey={3}
73+
title={<TabTitleText>Namespaces</TabTitleText>}
74+
tabContentId="namespacesTabContent"
75+
aria-label="Namespaces"
76+
/>
7077
</Tabs>
7178
</DrawerPanelBody>
7279

@@ -110,6 +117,20 @@ export const WorkspaceKindDetails: React.FunctionComponent<WorkspaceKindDetailsP
110117
/>
111118
</TabContentBody>
112119
</TabContent>
120+
<TabContent
121+
key={3}
122+
eventKey={3}
123+
id="namespacesTabContent"
124+
activeKey={activeTabKey}
125+
hidden={activeTabKey !== 3}
126+
>
127+
<TabContentBody hasPadding>
128+
<WorkspaceKindDetailsNamespaces
129+
workspaceKind={workspaceKind}
130+
workspaceCountPerKind={workspaceCountPerKind}
131+
/>
132+
</TabContentBody>
133+
</TabContent>
113134
</DrawerPanelBody>
114135
</DrawerPanelContent>
115136
);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React from 'react';
2+
import { List, ListItem } from '@patternfly/react-core';
3+
import { WorkspaceKind } from '~/shared/api/backendApiTypes';
4+
import { WorkspaceCountPerKind } from '~/app/hooks/useWorkspaceCountPerKind';
5+
6+
type WorkspaceDetailsNamespacesProps = {
7+
workspaceKind: WorkspaceKind;
8+
workspaceCountPerKind: WorkspaceCountPerKind;
9+
};
10+
11+
export const WorkspaceKindDetailsNamespaces: React.FunctionComponent<
12+
WorkspaceDetailsNamespacesProps
13+
> = ({ workspaceKind, workspaceCountPerKind }) => (
14+
<List isPlain>
15+
{Object.keys(
16+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
17+
workspaceCountPerKind[workspaceKind.name]
18+
? workspaceCountPerKind[workspaceKind.name].countByNamespace
19+
: [],
20+
).map((namespace, rowIndex) => (
21+
<ListItem key={rowIndex}>
22+
{namespace}:{' '}
23+
{
24+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
25+
workspaceCountPerKind[workspaceKind.name]
26+
? workspaceCountPerKind[workspaceKind.name].countByNamespace[namespace]
27+
: 0
28+
}
29+
{' Workspaces'}
30+
</ListItem>
31+
))}
32+
</List>
33+
);

workspaces/frontend/src/app/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
WorkspacePodConfigValue,
55
WorkspacePodVolumeMount,
66
WorkspacePodSecretMount,
7+
Workspace,
78
} from '~/shared/api/backendApiTypes';
89

910
export interface WorkspacesColumnNames {
@@ -47,8 +48,9 @@ export interface WorkspaceFormData {
4748
properties: WorkspaceFormProperties;
4849
}
4950

50-
export interface WorkspaceCountPerKindImagePodConfig {
51+
export interface WorkspaceCountPerOption {
5152
count: number;
5253
countByImage: Record<WorkspaceImageConfigValue['id'], number>;
5354
countByPodConfig: Record<WorkspacePodConfigValue['id'], number>;
55+
countByNamespace: Record<Workspace['namespace'], number>;
5456
}

0 commit comments

Comments
 (0)