Skip to content

Commit 31c060b

Browse files
committed
frontend: Home/ClusterTable: Add selecting multiple clusters
Signed-off-by: René Dudfield <renedudfield@microsoft.com>
1 parent 824b0f8 commit 31c060b

File tree

8 files changed

+71
-29
lines changed

8 files changed

+71
-29
lines changed

frontend/src/components/App/Home/ClusterTable.tsx

Lines changed: 64 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import { Icon } from '@iconify/react';
2-
import { useTheme } from '@mui/material';
2+
import { Button, useTheme } from '@mui/material';
33
import Box from '@mui/material/Box';
44
import Typography from '@mui/material/Typography';
55
import { useTranslation } from 'react-i18next';
6+
import { generatePath, useHistory } from 'react-router-dom';
67
import { useClustersConf, useClustersVersion } from '../../../lib/k8s';
78
import { ApiError } from '../../../lib/k8s/apiProxy';
89
import { Cluster } from '../../../lib/k8s/cluster';
9-
import { Link } from '../../common';
10-
import ResourceTable from '../../common/Resource/ResourceTable';
10+
import { getClusterPrefixedPath } from '../../../lib/util';
11+
import { Link, Table } from '../../common';
1112
import ClusterContextMenu from './ClusterContextMenu';
13+
import { MULTI_HOME_ENABLED } from './config';
1214
import { getCustomClusterNames } from './customClusterNames';
1315

1416
/**
@@ -80,6 +82,7 @@ export default function ClusterTable({
8082
clusters,
8183
warningLabels,
8284
}: ClusterTableProps) {
85+
const history = useHistory();
8386
const { t } = useTranslation(['translation']);
8487

8588
/**
@@ -99,56 +102,88 @@ export default function ClusterTable({
99102
}
100103
return 'Unknown';
101104
}
105+
const viewClusters = t('View Clusters');
102106

103107
return (
104-
<ResourceTable<any>
105-
defaultSortingColumn={{ id: 'name', desc: false }}
108+
<Table
106109
columns={[
107110
{
108111
id: 'name',
109-
label: t('Name'),
110-
getValue: cluster => cluster.name,
111-
render: ({ name }) => (
112-
<Link routeName="cluster" params={{ cluster: name }}>
113-
{name}
112+
header: t('Name'),
113+
accessorKey: 'name',
114+
Cell: ({ row: { original } }) => (
115+
<Link routeName="cluster" params={{ cluster: original.name }}>
116+
{original.name}
114117
</Link>
115118
),
116119
},
117120
{
118-
label: t('Origin'),
119-
getValue: cluster => getOrigin(cluster),
120-
render: ({ name }) => (
121-
<Typography variant="body2">{getOrigin((clusters || {})[name])}</Typography>
121+
header: t('Origin'),
122+
accessorFn: cluster => getOrigin(cluster),
123+
Cell: ({ row: { original } }) => (
124+
<Typography variant="body2">{getOrigin((clusters || {})[original.name])}</Typography>
122125
),
123126
},
124127
{
125-
label: t('Status'),
126-
getValue: cluster =>
128+
header: t('Status'),
129+
accessorFn: cluster =>
127130
errors[cluster.name] === null ? 'Active' : errors[cluster.name]?.message,
128-
render: ({ name }) => <ClusterStatus error={errors[name]} />,
131+
Cell: ({ row: { original } }) => <ClusterStatus error={errors[original.name]} />,
129132
},
133+
{ header: t('Warnings'), accessorFn: cluster => warningLabels[cluster.name] },
130134
{
131-
label: t('Warnings'),
132-
getValue: ({ name }) => warningLabels[name],
135+
header: t('glossary|Kubernetes Version'),
136+
accessorFn: ({ name }) => versions[name]?.gitVersion || '⋯',
133137
},
134138
{
135-
label: t('glossary|Kubernetes Version'),
136-
getValue: ({ name }) => versions[name]?.gitVersion || '⋯',
137-
},
138-
{
139-
label: '',
140-
getValue: cluster =>
141-
errors[cluster.name] === null ? 'Active' : errors[cluster.name]?.message,
142-
cellProps: {
139+
header: '',
140+
muiTableBodyCellProps: {
143141
align: 'right',
144142
},
145-
render: cluster => {
143+
accessorFn: cluster =>
144+
errors[cluster.name] === null ? 'Active' : errors[cluster.name]?.message,
145+
Cell: ({ row: { original: cluster } }) => {
146146
return <ClusterContextMenu cluster={cluster} />;
147147
},
148148
},
149149
]}
150150
data={Object.values(customNameClusters)}
151-
id="headlamp-home-clusters"
151+
enableRowSelection={
152+
MULTI_HOME_ENABLED
153+
? row => {
154+
// Only allow selection if the cluster is working
155+
return !errors[row.original.name];
156+
}
157+
: false
158+
}
159+
initialState={{
160+
sorting: [{ id: 'name', desc: false }],
161+
}}
162+
muiToolbarAlertBannerProps={{
163+
sx: theme => ({
164+
background: theme.palette.background.muted,
165+
}),
166+
}}
167+
renderToolbarAlertBannerContent={({ table }) => (
168+
<Button
169+
variant="contained"
170+
sx={{
171+
marginLeft: 1,
172+
}}
173+
onClick={() => {
174+
history.push({
175+
pathname: generatePath(getClusterPrefixedPath(), {
176+
cluster: table
177+
.getSelectedRowModel()
178+
.rows.map(it => it.original.name)
179+
.join('+'),
180+
}),
181+
});
182+
}}
183+
>
184+
{viewClusters}
185+
</Button>
186+
)}
152187
/>
153188
);
154189
}

frontend/src/i18n/locales/de/translation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"Active": "Aktiv",
2424
"Plugin": "",
2525
"In-cluster": "",
26+
"View Clusters": "",
2627
"Name": "Name",
2728
"Origin": "",
2829
"Status": "Status",

frontend/src/i18n/locales/en/translation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"Active": "Active",
2424
"Plugin": "Plugin",
2525
"In-cluster": "In-cluster",
26+
"View Clusters": "View Clusters",
2627
"Name": "Name",
2728
"Origin": "Origin",
2829
"Status": "Status",

frontend/src/i18n/locales/es/translation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"Active": "Activo",
2424
"Plugin": "Plugin",
2525
"In-cluster": "En-cluster",
26+
"View Clusters": "",
2627
"Name": "Nombre",
2728
"Origin": "Origen",
2829
"Status": "Estado",

frontend/src/i18n/locales/fr/translation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"Active": "Actif",
2424
"Plugin": "",
2525
"In-cluster": "",
26+
"View Clusters": "",
2627
"Name": "Nom",
2728
"Origin": "",
2829
"Status": "Statut",

frontend/src/i18n/locales/it/translation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"Active": "Attivo",
2424
"Plugin": "Estensione",
2525
"In-cluster": "In-cluster",
26+
"View Clusters": "",
2627
"Name": "Nome",
2728
"Origin": "Origine",
2829
"Status": "Stato",

frontend/src/i18n/locales/pt/translation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"Active": "Activo",
2424
"Plugin": "Plugin",
2525
"In-cluster": "No cluster",
26+
"View Clusters": "",
2627
"Name": "Nome",
2728
"Origin": "Origem",
2829
"Status": "Estado",

frontend/src/i18n/locales/zh-tw/translation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"Active": "活躍",
2424
"Plugin": "外掛",
2525
"In-cluster": "叢集內",
26+
"View Clusters": "",
2627
"Name": "名稱",
2728
"Origin": "來源",
2829
"Status": "狀態",

0 commit comments

Comments
 (0)