forked from guacsec/trustify-ui
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadvisory-details.tsx
More file actions
141 lines (130 loc) · 4.02 KB
/
advisory-details.tsx
File metadata and controls
141 lines (130 loc) · 4.02 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
import React from "react";
import {
Button,
Flex,
FlexItem,
Label,
PageSection,
Split,
SplitItem,
Tab,
TabContent,
TabTitleText,
Tabs,
Text,
TextContent,
} from "@patternfly/react-core";
import DownloadIcon from "@patternfly/react-icons/dist/esm/icons/download-icon";
import { PathParam, useRouteParams } from "@app/Routes";
import { LoadingWrapper } from "@app/components/LoadingWrapper";
import { useDownload } from "@app/hooks/domain-controls/useDownload";
import { useFetchAdvisoryById } from "@app/queries/advisories";
import { Overview } from "./overview";
import { VulnerabilitiesByAdvisory } from "./vulnerabilities-by-advisory";
export const AdvisoryDetails: React.FC = () => {
const [activeTabKey, setActiveTabKey] = React.useState<string | number>(0);
const handleTabClick = (
_event: React.MouseEvent | React.KeyboardEvent | MouseEvent,
tabIndex: string | number,
) => {
setActiveTabKey(tabIndex);
};
const infoTabRef = React.createRef<HTMLElement>();
const vulnerabilitiesTabRef = React.createRef<HTMLElement>();
//
const advisoryId = useRouteParams(PathParam.ADVISORY_ID);
const { advisory, isFetching, fetchError } = useFetchAdvisoryById(advisoryId);
const { downloadAdvisory } = useDownload();
return (
<>
<PageSection variant="light">
<Split>
<SplitItem isFilled>
<Flex>
<FlexItem spacer={{ default: "spacerSm" }}>
<TextContent>
<Text component="h1">
{advisory?.document_id ?? advisoryId ?? ""}
</Text>
<Text component="p">Advisory detail information</Text>
</TextContent>
</FlexItem>
<FlexItem>
{advisory?.labels.type && (
<Label color="blue">{advisory?.labels.type}</Label>
)}
</FlexItem>
</Flex>
</SplitItem>
<SplitItem>
{!isFetching && (
<Button
variant="secondary"
icon={<DownloadIcon />}
onClick={() => {
if (advisoryId) {
downloadAdvisory(
advisoryId,
advisory?.identifier
? `${advisory?.identifier}.json`
: `${advisoryId}.json`,
);
}
}}
>
Download
</Button>
)}
</SplitItem>
</Split>
</PageSection>
<PageSection type="nav">
<Tabs
mountOnEnter
activeKey={activeTabKey}
onSelect={handleTabClick}
aria-label="Tabs that contain the SBOM information"
role="region"
>
<Tab
eventKey={0}
title={<TabTitleText>Info</TabTitleText>}
tabContentId="refTabInfoSection"
tabContentRef={infoTabRef}
/>
<Tab
eventKey={1}
title={<TabTitleText>Vulnerabilities</TabTitleText>}
tabContentId="refVulnerabilitiesSection"
tabContentRef={vulnerabilitiesTabRef}
/>
</Tabs>
</PageSection>
<PageSection>
<TabContent
eventKey={0}
id="refTabInfoSection"
ref={infoTabRef}
aria-label="Information of the Advisory"
>
<LoadingWrapper isFetching={isFetching} fetchError={fetchError}>
{advisory && <Overview advisory={advisory} />}
</LoadingWrapper>
</TabContent>
<TabContent
eventKey={1}
id="refVulnerabilitiesSection"
ref={vulnerabilitiesTabRef}
aria-label="Vulnerabilities within the SBOM"
hidden
>
<VulnerabilitiesByAdvisory
isFetching={isFetching}
fetchError={fetchError}
vulnerabilities={advisory?.vulnerabilities || []}
/>
</TabContent>
</PageSection>
</>
);
};