-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathuseVMNetworkTableColumns.tsx
More file actions
70 lines (65 loc) · 2.37 KB
/
useVMNetworkTableColumns.tsx
File metadata and controls
70 lines (65 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import React, { useMemo } from 'react';
import { Link } from 'react-router-dom-v5-compat';
import { ColumnConfig } from '@kubevirt-utils/hooks/useDataViewTableSort/types';
import { useKubevirtTranslation } from '@kubevirt-utils/hooks/useKubevirtTranslation';
import { getName } from '@kubevirt-utils/resources/shared';
import { getLocalnet, getMTU, getVLANID } from '@kubevirt-utils/resources/udn/selectors';
import { ClusterUserDefinedNetworkKind } from '@kubevirt-utils/resources/udn/types';
import { NO_DATA_DASH } from '@kubevirt-utils/resources/vm/utils/constants';
import VMNetworkActions from '../../actions/VMNetworkActions';
import { VM_NETWORKS_PATH } from '../../constants';
import MatchedProjects from '../components/MatchedProjects';
const useVMNetworkTableColumns = (): ColumnConfig<ClusterUserDefinedNetworkKind>[] => {
const { t } = useKubevirtTranslation();
return useMemo(
(): ColumnConfig<ClusterUserDefinedNetworkKind>[] => [
{
getValue: (row) => getName(row) ?? '',
key: 'name',
label: t('Name'),
renderCell: (row) => {
const name = getName(row);
return <Link to={`${VM_NETWORKS_PATH}/${name}`}>{name}</Link>;
},
sortable: true,
},
{
key: 'connected-projects',
label: t('Connected projects'),
renderCell: (row) => <MatchedProjects obj={row} />,
},
{
getValue: (row) => getLocalnet(row)?.physicalNetworkName ?? '',
key: 'physicalNetworkName',
label: t('Physical network name'),
renderCell: (row) => getLocalnet(row)?.physicalNetworkName || NO_DATA_DASH,
sortable: true,
},
{
getValue: (row) => String(getVLANID(row) ?? ''),
key: 'vlanID',
label: t('VLAN ID'),
renderCell: (row) => getVLANID(row) ?? NO_DATA_DASH,
sortable: true,
},
{
getValue: (row) => getMTU(row) ?? 0,
key: 'mtu',
label: t('MTU'),
renderCell: (row) => {
const mtu = getMTU(row);
return mtu ?? <div className="pf-v6-u-text-color-subtle">{t('Not available')}</div>;
},
sortable: true,
},
{
key: 'actions',
label: '',
props: { className: 'pf-v6-c-table__action' },
renderCell: (row) => <VMNetworkActions obj={row} />,
},
],
[t],
);
};
export default useVMNetworkTableColumns;