Skip to content

Commit 1662c79

Browse files
authored
Merge pull request #553 from mudit06mah/feat/knative-refactor
knative: kservice: common: Refactor Kservice sections to match Headlamp UI
2 parents b6ef1de + 4a42adb commit 1662c79

File tree

7 files changed

+920
-666
lines changed

7 files changed

+920
-666
lines changed

knative/src/components/common/ConditionsSection.tsx

Lines changed: 44 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { SectionBox } from '@kinvolk/headlamp-plugin/lib/CommonComponents';
18-
import {
19-
Chip,
20-
Table,
21-
TableBody,
22-
TableCell,
23-
TableContainer,
24-
TableHead,
25-
TableRow,
26-
Tooltip,
27-
Typography,
28-
} from '@mui/material';
17+
import { SectionBox, SimpleTable } from '@kinvolk/headlamp-plugin/lib/CommonComponents';
18+
import { Chip, Tooltip, Typography } from '@mui/material';
2919
import type { Condition } from '../../resources/knative/common';
3020
import { getAge } from '../../utils/time';
3121

@@ -34,62 +24,50 @@ type ConditionsSectionProps = {
3424
};
3525

3626
export default function ConditionsSection({ conditions }: ConditionsSectionProps) {
27+
const columns = [
28+
{
29+
label: 'Type',
30+
getter: (c: Condition) => c.type,
31+
},
32+
{
33+
label: 'Status',
34+
getter: (c: Condition) =>
35+
c.status === 'True' ? (
36+
<Chip label="True" color="success" size="small" />
37+
) : c.status === 'False' ? (
38+
<Chip label="False" color="error" size="small" />
39+
) : (
40+
<Chip label={c.status || 'Unknown'} color="warning" size="small" />
41+
),
42+
},
43+
{
44+
label: 'Reason',
45+
getter: (c: Condition) => c.reason || '-',
46+
},
47+
{
48+
label: 'Message',
49+
getter: (c: Condition) =>
50+
c.message ? (
51+
<Tooltip title={c.message}>
52+
<Typography variant="body2" color="text.secondary" noWrap sx={{ maxWidth: 400 }}>
53+
{c.message}
54+
</Typography>
55+
</Tooltip>
56+
) : (
57+
<Typography variant="body2" color="text.secondary" noWrap sx={{ maxWidth: 400 }}>
58+
-
59+
</Typography>
60+
),
61+
},
62+
{
63+
label: 'Last Transition',
64+
getter: (c: Condition) => (c.lastTransitionTime ? getAge(c.lastTransitionTime) : '-'),
65+
},
66+
];
67+
3768
return (
3869
<SectionBox title="Conditions">
39-
<TableContainer>
40-
<Table size="small" sx={{ tableLayout: 'fixed', width: '100%' }}>
41-
<TableHead>
42-
<TableRow>
43-
<TableCell>Type</TableCell>
44-
<TableCell>Status</TableCell>
45-
<TableCell>Reason</TableCell>
46-
<TableCell>Message</TableCell>
47-
<TableCell>Last Transition</TableCell>
48-
</TableRow>
49-
</TableHead>
50-
<TableBody>
51-
{conditions.map(c => (
52-
<TableRow key={c.type}>
53-
<TableCell>{c.type}</TableCell>
54-
<TableCell>
55-
{c.status === 'True' ? (
56-
<Chip label="True" color="success" size="small" />
57-
) : c.status === 'False' ? (
58-
<Chip label="False" color="error" size="small" />
59-
) : (
60-
<Chip label={c.status || 'Unknown'} color="warning" size="small" />
61-
)}
62-
</TableCell>
63-
<TableCell>{c.reason || '-'}</TableCell>
64-
<TableCell>
65-
{c.message ? (
66-
<Tooltip title={c.message}>
67-
<Typography
68-
variant="body2"
69-
color="text.secondary"
70-
noWrap
71-
sx={{ maxWidth: 400 }}
72-
>
73-
{c.message}
74-
</Typography>
75-
</Tooltip>
76-
) : (
77-
<Typography
78-
variant="body2"
79-
color="text.secondary"
80-
noWrap
81-
sx={{ maxWidth: 400 }}
82-
>
83-
-
84-
</Typography>
85-
)}
86-
</TableCell>
87-
<TableCell>{c.lastTransitionTime ? getAge(c.lastTransitionTime) : '-'}</TableCell>
88-
</TableRow>
89-
))}
90-
</TableBody>
91-
</Table>
92-
</TableContainer>
70+
<SimpleTable columns={columns} data={conditions} />
9371
</SectionBox>
9472
);
9573
}

0 commit comments

Comments
 (0)