|
1 | 1 | import { Table, Tbody, Td, Th, Thead, Tr } from '@patternfly/react-table'; |
2 | 2 | import * as React from 'react'; |
3 | 3 |
|
4 | | -import { Label } from '@patternfly/react-core'; |
5 | 4 | import { useTranslation } from 'react-i18next'; |
6 | | -import { Link } from 'react-router-dom'; |
7 | | -import { valueFormat } from '../../utils/format'; |
8 | | -import { HealthColorSquare } from './health-color-square'; |
9 | | -import { ByResource, getAlertFilteredLabels, getAlertLink, getAllAlerts, getHealthMetadata } from './helper'; |
| 5 | +import { AlertRow, AlertSummaryCell } from './alert-row'; |
| 6 | +import { ByResource, getAllAlerts } from './helper'; |
10 | 7 |
|
11 | 8 | export interface RuleDetailsProps { |
12 | 9 | info: ByResource; |
13 | | - header: boolean; |
| 10 | + wide: boolean; |
14 | 11 | } |
15 | 12 |
|
16 | | -export const RuleDetails: React.FC<RuleDetailsProps> = ({ info, header }) => { |
| 13 | +export const RuleDetails: React.FC<RuleDetailsProps> = ({ info, wide }) => { |
17 | 14 | const { t } = useTranslation('plugin__netobserv-plugin'); |
18 | 15 |
|
19 | 16 | const allAlerts = getAllAlerts(info); |
20 | 17 |
|
21 | 18 | return ( |
22 | 19 | <Table data-test-rows-count={allAlerts.length} aria-label="Detailed alerting rules" variant="compact"> |
23 | | - {header && ( |
| 20 | + {wide && ( |
24 | 21 | <Thead> |
25 | 22 | <Th>{t('Summary')}</Th> |
26 | 23 | <Th>{t('State')}</Th> |
27 | 24 | <Th>{t('Severity')}</Th> |
28 | 25 | <Th>{t('Labels')}</Th> |
29 | 26 | <Th>{t('Value')}</Th> |
30 | 27 | <Th>{t('Description')}</Th> |
| 28 | + <Th screenReaderText="Links" /> |
31 | 29 | </Thead> |
32 | 30 | )} |
33 | | - {header ? ( |
| 31 | + {wide ? ( |
34 | 32 | <Tbody> |
35 | | - {allAlerts.map((a, i) => { |
36 | | - const md = getHealthMetadata(a.annotations); |
37 | | - const labels = getAlertFilteredLabels(a, info.name); |
38 | | - return ( |
39 | | - <Tr key={'detailed-rules-row-' + i}> |
40 | | - <Td> |
41 | | - <HealthColorSquare alert={a} /> |
42 | | - <Link to={getAlertLink(a)} title={t('Navigate to alert details')}> |
43 | | - {a.annotations['summary']} |
44 | | - </Link> |
45 | | - </Td> |
46 | | - <Td>{a.state}</Td> |
47 | | - <Td>{a.labels.severity}</Td> |
48 | | - <Td> |
49 | | - {labels.length === 0 |
50 | | - ? t('None') |
51 | | - : labels.map(kv => ( |
52 | | - <Label key={kv[0]}> |
53 | | - {kv[0]}={kv[1]} |
54 | | - </Label> |
55 | | - ))} |
56 | | - </Td> |
57 | | - <Td> |
58 | | - {valueFormat(a.value as number, 2)} |
59 | | - {md?.threshold && ' > ' + md.threshold + ' ' + md.unit} |
60 | | - </Td> |
61 | | - <Td>{a.annotations['description']}</Td> |
62 | | - </Tr> |
63 | | - ); |
64 | | - })} |
| 33 | + {allAlerts.map((a, i) => ( |
| 34 | + <AlertRow key={'detailed-rules-row-' + i} alert={a} resourceName={info.name} wide={wide} /> |
| 35 | + ))} |
65 | 36 | </Tbody> |
66 | 37 | ) : ( |
67 | 38 | allAlerts.map((a, i) => { |
68 | | - // in non-detailed mode, alert summaries take full cols span, and the other fields are displayed below; requires to have Tbody within Tr. |
69 | | - const md = getHealthMetadata(a.annotations); |
70 | | - const labels = getAlertFilteredLabels(a, info.name); |
| 39 | + // in non-detailed mode, alert summaries take full cols span, and the other fields are displayed below; requires to have a Tbody for each row. |
71 | 40 | return ( |
72 | 41 | <Tbody key={'detailed-rules-row-' + i} isExpanded> |
73 | 42 | <Tr isExpanded> |
74 | 43 | <Td noPadding colSpan={4}> |
75 | | - <HealthColorSquare alert={a} /> |
76 | | - <Link to={getAlertLink(a)} title={t('Navigate to alert details')}> |
77 | | - {a.annotations['summary']} |
78 | | - </Link> |
79 | | - </Td> |
80 | | - </Tr> |
81 | | - <Tr> |
82 | | - <Td noPadding>{a.state}</Td> |
83 | | - <Td>{a.labels.severity}</Td> |
84 | | - <Td> |
85 | | - {labels.length === 0 |
86 | | - ? t('None') |
87 | | - : labels.map(kv => ( |
88 | | - <Label key={kv[0]}> |
89 | | - {kv[0]}={kv[1]} |
90 | | - </Label> |
91 | | - ))} |
92 | | - </Td> |
93 | | - <Td> |
94 | | - {valueFormat(a.value as number, 2)} |
95 | | - {md?.threshold && ' > ' + md.threshold + ' ' + md.unit} |
| 44 | + <AlertSummaryCell alert={a} showTooltip={true} /> |
96 | 45 | </Td> |
97 | 46 | </Tr> |
| 47 | + <AlertRow alert={a} resourceName={info.name} wide={wide} /> |
98 | 48 | </Tbody> |
99 | 49 | ); |
100 | 50 | }) |
|
0 commit comments