Skip to content

Commit

Permalink
feat(ActionMenu<Scan>): ds-437 add download report button
Browse files Browse the repository at this point in the history
The button shall only be enabled when the scan is completed.

Also touch showScansModal to use the helper 'canDownloadReport'
to decide if the report can be downloaded.

Relates to JIRA: DISCOVERY-437
  • Loading branch information
bruno-fs committed Nov 14, 2024
1 parent 00cdac8 commit 04965c7
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 10 deletions.
1 change: 1 addition & 0 deletions public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/components/actionMenu/actionMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { EllipsisVIcon } from '@patternfly/react-icons';

interface ActionMenuProps<T = unknown> {
item: T;
actions: { label: string; onClick: (item: T) => void }[];
actions: { label: string; onClick: (item: T) => void; disabled?: boolean }[];
}

const ActionMenu = <T,>({ item, actions }: ActionMenuProps<T>) => {
Expand Down Expand Up @@ -43,6 +43,7 @@ const ActionMenu = <T,>({ item, actions }: ActionMenuProps<T>) => {
onClick={() => {
a.onClick(item);
}}
isDisabled={a.disabled}
>
{a.label}
</DropdownItem>
Expand Down
5 changes: 1 addition & 4 deletions src/helpers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
6 changes: 3 additions & 3 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/views/scans/__tests__/showScansModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/views/scans/showScansModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const ShowScansModal: React.FC<ShowScansModalProps> = ({
<Td dataLabel="Scan Time">{helpers.formatDate(job.end_time || job.start_time)}</Td>
<Td dataLabel="Scan Result">{job.status}</Td>
<Td dataLabel="Download" isActionCell>
{job.report_id && job.end_time && (
{helpers.canDownloadReport(job) && (
<Button onClick={() => onDownload(job.report_id)} icon={<DownloadIcon />} variant="link">
Download
</Button>
Expand Down
9 changes: 9 additions & 0 deletions src/views/scans/viewScansList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
]}
/>
Expand Down

0 comments on commit 04965c7

Please sign in to comment.