Skip to content

Commit ceb16a9

Browse files
authored
feat(quay): fix sorting in quay table and tag details (#1044)
* feat(quay): fix sorting in quay table and tag details * chore(quay): update type assertions * chore: update types to take advantage of generics
1 parent c4f2969 commit ceb16a9

File tree

5 files changed

+43
-24
lines changed

5 files changed

+43
-24
lines changed

plugins/quay/src/components/QuayRepository/QuayRepository.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function QuayRepository(_props: QuayRepositoryProps) {
3838
<div data-testid="quay-repo-table" style={{ border: '1px solid #ddd' }}>
3939
<Table
4040
title={title}
41-
options={{ paging: true, padding: 'dense' }}
41+
options={{ sorting: true, paging: true, padding: 'dense' }}
4242
data={data}
4343
columns={columns}
4444
emptyContent={

plugins/quay/src/components/QuayRepository/tableHeading.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import { Tooltip } from '@material-ui/core';
66
import makeStyles from '@material-ui/core/styles/makeStyles';
77

88
import { vulnerabilitySummary } from '../../lib/utils';
9-
import type { Layer } from '../../types';
9+
import type { QuayTagData } from '../../types';
1010

11-
export const columns: TableColumn[] = [
11+
export const columns: TableColumn<QuayTagData>[] = [
1212
{
1313
title: 'Tag',
1414
field: 'name',
@@ -23,7 +23,7 @@ export const columns: TableColumn[] = [
2323
{
2424
title: 'Security Scan',
2525
field: 'securityScan',
26-
render: (rowData: any): React.ReactNode => {
26+
render: (rowData: QuayTagData): React.ReactNode => {
2727
if (!rowData.securityStatus && !rowData.securityDetails) {
2828
return (
2929
<span data-testid="quay-repo-security-scan-progress">
@@ -43,15 +43,17 @@ export const columns: TableColumn[] = [
4343
}
4444

4545
const tagManifest = rowData.manifest_digest_raw;
46-
const retStr = vulnerabilitySummary(rowData.securityDetails as Layer);
46+
const retStr = vulnerabilitySummary(rowData.securityDetails);
4747
return <Link to={`tag/${tagManifest}`}>{retStr}</Link>;
4848
},
4949
id: 'securityScan',
50+
sorting: false,
5051
},
5152
{
5253
title: 'Size',
5354
field: 'size',
5455
type: 'numeric',
56+
customSort: (a: QuayTagData, b: QuayTagData) => a.rawSize - b.rawSize,
5557
},
5658
{
5759
title: 'Expires',
@@ -63,6 +65,8 @@ export const columns: TableColumn[] = [
6365
title: 'Manifest',
6466
field: 'manifest_digest',
6567
type: 'string',
68+
customSort: (a: QuayTagData, b: QuayTagData) =>
69+
a.manifest_digest_raw.localeCompare(b.manifest_digest_raw),
6670
},
6771
];
6872

plugins/quay/src/components/QuayTagDetails/component.tsx

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,44 @@ type QuayTagDetailsProps = {
2525
// from: https://github.com/quay/quay/blob/f1d85588157eababc3cbf789002c5db521dbd616/web/src/routes/TagDetails/SecurityReport/SecurityReportTable.tsx#L43
2626
const getVulnerabilityLink = (link: string) => link.split(' ')[0];
2727

28-
const columns: TableColumn[] = [
28+
const columns: TableColumn<VulnerabilityListItem>[] = [
2929
{
3030
title: 'Advisory',
3131
field: 'name',
32-
render: (rowData: any): React.ReactNode => {
33-
const row = rowData as Vulnerability;
32+
render: (rowData: VulnerabilityListItem): React.ReactNode => {
3433
return (
3534
<div style={{ display: 'flex', alignItems: 'center' }}>
36-
{row.Name}
37-
{row.Link.trim().length > 0 ? (
38-
<Link to={getVulnerabilityLink(row.Link)}>
35+
{rowData.Name}
36+
{rowData.Link.trim().length > 0 ? (
37+
<Link to={getVulnerabilityLink(rowData.Link)}>
3938
<LinkIcon style={{ marginLeft: '0.5rem' }} />
4039
</Link>
4140
) : null}
4241
</div>
4342
);
4443
},
44+
customSort: (a: VulnerabilityListItem, b: VulnerabilityListItem) =>
45+
a.Name.localeCompare(b.Name, 'en'),
4546
},
4647
{
4748
title: 'Severity',
4849
field: 'Severity',
49-
render: (rowData: any): React.ReactNode => {
50-
const row = rowData as Vulnerability;
50+
customSort: (a: VulnerabilityListItem, b: VulnerabilityListItem) => {
51+
const severityA = VulnerabilityOrder[a.Severity];
52+
const severityB = VulnerabilityOrder[b.Severity];
53+
54+
return severityA - severityB;
55+
},
56+
render: (rowData: VulnerabilityListItem): React.ReactNode => {
5157
return (
5258
<div style={{ display: 'flex', alignItems: 'center' }}>
5359
<WarningIcon
54-
htmlColor={SEVERITY_COLORS[row.Severity]}
60+
htmlColor={SEVERITY_COLORS[rowData.Severity]}
5561
style={{
5662
marginRight: '0.5rem',
5763
}}
5864
/>
59-
<span>{row.Severity}</span>
65+
<span>{rowData.Severity}</span>
6066
</div>
6167
);
6268
},
@@ -74,14 +80,11 @@ const columns: TableColumn[] = [
7480
{
7581
title: 'Fixed By',
7682
field: 'FixedBy',
77-
render: (rowData: any): React.ReactNode => {
78-
const row = rowData as VulnerabilityListItem;
83+
render: (rowData: VulnerabilityListItem): React.ReactNode => {
7984
return (
8085
<>
81-
{row.FixedBy.length > 0 ? (
82-
<>
83-
<span>{row.FixedBy}</span>
84-
</>
86+
{rowData.FixedBy.length > 0 ? (
87+
<span>{rowData.FixedBy}</span>
8588
) : (
8689
'(None)'
8790
)}

plugins/quay/src/hooks/quay.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Box, Chip, makeStyles } from '@material-ui/core';
1010
import { formatByteSize, formatDate } from '@janus-idp/shared-react';
1111

1212
import { quayApiRef } from '../api';
13-
import { Layer, Tag } from '../types';
13+
import { Layer, QuayTagData, Tag } from '../types';
1414

1515
const useLocalStyles = makeStyles({
1616
chip: {
@@ -68,7 +68,7 @@ export const useTags = (organization: string, repository: string) => {
6868
return tagsResponse;
6969
});
7070

71-
const data = useMemo(() => {
71+
const data: QuayTagData[] = useMemo(() => {
7272
return Object.values(tags)?.map(tag => {
7373
const hashFunc = tag.manifest_digest.substring(0, 6);
7474
const shortHash = tag.manifest_digest.substring(7, 19);
@@ -77,6 +77,7 @@ export const useTags = (organization: string, repository: string) => {
7777
name: tag.name,
7878
last_modified: formatDate(tag.last_modified),
7979
size: formatByteSize(tag.size),
80+
rawSize: tag.size,
8081
manifest_digest: (
8182
<Box sx={{ display: 'flex', alignItems: 'center' }}>
8283
<Chip label={hashFunc} className={localClasses.chip} />

plugins/quay/src/types.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,18 @@ export interface Tag {
2020
export interface LabelsResponse {
2121
labels: Label[];
2222
}
23-
23+
export interface QuayTagData {
24+
id: string;
25+
name: string;
26+
last_modified: string;
27+
size: string;
28+
rawSize: number;
29+
manifest_digest: React.JSX.Element;
30+
expiration?: string;
31+
securityDetails: Layer;
32+
securityStatus: string;
33+
manifest_digest_raw: string;
34+
}
2435
export interface Label {
2536
id: string;
2637
key: string;

0 commit comments

Comments
 (0)