diff --git a/public/locales/en.json b/public/locales/en.json index 506c1a81..d6e6c34c 100644 --- a/public/locales/en.json +++ b/public/locales/en.json @@ -173,6 +173,7 @@ "label_satellite": "Satellite", "label_rhacs": "RHACS", "label_rescan": "Rescan", + "label_download": "Download", "label_scan": "Scan", "label_source": "Source", "label_source_other": "Sources", diff --git a/src/components/actionMenu/actionMenu.tsx b/src/components/actionMenu/actionMenu.tsx index ba28f49a..448b9c96 100644 --- a/src/components/actionMenu/actionMenu.tsx +++ b/src/components/actionMenu/actionMenu.tsx @@ -11,7 +11,7 @@ import { EllipsisVIcon } from '@patternfly/react-icons'; interface ActionMenuProps { item: T; - actions: { label: string; onClick: (item: T) => void }[]; + actions: { label: string; onClick: (item: T) => void; disabled?: boolean }[]; } const ActionMenu = ({ item, actions }: ActionMenuProps) => { @@ -43,6 +43,7 @@ const ActionMenu = ({ item, actions }: ActionMenuProps) => { onClick={() => { a.onClick(item); }} + isDisabled={a.disabled} > {a.label} diff --git a/src/helpers/helpers.ts b/src/helpers/helpers.ts index 5f753de1..b72e4ca9 100644 --- a/src/helpers/helpers.ts +++ b/src/helpers/helpers.ts @@ -233,10 +233,7 @@ const getTitleImg = (isBrand = UI_BRAND) => ((isBrand && titleImgBrand) || title * @returns {boolean} */ const canDownloadReport = (job?: scanJob | MostRecentScan) => { - if (job && job.status === 'completed' && job.report_id) { - return true; - } - return false; + return job?.status === 'completed' && job?.report_id !== undefined; }; const helpers = { diff --git a/src/types/types.ts b/src/types/types.ts index 867503f8..e0c52a57 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -181,9 +181,9 @@ export type StatusDetails = { job_status_message: string; }; -// TODO: the object returned from the API representing scanJob and MostRecentScan are the same; -// consider this in a future refactor. Also, MostRecentScan is a ScanJob, not a scan. Yeah, quipucords -// is confusing... +// TODO: Considerations for a future refactor: merge and/or rename scanJob and MostRecentScan. +// Reason: the object returned from the api representing scanJob and MostRecentScan are the same; +// also, in quipucords jargon, MostRecentScan is a ScanJob, not a Scan. export type MostRecentScan = { id: number; report_id: number; diff --git a/src/views/scans/__tests__/showScansModal.test.tsx b/src/views/scans/__tests__/showScansModal.test.tsx index 10beaaf4..7bae02bf 100644 --- a/src/views/scans/__tests__/showScansModal.test.tsx +++ b/src/views/scans/__tests__/showScansModal.test.tsx @@ -16,7 +16,7 @@ describe('ShowScansModal', () => { scanJobs={[ { id: 12345, - status: 'DOLOR SIT', + status: 'completed', start_time: new Date('2024-09-06'), end_time: new Date('2024-09-06'), report_id: 67890 diff --git a/src/views/scans/showScansModal.tsx b/src/views/scans/showScansModal.tsx index 2f9624a7..2f78437a 100644 --- a/src/views/scans/showScansModal.tsx +++ b/src/views/scans/showScansModal.tsx @@ -131,7 +131,7 @@ const ShowScansModal: React.FC = ({ {helpers.formatDate(job.end_time || job.start_time)} {job.status} - {job.report_id && job.end_time && ( + {helpers.canDownloadReport(job) && ( diff --git a/src/views/scans/viewScansList.tsx b/src/views/scans/viewScansList.tsx index 6b9097f0..8d5ba89c 100644 --- a/src/views/scans/viewScansList.tsx +++ b/src/views/scans/viewScansList.tsx @@ -250,6 +250,15 @@ const ScansListView: React.FunctionComponent = () => { setScanSelected(undefined); }); } + }, + { + label: t('table.label', { context: 'download' }), + disabled: !helpers.canDownloadReport(scan?.most_recent), + onClick: () => { + if (scan?.most_recent) { + downloadReport(scan.most_recent.report_id); + } + } } ]} />