Skip to content

Commit 71ff2a8

Browse files
authored
fix(quay): add visual indicator to security scan when it is still loading (#848)
1 parent 9077ce9 commit 71ff2a8

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ import { render } from '@testing-library/react';
66
import { useTags } from '../../hooks';
77
import { QuayRepository } from './QuayRepository';
88

9+
jest.mock('react-use', () => ({
10+
...jest.requireActual('react-use'),
11+
useAsync: jest.fn().mockReturnValue({ loading: true }),
12+
}));
13+
914
jest.mock('@backstage/core-plugin-api', () => ({
1015
...jest.requireActual('@backstage/core-plugin-api'),
1116
useApi: jest
@@ -68,4 +73,27 @@ describe('QuayRepository', () => {
6873
expect(queryByText(/Quay repository/i)).toBeInTheDocument();
6974
expect(queryByText(/No data was added yet/i)).not.toBeInTheDocument();
7075
});
76+
77+
it('should show table if loaded and data is present but shows progress if security scan is not loaded', () => {
78+
(useTags as jest.Mock).mockReturnValue({
79+
loading: false,
80+
data: [
81+
{
82+
name: 'latest',
83+
manifest_digest: undefined,
84+
size: null,
85+
last_modified: 'Wed, 15 Mar 2023 18:22:18 -0000',
86+
},
87+
],
88+
});
89+
const { queryByTestId, queryByText } = render(
90+
<BrowserRouter>
91+
<QuayRepository />
92+
</BrowserRouter>,
93+
);
94+
expect(queryByTestId('quay-repo-table')).not.toBeNull();
95+
expect(queryByTestId('quay-repo-table-empty')).toBeNull();
96+
expect(queryByText(/Quay repository/i)).toBeInTheDocument();
97+
expect(queryByTestId('quay-repo-security-scan-progress')).not.toBeNull();
98+
});
7199
});

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
import React from 'react';
22

3-
import { Link, TableColumn } from '@backstage/core-components';
3+
import { Link, Progress, TableColumn } from '@backstage/core-components';
44

55
import makeStyles from '@material-ui/core/styles/makeStyles';
66

77
import type { Layer } from '../../types';
88

9-
const vulnerabilitySummary = (layer?: Layer): string => {
10-
if (!layer) {
11-
return 'No security scan';
12-
}
9+
const vulnerabilitySummary = (layer: Layer): string => {
1310
const summary: Record<string, number> = {};
1411

15-
layer.Features.forEach(feature => {
12+
layer?.Features.forEach(feature => {
1613
feature.Vulnerabilities?.forEach(vulnerability => {
1714
const { Severity } = vulnerability;
1815
if (!summary[Severity]) {
@@ -44,7 +41,14 @@ export const columns: TableColumn[] = [
4441
title: 'Security Scan',
4542
field: 'securityScan',
4643
render: (rowData: any): React.ReactNode => {
47-
const tagManifest = rowData.manifest_digest_raw as string;
44+
if (!rowData.securityDetails) {
45+
return (
46+
<span data-testid="quay-repo-security-scan-progress">
47+
<Progress />
48+
</span>
49+
);
50+
}
51+
const tagManifest = rowData.manifest_digest_raw;
4852
const retStr = vulnerabilitySummary(rowData.securityDetails as Layer);
4953
return <Link to={`tag/${tagManifest}`}>{retStr}</Link>;
5054
},

plugins/quay/src/hooks/quay.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export const useTags = (organization: string, repository: string) => {
6464
const hashFunc = tag.manifest_digest.substring(0, 6);
6565
const shortHash = tag.manifest_digest.substring(7, 19);
6666
return {
67+
id: `${tag.manifest_digest}-${tag.name}`,
6768
name: tag.name,
6869
last_modified: formatDate(tag.last_modified),
6970
size: formatByteSize(tag.size),

0 commit comments

Comments
 (0)