-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Packages within Vulnerabilities detail page (#83)
- Loading branch information
1 parent
7ff01aa
commit b6f7181
Showing
5 changed files
with
268 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
220 changes: 220 additions & 0 deletions
220
client/src/app/pages/vulnerability-details/packages-by-vulnerability.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,220 @@ | ||
import React from "react"; | ||
import { NavLink } from "react-router-dom"; | ||
|
||
import { DescriptionList, DescriptionListDescription, DescriptionListGroup, DescriptionListTerm, Label, Toolbar, ToolbarContent, ToolbarItem } from "@patternfly/react-core"; | ||
import { ExpandableRowContent, Table, Tbody, Td, Th, Thead, Tr } from "@patternfly/react-table"; | ||
|
||
import { AdvisoryWithinVulnerability, DecomposedPurl } from "@app/api/models"; | ||
import { FilterToolbar, FilterType } from "@app/components/FilterToolbar"; | ||
import { SeverityShieldAndText } from "@app/components/SeverityShieldAndText"; | ||
import { SimplePagination } from "@app/components/SimplePagination"; | ||
import { | ||
ConditionalTableBody, | ||
TableHeaderContentWithControls, | ||
TableRowContentWithControls, | ||
} from "@app/components/TableControls"; | ||
import { useLocalTableControls } from "@app/hooks/table-controls"; | ||
import { decomposePurl, formatDate } from "@app/utils/utils"; | ||
import { PackageQualifiers } from "@app/components/PackageQualifiers"; | ||
|
||
interface TableData { | ||
purl: string; | ||
versionRange: string; | ||
decomposedPurl?: DecomposedPurl | ||
} | ||
|
||
interface PackagesByVulnerabilityProps { | ||
advisories: AdvisoryWithinVulnerability[]; | ||
} | ||
|
||
export const PackagesByVulnerability: React.FC<PackagesByVulnerabilityProps> = ({ | ||
advisories, | ||
}) => { | ||
const tableData = React.useMemo(() => { | ||
return advisories.flatMap(advisory => advisory.statuses?.affected ?? []) | ||
.map(item => { | ||
const result: TableData = { | ||
versionRange: item.version, | ||
purl: item.package.purl, | ||
decomposedPurl: decomposePurl(item.package.purl) | ||
}; | ||
return result; | ||
}) | ||
}, [advisories]); | ||
|
||
const tableControls = useLocalTableControls({ | ||
tableName: "package-table", | ||
idProperty: "purl", | ||
items: tableData, | ||
isLoading: false, | ||
columnNames: { | ||
name: "Name", | ||
namespace: "Namespace", | ||
version: "Version", | ||
type: "Type", | ||
qualifiers: "Qualifiers", | ||
affectedVersions: "Affected version", | ||
}, | ||
hasActionsColumn: true, | ||
isSortEnabled: false, | ||
isPaginationEnabled: true, | ||
initialItemsPerPage: 10, | ||
isFilterEnabled: true, | ||
filterCategories: [ | ||
{ | ||
categoryKey: "", | ||
title: "Filter text", | ||
placeholderText: "Search", | ||
type: FilterType.search, | ||
}, | ||
], | ||
isExpansionEnabled: true, | ||
expandableVariant: "single", | ||
}); | ||
|
||
const { | ||
currentPageItems, | ||
numRenderedColumns, | ||
propHelpers: { | ||
toolbarProps, | ||
filterToolbarProps, | ||
paginationToolbarItemProps, | ||
paginationProps, | ||
tableProps, | ||
getThProps, | ||
getTrProps, | ||
getTdProps, | ||
}, | ||
expansionDerivedState: { isCellExpanded }, | ||
} = tableControls; | ||
|
||
return ( | ||
<> | ||
{tableControls.isFilterEnabled && ( | ||
<Toolbar {...toolbarProps}> | ||
<ToolbarContent> | ||
<FilterToolbar showFiltersSideBySide {...filterToolbarProps} /> | ||
<ToolbarItem {...paginationToolbarItemProps}> | ||
<SimplePagination | ||
idPrefix="package-table" | ||
isTop | ||
paginationProps={paginationProps} | ||
/> | ||
</ToolbarItem> | ||
</ToolbarContent> | ||
</Toolbar> | ||
)} | ||
<Table {...tableProps} aria-label="Package table"> | ||
<Thead> | ||
<Tr> | ||
<TableHeaderContentWithControls {...tableControls}> | ||
<Th {...getThProps({ columnKey: "name" })} /> | ||
<Th {...getThProps({ columnKey: "namespace" })} /> | ||
<Th {...getThProps({ columnKey: "version" })} /> | ||
<Th {...getThProps({ columnKey: "type" })} /> | ||
<Th {...getThProps({ columnKey: "qualifiers" })} /> | ||
<Th {...getThProps({ columnKey: "affectedVersions" })} /> | ||
</TableHeaderContentWithControls> | ||
</Tr> | ||
</Thead> | ||
<ConditionalTableBody | ||
isLoading={false} | ||
isError={undefined} | ||
isNoData={tableData.length === 0} | ||
numRenderedColumns={numRenderedColumns} | ||
> | ||
{currentPageItems?.map((item, rowIndex) => { | ||
return ( | ||
<Tbody key={item.purl}> | ||
<Tr {...getTrProps({ item })}> | ||
<TableRowContentWithControls | ||
{...tableControls} | ||
item={item} | ||
rowIndex={rowIndex} | ||
> | ||
<Td width={20} {...getTdProps({ columnKey: "name" })}> | ||
<NavLink | ||
to={`/packages/${encodeURIComponent(item.purl)}`} | ||
> | ||
{item.decomposedPurl ? item.decomposedPurl?.name : item.purl} | ||
</NavLink> | ||
</Td> | ||
<Td | ||
width={10} | ||
modifier="truncate" | ||
{...getTdProps({ columnKey: "namespace" })} | ||
> | ||
{item.decomposedPurl?.namespace} | ||
</Td> | ||
<Td | ||
width={15} | ||
modifier="truncate" | ||
{...getTdProps({ columnKey: "version" })} | ||
> | ||
{item.decomposedPurl?.version} | ||
</Td> | ||
<Td | ||
width={10} | ||
modifier="truncate" | ||
{...getTdProps({ columnKey: "type" })} | ||
> | ||
{item.decomposedPurl?.type} | ||
</Td> | ||
<Td | ||
width={30} | ||
{...getTdProps({ columnKey: "qualifiers" })} | ||
> | ||
{item.decomposedPurl?.qualifiers && <PackageQualifiers value={item.decomposedPurl?.qualifiers} />} | ||
</Td> | ||
<Td | ||
width={10} | ||
{...getTdProps({ columnKey: "affectedVersions" })} | ||
> | ||
<Label color="grey">{item.versionRange}</Label> | ||
</Td> | ||
</TableRowContentWithControls> | ||
</Tr> | ||
{isCellExpanded(item) ? ( | ||
<Tr isExpanded> | ||
<Td colSpan={7}> | ||
<ExpandableRowContent> | ||
<div className="pf-v5-u-m-md"> | ||
<DescriptionList> | ||
<DescriptionListGroup> | ||
<DescriptionListTerm> | ||
Purl | ||
</DescriptionListTerm> | ||
<DescriptionListDescription> | ||
{item.purl} | ||
</DescriptionListDescription> | ||
</DescriptionListGroup> | ||
<DescriptionListGroup> | ||
<DescriptionListTerm> | ||
Path | ||
</DescriptionListTerm> | ||
<DescriptionListDescription> | ||
{item.decomposedPurl?.path} | ||
</DescriptionListDescription> | ||
</DescriptionListGroup> | ||
</DescriptionList> | ||
</div> | ||
</ExpandableRowContent> | ||
</Td> | ||
</Tr> | ||
) : null} | ||
</Tbody> | ||
|
||
); | ||
})} | ||
|
||
</ConditionalTableBody> | ||
</Table > | ||
<SimplePagination | ||
idPrefix="package-table" | ||
isTop={false} | ||
isCompact | ||
paginationProps={paginationProps} | ||
/> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters