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.
  • Loading branch information
bruno-fs committed Nov 6, 2024
1 parent 7bdf3a3 commit 9868c8d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
2 changes: 2 additions & 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 Expand Up @@ -276,6 +277,7 @@
"description_scan-jobs_fetched_error": "Error displaying connection information. {{message}",
"description_report_downloaded": "Report {{name}} downloaded successfully.",
"description_report_downloaded_error": "Failed to download report {{name}}: {{message}}",
"description_report_downloaded_error_no_report": "The report doesn't exist.",
"description_scan-report_start": "$t(toast-notifications.description_scan-report_play)",
"title_add-source_hidden_error": "Error creating source {{ name }}. {{ message }}",
"title_add-source_hidden_error_edit": "Error updating source {{ name }}. {{ message }}"
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
13 changes: 12 additions & 1 deletion src/hooks/useScanApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,19 @@ const useDownloadReportApi = (onAddAlert: (alert: AlertProps) => void) => {
[onAddAlert, t]
);

const callbackErrorNoReport = useCallback(() => {
onAddAlert({
title: t('toast-notifications.description_report_downloaded_error_no_report'),
variant: 'danger'
});
return;
}, [onAddAlert, t]);

const downloadReport = useCallback(
async (reportId: number) => {
async (reportId: number | undefined) => {
if (!reportId) {
return callbackErrorNoReport();
}
let response;
try {
response = await apiCall(reportId);
Expand Down
7 changes: 7 additions & 0 deletions src/views/scans/viewScansList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ const ScansListView: React.FunctionComponent = () => {
setScanSelected(undefined);
});
}
},
{
label: t('table.label', { context: 'download' }),
disabled: scan.most_recent?.status === 'completed' ? false : true,
onClick: () => {
downloadReport(scan.most_recent?.report_id);
}
}
]}
/>
Expand Down

0 comments on commit 9868c8d

Please sign in to comment.