-
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 expandable section for image vulnerability components
- Loading branch information
Showing
5 changed files
with
144 additions
and
16 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
61 changes: 61 additions & 0 deletions
61
ui/apps/platform/src/Containers/Vulnerabilities/WorkloadCves/Tables/ImageComponentsTable.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,61 @@ | ||
import React from 'react'; | ||
import { CodeBlock, CodeBlockCode } from '@patternfly/react-core'; | ||
import { TableComposable, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table'; | ||
|
||
import { ImageVulnerabilitiesResponse } from '../hooks/useImageVulnerabilities'; | ||
import { ImageDetailsResponse } from '../hooks/useImageDetails'; | ||
|
||
export type ImageComponentsTableProps = { | ||
image: ImageDetailsResponse['image'] | undefined; | ||
imageComponents: ImageVulnerabilitiesResponse['image']['imageVulnerabilities'][number]['imageComponents']; | ||
}; | ||
|
||
function ImageComponentsTable({ image, imageComponents }: ImageComponentsTableProps) { | ||
const layers = image?.metadata?.v1?.layers ?? []; | ||
return ( | ||
<TableComposable borders={false}> | ||
<Thead> | ||
<Tr> | ||
<Th>Component</Th> | ||
<Th>Version</Th> | ||
<Th>Fixed In</Th> | ||
<Th>Location</Th> | ||
</Tr> | ||
</Thead> | ||
{imageComponents.map(({ id, name, version, fixedIn, location, layerIndex }) => { | ||
let dockerfileText = `< Dockerfile layer information is not available >`; | ||
|
||
if (layerIndex !== null) { | ||
const layer = layers[layerIndex]; | ||
if (layer) { | ||
dockerfileText = `${layer.instruction} ${layer.value}`; | ||
} | ||
} | ||
return ( | ||
<Tbody | ||
key={id} | ||
style={{ | ||
borderBottom: '1px solid var(--pf-c-table--BorderColor)', | ||
}} | ||
> | ||
<Tr> | ||
<Td>{name}</Td> | ||
<Td>{version}</Td> | ||
<Td>{fixedIn || 'TODO - why empty'}</Td> | ||
<Td>{location || 'TODO - why empty'}</Td> | ||
</Tr> | ||
<Tr> | ||
<Td colSpan={4} className="pf-u-pt-0"> | ||
<CodeBlock> | ||
<CodeBlockCode>{dockerfileText}</CodeBlockCode> | ||
</CodeBlock> | ||
</Td> | ||
</Tr> | ||
</Tbody> | ||
); | ||
})} | ||
</TableComposable> | ||
); | ||
} | ||
|
||
export default ImageComponentsTable; |
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
21 changes: 21 additions & 0 deletions
21
ui/apps/platform/src/hooks/patternfly/useTableExpandedRows.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,21 @@ | ||
import { useState } from 'react'; | ||
|
||
export default function useTableExpandedRows() { | ||
const [expandedSet, setExpandedSet] = useState<Set<string>>(new Set()); | ||
|
||
function isRowExpanded(key: string): boolean { | ||
return expandedSet.has(key); | ||
} | ||
|
||
function setRowExpanded(key: string, isExpanded: boolean) { | ||
const nextSet = new Set(expandedSet); | ||
if (isExpanded) { | ||
nextSet.add(key); | ||
} else { | ||
nextSet.delete(key); | ||
} | ||
setExpandedSet(nextSet); | ||
} | ||
|
||
return { isRowExpanded, setRowExpanded }; | ||
} |