forked from guacsec/trustify-ui
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvulnerability-table.tsx
More file actions
149 lines (143 loc) · 5 KB
/
vulnerability-table.tsx
File metadata and controls
149 lines (143 loc) · 5 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
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
import React from "react";
import { NavLink } from "react-router-dom";
import {
Table,
TableText,
Tbody,
Td,
Th,
Thead,
Tr,
} from "@patternfly/react-table";
import { extendedSeverityFromSeverity } from "@app/api/models";
import { SeverityShieldAndText } from "@app/components/SeverityShieldAndText";
import { SimplePagination } from "@app/components/SimplePagination";
import {
ConditionalTableBody,
TableHeaderContentWithControls,
TableRowContentWithControls,
} from "@app/components/TableControls";
import { VulnerabilityDescription } from "@app/components/VulnerabilityDescription";
import { formatDate } from "@app/utils/utils";
import { TdWithFocusStatus } from "@app/components/TdWithFocusStatus";
import { SbomsCount } from "./components/SbomsCount";
import { VulnerabilitySearchContext } from "./vulnerability-context";
export const VulnerabilityTable: React.FC = () => {
const { isFetching, fetchError, totalItemCount, tableControls } =
React.useContext(VulnerabilitySearchContext);
const {
numRenderedColumns,
currentPageItems,
propHelpers: {
paginationProps,
tableProps,
getThProps,
getTrProps,
getTdProps,
},
} = tableControls;
return (
<>
<Table {...tableProps} aria-label="Vulnerability table">
<Thead>
<Tr>
<TableHeaderContentWithControls {...tableControls}>
<Th {...getThProps({ columnKey: "identifier" })} />
<Th {...getThProps({ columnKey: "title" })} />
<Th
{...getThProps({ columnKey: "severity" })}
info={{
tooltip:
"The Common Vulnerability Scoring System measuring the severity of security flaws.",
}}
/>
<Th {...getThProps({ columnKey: "published" })} />
<Th {...getThProps({ columnKey: "sboms" })} />
</TableHeaderContentWithControls>
</Tr>
</Thead>
<ConditionalTableBody
isLoading={isFetching}
isError={!!fetchError}
isNoData={totalItemCount === 0}
numRenderedColumns={numRenderedColumns}
>
{currentPageItems.map((item, rowIndex) => {
return (
<Tbody key={item.identifier}>
<Tr {...getTrProps({ item })}>
<TableRowContentWithControls
{...tableControls}
item={item}
rowIndex={rowIndex}
>
<Td
width={15}
modifier="breakWord"
{...getTdProps({
columnKey: "identifier",
item: item,
rowIndex,
})}
>
<NavLink to={`/vulnerabilities/${item.identifier}`}>
{item.identifier}
</NavLink>
</Td>
<TdWithFocusStatus>
{(isFocused, setIsFocused) => (
<Td
width={45}
modifier="truncate"
onFocus={() => setIsFocused(true)}
onBlur={() => setIsFocused(false)}
tabIndex={0}
{...getTdProps({ columnKey: "title" })}
>
<TableText
focused={isFocused}
wrapModifier="truncate"
>
<VulnerabilityDescription vulnerability={item} />
</TableText>
</Td>
)}
</TdWithFocusStatus>
<Td width={10} {...getTdProps({ columnKey: "severity" })}>
<SeverityShieldAndText
value={extendedSeverityFromSeverity(
item.average_severity,
)}
score={item.average_score}
showLabel
showScore
/>
</Td>
<Td width={10} {...getTdProps({ columnKey: "published" })}>
{formatDate(item.published)}
</Td>
<Td
width={10}
{...getTdProps({
columnKey: "sboms",
item: item,
rowIndex,
})}
>
<SbomsCount vulnerabilityId={item.identifier} />
</Td>
</TableRowContentWithControls>
</Tr>
</Tbody>
);
})}
</ConditionalTableBody>
</Table>
<SimplePagination
idPrefix="vulnerability-table"
isTop={false}
paginationProps={paginationProps}
/>
</>
);
};