-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add images table for Workload CVE Image single page
- Loading branch information
Showing
5 changed files
with
269 additions
and
61 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
100 changes: 100 additions & 0 deletions
100
...platform/src/Containers/Vulnerabilities/WorkloadCves/SingleEntityVulnerabilitiesTable.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,100 @@ | ||
import React from 'react'; | ||
import { Button, ButtonVariant } from '@patternfly/react-core'; | ||
import { TableComposable, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table'; | ||
import { CheckCircleIcon, ExclamationCircleIcon } from '@patternfly/react-icons'; | ||
import { SVGIconProps } from '@patternfly/react-icons/dist/js/createIcon'; | ||
|
||
import LinkShim from 'Components/PatternFly/LinkShim'; | ||
import SeverityIcons from 'Components/PatternFly/SeverityIcons'; | ||
import { vulnerabilitySeverityLabels } from 'messages/common'; | ||
import { getDistanceStrictAsPhrase } from 'utils/dateUtils'; | ||
import { ImageVulnerabilitiesResponse } from './hooks/useImageVulnerabilities'; | ||
import { getEntityPagePath } from './searchUtils'; | ||
|
||
export type SingleEntityVulnerabilitiesTableProps = { | ||
// TODO - Note that we may need to adjust this prop type, or do some pre-processing of data | ||
// when this component is used for the Deployment single page | ||
vulnerabilities: ImageVulnerabilitiesResponse['image']['imageVulnerabilities']; | ||
}; | ||
|
||
function SingleEntityVulnerabilitiesTable({ | ||
vulnerabilities, | ||
}: SingleEntityVulnerabilitiesTableProps) { | ||
return ( | ||
<TableComposable> | ||
<Thead> | ||
<Tr> | ||
<Th>CVE</Th> | ||
<Th>Severity</Th> | ||
<Th>CVE Status</Th> | ||
<Th>Affected components</Th> | ||
<Th>First discovered</Th> | ||
</Tr> | ||
</Thead> | ||
<Tbody> | ||
{vulnerabilities.map( | ||
({ cve, severity, isFixable, imageComponents, discoveredAtImage }) => { | ||
const SeverityIcon: React.FC<SVGIconProps> | undefined = | ||
SeverityIcons[severity]; | ||
const severityLabel: string | undefined = | ||
vulnerabilitySeverityLabels[severity]; | ||
|
||
return ( | ||
<Tr key={cve}> | ||
<Td dataLabel="CVE"> | ||
<Button | ||
variant={ButtonVariant.link} | ||
isInline | ||
component={LinkShim} | ||
href={getEntityPagePath('CVE', cve)} | ||
> | ||
{cve} | ||
</Button> | ||
</Td> | ||
<Td dataLabel="Severity"> | ||
<span> | ||
{SeverityIcon && ( | ||
<SeverityIcon className="pf-u-display-inline" /> | ||
)} | ||
{severityLabel && ( | ||
<span className="pf-u-pl-sm">{severityLabel}</span> | ||
)} | ||
</span> | ||
</Td> | ||
<Td dataLabel="CVE Status"> | ||
{isFixable ? ( | ||
<span> | ||
<CheckCircleIcon | ||
className="pf-u-display-inline" | ||
color="var(--pf-global--success-color--100)" | ||
/> | ||
<span className="pf-u-pl-sm">Fixable</span> | ||
</span> | ||
) : ( | ||
<span> | ||
<ExclamationCircleIcon | ||
className="pf-u-display-inline" | ||
color="var(--pf-global--danger-color--100)" | ||
/> | ||
<span className="pf-u-pl-sm">Not fixable</span> | ||
</span> | ||
)} | ||
</Td> | ||
<Td dataLabel="Affected components"> | ||
{imageComponents.length === 1 | ||
? imageComponents[0].name | ||
: `${imageComponents.length} components`} | ||
</Td> | ||
<Td dataLabel="First discovered"> | ||
{getDistanceStrictAsPhrase(discoveredAtImage, new Date())} | ||
</Td> | ||
</Tr> | ||
); | ||
} | ||
)} | ||
</Tbody> | ||
</TableComposable> | ||
); | ||
} | ||
|
||
export default SingleEntityVulnerabilitiesTable; |
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
78 changes: 78 additions & 0 deletions
78
...pps/platform/src/Containers/Vulnerabilities/WorkloadCves/hooks/useImageVulnerabilities.ts
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,78 @@ | ||
import { gql, useQuery } from '@apollo/client'; | ||
import { SearchFilter } from 'types/search'; | ||
import { getRequestQueryStringForSearchFilter } from 'utils/searchUtils'; | ||
|
||
export type ImageVulnerabilitiesVariables = { | ||
id: string; | ||
vulnQuery: string; | ||
}; | ||
|
||
export type ImageVulnerabilitiesResponse = { | ||
image: { | ||
id: string; | ||
metadata: { | ||
v1: { | ||
layers: { | ||
instruction: string; | ||
value: string; | ||
}; | ||
} | null; | ||
} | null; | ||
imageVulnerabilities: { | ||
severity: string; | ||
isFixable: boolean; | ||
cve: string; | ||
summary: string; | ||
discoveredAtImage: Date | null; | ||
imageComponents: { | ||
name: string; | ||
version: string; | ||
fixedIn: string; | ||
location: string; | ||
layerIndex: string | null; | ||
}[]; | ||
}[]; | ||
}; | ||
}; | ||
|
||
export const imageVulnerabilitiesQuery = gql` | ||
query getImageVulnerabilities($id: ID!, $vulnQuery: String!) { | ||
image(id: $id) { | ||
id | ||
metadata { | ||
v1 { | ||
layers { | ||
instruction | ||
value | ||
} | ||
} | ||
} | ||
imageVulnerabilities(query: $vulnQuery) { | ||
severity | ||
isFixable | ||
cve | ||
summary | ||
discoveredAtImage | ||
imageComponents { | ||
name | ||
version | ||
fixedIn | ||
location | ||
layerIndex | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
|
||
export default function useImageVulnerabilities(imageId: string, searchFilter: SearchFilter) { | ||
return useQuery<ImageVulnerabilitiesResponse, ImageVulnerabilitiesVariables>( | ||
imageVulnerabilitiesQuery, | ||
{ | ||
variables: { | ||
id: imageId, | ||
vulnQuery: getRequestQueryStringForSearchFilter(searchFilter), | ||
}, | ||
} | ||
); | ||
} |
Oops, something went wrong.