-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathvulnerability-context.tsx
124 lines (113 loc) · 3.28 KB
/
vulnerability-context.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
import React from "react";
import { AxiosError } from "axios";
import { VulnerabilitySummary } from "@app/client";
import { FilterType } from "@app/components/FilterToolbar";
import {
FILTER_TEXT_CATEGORY_KEY,
TablePersistenceKeyPrefixes,
} from "@app/Constants";
import {
getHubRequestParams,
ITableControls,
useTableControlProps,
useTableControlState,
} from "@app/hooks/table-controls";
import { useSelectionState } from "@app/hooks/useSelectionState";
import { useFetchVulnerabilities } from "@app/queries/vulnerabilities";
export interface IVulnerabilitySearchContext {
tableControls: ITableControls<
VulnerabilitySummary,
"identifier" | "title" | "severity" | "published" | "sboms",
"published" | "severity",
"" | "average_severity" | "published",
string
>;
totalItemCount: number;
isFetching: boolean;
fetchError: AxiosError;
}
const contextDefaultValue = {} as IVulnerabilitySearchContext;
export const VulnerabilitySearchContext =
React.createContext<IVulnerabilitySearchContext>(contextDefaultValue);
interface IVulnerabilityProvider {
children: React.ReactNode;
}
export const VulnerabilitySearchProvider: React.FunctionComponent<
IVulnerabilityProvider
> = ({ children }) => {
const tableControlState = useTableControlState({
tableName: "vulnerability",
persistenceKeyPrefix: TablePersistenceKeyPrefixes.vulnerabilities,
persistTo: "urlParams",
columnNames: {
identifier: "ID",
title: "Description",
severity: "CVSS",
published: "Date published",
sboms: "Related documents",
},
isPaginationEnabled: true,
isSortEnabled: true,
sortableColumns: ["published", "severity"],
isFilterEnabled: true,
filterCategories: [
{
categoryKey: FILTER_TEXT_CATEGORY_KEY,
title: "Filter text",
placeholderText: "Search",
type: FilterType.search,
},
{
categoryKey: "average_severity",
title: "CVSS",
placeholderText: "CVSS",
type: FilterType.multiselect,
selectOptions: [
{ value: "none", label: "None" },
{ value: "low", label: "Low" },
{ value: "medium", label: "Medium" },
{ value: "high", label: "High" },
{ value: "critical", label: "Critical" },
],
},
{
categoryKey: "published",
title: "Created on",
type: FilterType.dateRange,
},
],
isExpansionEnabled: true,
expandableVariant: "compound",
});
const {
result: { data: vulnerabilities, total: totalItemCount },
isFetching,
fetchError,
} = useFetchVulnerabilities(
getHubRequestParams({
...tableControlState,
hubSortFieldKeys: {
severity: "average_severity",
published: "published",
},
})
);
const tableControls = useTableControlProps({
...tableControlState,
idProperty: "identifier",
currentPageItems: vulnerabilities,
totalItemCount,
isLoading: isFetching,
selectionState: useSelectionState({
items: vulnerabilities,
isEqual: (a, b) => a.identifier === b.identifier,
}),
});
return (
<VulnerabilitySearchContext.Provider
value={{ totalItemCount, isFetching, fetchError, tableControls }}
>
{children}
</VulnerabilitySearchContext.Provider>
);
};