forked from guacsec/trustify-ui
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpackage-details.tsx
More file actions
132 lines (122 loc) · 3.9 KB
/
package-details.tsx
File metadata and controls
132 lines (122 loc) · 3.9 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
import React from "react";
import {
Content,
Flex,
FlexItem,
PageSection,
Popover,
Stack,
StackItem,
Tab,
TabAction,
TabContent,
TabTitleText,
Tabs,
} from "@patternfly/react-core";
import HelpIcon from "@patternfly/react-icons/dist/esm/icons/help-icon";
import { PathParam, useRouteParams } from "@app/Routes";
import { LoadingWrapper } from "@app/components/LoadingWrapper";
import { PackageQualifiers } from "@app/components/PackageQualifiers";
import { useFetchPackageById } from "@app/queries/packages";
import { decomposePurl } from "@app/utils/utils";
import { SbomsByPackage } from "./sboms-by-package";
import { VulnerabilitiesByPackage } from "./vulnerabilities-by-package";
export const PackageDetails: React.FC = () => {
const packageId = useRouteParams(PathParam.PACKAGE_ID);
const { pkg, isFetching, fetchError } = useFetchPackageById(packageId);
const decomposedPurl = React.useMemo(() => {
return pkg ? decomposePurl(pkg.purl) : undefined;
}, [pkg]);
// Tabs
const [activeTabKey, setActiveTabKey] = React.useState<string | number>(0);
const handleTabClick = (
_event: React.MouseEvent | React.KeyboardEvent | MouseEvent,
tabIndex: string | number,
) => {
setActiveTabKey(tabIndex);
};
const vulnerabilitiesTabRef = React.createRef<HTMLElement>();
const sbomsTabRef = React.createRef<HTMLElement>();
const sbomsPopupRef = React.createRef<HTMLElement>();
return (
<>
<PageSection hasBodyWrapper={false}>
<Stack>
<StackItem>
<Content>
<Content component="h1">
{decomposedPurl?.name ?? packageId ?? ""}
</Content>
</Content>
</StackItem>
<StackItem>
<Flex>
<FlexItem spacer={{ default: "spacerSm" }}>
<p>version: {decomposedPurl?.version}</p>{" "}
</FlexItem>
<FlexItem>
{decomposedPurl?.qualifiers && (
<PackageQualifiers value={decomposedPurl?.qualifiers} />
)}
</FlexItem>
</Flex>
</StackItem>
</Stack>
</PageSection>
<PageSection hasBodyWrapper={false}>
<Tabs
mountOnEnter
activeKey={activeTabKey}
onSelect={handleTabClick}
aria-label="Tabs that contain the SBOM information"
role="region"
>
<Tab
eventKey={0}
title={<TabTitleText>Vulnerabilities</TabTitleText>}
tabContentId="refTabVulnerabilitiesSection"
tabContentRef={vulnerabilitiesTabRef}
/>
<Tab
eventKey={1}
title={<TabTitleText>SBOMs using package</TabTitleText>}
actions={
<>
<TabAction ref={sbomsPopupRef}>
<HelpIcon />
</TabAction>
<Popover
bodyContent={<div>A list of SBOMs using this package.</div>}
triggerRef={sbomsPopupRef}
/>
</>
}
tabContentId="refTabSbomsSection"
tabContentRef={sbomsTabRef}
/>
</Tabs>
</PageSection>
<PageSection hasBodyWrapper={false}>
<TabContent
eventKey={0}
id="refTabVulnerabilitiesSection"
ref={vulnerabilitiesTabRef}
aria-label="Vulnerabilities of the Package"
>
{packageId && <VulnerabilitiesByPackage packageId={packageId} />}
</TabContent>
<TabContent
eventKey={1}
id="refTabSbomsSection"
ref={sbomsTabRef}
aria-label="SBOMs using the Package"
hidden
>
<LoadingWrapper isFetching={isFetching} fetchError={fetchError}>
{pkg?.purl && <SbomsByPackage purl={pkg.purl} />}
</LoadingWrapper>
</TabContent>
</PageSection>
</>
);
};