Skip to content

Commit db82bd5

Browse files
authored
fix(ws): removed empty table column from workspace kinds table and fixed labels (#389)
Signed-off-by: paulovmr <832830+paulovmr@users.noreply.github.com>
1 parent 3c8c8e0 commit db82bd5

File tree

2 files changed

+43
-34
lines changed

2 files changed

+43
-34
lines changed

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

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import { CodeIcon, FilterIcon } from '@patternfly/react-icons';
3737
import { WorkspaceKind } from '~/shared/api/backendApiTypes';
3838
import useWorkspaceKinds from '~/app/hooks/useWorkspaceKinds';
3939
import { useWorkspaceCountPerKind } from '~/app/hooks/useWorkspaceCountPerKind';
40-
import { WorkspaceKindsColumnNames } from '~/app/types';
40+
import { WorkspaceKindsColumns } from '~/app/types';
4141
import ThemeAwareSearchInput from '~/app/components/ThemeAwareSearchInput';
4242
import CustomEmptyState from '~/shared/components/CustomEmptyState';
4343

@@ -47,13 +47,20 @@ export enum ActionType {
4747

4848
export const WorkspaceKinds: React.FunctionComponent = () => {
4949
// Table columns
50-
const columnNames: WorkspaceKindsColumnNames = {
51-
icon: '',
52-
name: 'Name',
53-
description: 'Description',
54-
deprecated: 'Status',
55-
numberOfWorkspaces: 'Number of workspaces',
56-
};
50+
const columns: WorkspaceKindsColumns = React.useMemo(
51+
() => ({
52+
icon: { name: '', label: 'Icon', id: 'icon' },
53+
name: { name: 'Name', label: 'Name', id: 'name' },
54+
description: { name: 'Description', label: 'Description', id: 'description' },
55+
deprecated: { name: 'Status', label: 'Status', id: 'status' },
56+
numberOfWorkspaces: {
57+
name: 'Number of workspaces',
58+
label: 'Number of workspaces',
59+
id: 'number-of-workspaces',
60+
},
61+
}),
62+
[],
63+
);
5764

5865
const [workspaceKinds, workspaceKindsLoaded, workspaceKindsError] = useWorkspaceKinds();
5966
const workspaceCountPerKind = useWorkspaceCountPerKind();
@@ -509,30 +516,27 @@ export const WorkspaceKinds: React.FunctionComponent = () => {
509516
<Table aria-label="Sortable table" ouiaId="SortableTable">
510517
<Thead>
511518
<Tr>
512-
<Th aria-label="WorkspaceKind Icon" />
513-
{Object.values(columnNames)
514-
.filter((name) => name !== '')
515-
.map((columnName, index) => (
516-
<Th
517-
key={`${columnName}-col-name`}
518-
sort={
519-
columnName === 'Name' || columnName === 'Status'
520-
? getSortParams(index)
521-
: undefined
522-
}
523-
>
524-
{columnName}
525-
</Th>
526-
))}
519+
{Object.values(columns).map((column, index) => (
520+
<Th
521+
aria-label={`${column.label} column`}
522+
key={`${column.id}-column`}
523+
sort={
524+
column.id === 'name' || column.id === 'status'
525+
? getSortParams(index)
526+
: undefined
527+
}
528+
>
529+
{column.name}
530+
</Th>
531+
))}
527532
<Th screenReaderText="Primary action" />
528533
</Tr>
529534
</Thead>
530535
{filteredWorkspaceKinds.length > 0 &&
531536
filteredWorkspaceKinds.map((workspaceKind, rowIndex) => (
532537
<Tbody id="workspace-kind-table-content" key={rowIndex} data-testid="table-body">
533538
<Tr id={`workspace-kind-table-row-${rowIndex + 1}`}>
534-
<Td />
535-
<Td dataLabel={columnNames.icon} style={{ width: '50px' }}>
539+
<Td dataLabel={columns.icon.name} style={{ width: '50px' }}>
536540
{workspaceKind.icon.url ? (
537541
<Brand
538542
src={workspaceKind.icon.url}
@@ -543,9 +547,9 @@ export const WorkspaceKinds: React.FunctionComponent = () => {
543547
<CodeIcon />
544548
)}
545549
</Td>
546-
<Td dataLabel={columnNames.name}>{workspaceKind.name}</Td>
550+
<Td dataLabel={columns.name.name}>{workspaceKind.name}</Td>
547551
<Td
548-
dataLabel={columnNames.description}
552+
dataLabel={columns.description.name}
549553
style={{ maxWidth: '200px', overflow: 'hidden' }}
550554
>
551555
<Tooltip content={workspaceKind.description}>
@@ -556,7 +560,7 @@ export const WorkspaceKinds: React.FunctionComponent = () => {
556560
</span>
557561
</Tooltip>
558562
</Td>
559-
<Td dataLabel={columnNames.deprecated}>
563+
<Td dataLabel={columns.deprecated.name}>
560564
{workspaceKind.deprecated ? (
561565
<Tooltip content={workspaceKind.deprecationMessage}>
562566
<Label color="red">Deprecated</Label>
@@ -565,7 +569,7 @@ export const WorkspaceKinds: React.FunctionComponent = () => {
565569
<Label color="green">Active</Label>
566570
)}
567571
</Td>
568-
<Td dataLabel={columnNames.numberOfWorkspaces}>
572+
<Td dataLabel={columns.numberOfWorkspaces.name}>
569573
{workspaceCountPerKind[workspaceKind.name] ?? 0}
570574
</Td>
571575

workspaces/frontend/src/app/types.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@ export interface WorkspacesColumnNames {
1919
redirectStatus: string;
2020
}
2121

22-
export interface WorkspaceKindsColumnNames {
23-
icon: string;
22+
export interface WorkspaceColumnDefinition {
2423
name: string;
25-
description: string;
26-
deprecated: string;
27-
numberOfWorkspaces: string;
24+
label: string;
25+
id: string;
26+
}
27+
export interface WorkspaceKindsColumns {
28+
icon: WorkspaceColumnDefinition;
29+
name: WorkspaceColumnDefinition;
30+
description: WorkspaceColumnDefinition;
31+
deprecated: WorkspaceColumnDefinition;
32+
numberOfWorkspaces: WorkspaceColumnDefinition;
2833
}
2934

3035
export interface WorkspaceFormProperties {

0 commit comments

Comments
 (0)