forked from openshift-assisted/assisted-installer-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisksTable.tsx
233 lines (221 loc) · 7.16 KB
/
DisksTable.tsx
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
import React from 'react';
import {
TextContent,
Text,
TextVariants,
Popover,
Alert,
AlertVariant,
} from '@patternfly/react-core';
import { TableVariant, Thead, Tbody, Table, Th, Tr, Td } from '@patternfly/react-table';
import type { Disk, Host } from '@openshift-assisted/types/assisted-installer-service';
import type { WithTestID } from '../../types/index';
import DiskRole, { OnDiskRoleType } from '../hosts/DiskRole';
import DiskLimitations from '../hosts/DiskLimitations';
import { ExclamationTriangleIcon } from '@patternfly/react-icons/dist/js/icons/exclamation-triangle-icon';
import FormatDiskCheckbox, {
DiskFormattingType,
isInDiskSkipFormattingList,
} from '../hosts/FormatDiskCheckbox';
import { fileSize } from '../../utils';
import { PopoverIcon, UiIcon } from '../ui';
import { useTranslation } from '../../hooks/use-translation-wrapper';
import { TFunction } from 'i18next';
interface DisksTableProps extends WithTestID {
canEditDisks?: (host: Host) => boolean;
onDiskRole?: OnDiskRoleType;
host: Host;
disks: Disk[];
installationDiskId?: string;
updateDiskSkipFormatting?: DiskFormattingType;
}
const diskColumns = (t: TFunction, showFormat: boolean) =>
[
{ title: t('ai:Name') },
{ title: t('ai:Role') },
{ title: t('ai:Limitations') },
showFormat ? { title: t('ai:Format?') } : '',
{ title: t('ai:Drive type') },
{ title: t('ai:Size') },
{ title: t('ai:Serial') },
{ title: t('ai:Model') },
{
title: (
<>
WWN{' '}
<PopoverIcon bodyContent={t('ai:World Wide Name (WWN) is a unique disk identifier.')} />
</>
),
},
].filter(Boolean) as { title: string | React.ReactNode }[];
const SkipFormattingDisk = () => (
<TextContent>
<Text component={TextVariants.p}>This bootable disk will skip formatting</Text>
</TextContent>
);
const getDiskLimitation = (
diskName: Disk['name'],
hostName: Host['requestedHostname'],
holder: Disk,
) => {
if (holder.driveType) {
switch (holder.driveType) {
case 'LVM':
return `LVM logical volumes were found on the installation disk ${
diskName as string
} selected for host ${hostName as string} and will be deleted during installation.`;
case 'RAID':
return `The installation disk ${diskName as string} selected for host ${
hostName as string
}, is part of a software RAID that will be deleted during the installation.`;
case 'Multipath':
return `The installation disk ${diskName as string} selected for host ${
hostName as string
} is managed by multipath. We strongly recommend using the multipath device ${
holder.name as string
} to improve reliability.`;
}
}
};
const DiskName = ({
disk,
disks,
host,
installationDiskId,
}: {
disk: Disk;
disks: Disk[];
host: Host;
installationDiskId?: string;
}) => {
const isIndented = disk.holders?.split(',').length === 1;
let diskLimitations = null;
if (disk.id === installationDiskId) {
const parentDisk = disks.find((d) => disk.holders?.split(',').includes(d.name as string));
if (parentDisk) {
diskLimitations = getDiskLimitation(disk.name, host.requestedHostname, parentDisk);
}
}
return (
<>
{isIndented && <span style={{ width: '1rem', display: 'inline-block' }} />}
{isInDiskSkipFormattingList(host, disk.id) && (
<Popover bodyContent={<SkipFormattingDisk />} minWidth="20rem" maxWidth="30rem">
<UiIcon size="sm" status="warning" icon={<ExclamationTriangleIcon />} />
</Popover>
)}
{' '}
{disk.bootable ? `${disk.name || ''} (bootable)` : disk.name}
{diskLimitations && (
<>
{' '}
<Popover
headerContent="Warning"
bodyContent={<Alert variant={AlertVariant.warning} isInline title={diskLimitations} />}
minWidth="20rem"
maxWidth="30rem"
data-testid="disk-limitations-popover"
>
<UiIcon size="sm" status="warning" icon={<ExclamationTriangleIcon />} />
</Popover>
</>
)}
</>
);
};
const DisksTable = ({
canEditDisks,
host,
disks,
installationDiskId,
testId,
onDiskRole,
updateDiskSkipFormatting,
}: DisksTableProps) => {
const { t } = useTranslation();
const isEditable = !!canEditDisks?.(host);
const diskColumnTitles = diskColumns(t, isEditable);
const rows = disks
.filter((disk) => disk.driveType !== 'LVM')
.sort((a, b) => (a.name && a.name.localeCompare(b.name as string)) || 0)
.sort((a, b) => {
const aVal = (a.holders || a.name) as string;
const bVal = (b.holders || b.name) as string;
return aVal?.localeCompare(bVal) || 0;
})
.map((disk, index) => {
const rowCells = [
{
title: (
<DiskName
disk={disk}
disks={disks}
host={host}
installationDiskId={installationDiskId}
/>
),
props: { 'data-testid': 'disk-name' },
},
{
title: (
<DiskRole
host={host}
disk={disk}
installationDiskId={installationDiskId}
isEditable={isEditable}
onDiskRole={onDiskRole}
/>
),
props: { 'data-testid': 'disk-role' },
},
{ title: <DiskLimitations disk={disk} />, props: { 'data-testid': 'disk-limitations' } },
isEditable
? {
title: (
<FormatDiskCheckbox
host={host}
diskId={disk.id}
installationDiskId={installationDiskId}
index={index}
updateDiskSkipFormatting={updateDiskSkipFormatting}
/>
),
props: { 'data-testid': 'disk-formatted' },
}
: null,
{ title: disk.driveType, props: { 'data-testid': 'drive-type' } },
{ title: fileSize(disk.sizeBytes || 0, 2, 'si'), props: { 'data-testid': 'disk-size' } },
{ title: disk.serial, props: { 'data-testid': 'disk-serial' } },
{ title: disk.model, props: { 'data-testid': 'disk-model' } },
{ title: disk.wwn, props: { 'data-testid': 'disk-wwn' } },
].filter(Boolean); // Remove null values to keep alignment
return { key: disk.path, cells: rowCells } as {
key: string;
cells: { title: string | React.ReactNode; props: object }[];
};
});
return (
<Table data-testid={testId} variant={TableVariant.compact} aria-label="Host's disks table">
<Thead>
<Tr>
{diskColumnTitles.map((col, i) => (
<Th key={`col-${i}`}>{col.title}</Th>
))}
</Tr>
</Thead>
<Tbody>
{rows.map((row, i) => (
// eslint-disable-next-line no-console
<Tr key={`disk-row-${row.key}`} data-testid={`disk-row-${row.key}`}>
{row.cells.map((cell, j) => (
<Td key={`cell-${i}-${j}`} {...cell.props}>
{cell.title}
</Td>
))}
</Tr>
))}
</Tbody>
</Table>
);
};
export { DisksTable, getDiskLimitation };