Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ActionMenu<Scan>): ds-437 add download report button #513

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"build:pre": "bash ./scripts/pre.sh",
"release": "changelog --link-url https://github.com/quipucords/quipucords-ui.git",
"start": "export PROTOCOL=http; export HOST=127.0.0.1; export PORT=${PORT:-3000}; export MOCK_PORT=${MOCK_PORT:-3030}; run-p -l api:dev start:js start:open",
"start:using-server": "export PROTOCOL=${QUIPUCORDS_SERVER_PROTOCOL:-https}; export HOST=${QUIPUCORDS_SERVER_HOST:-127.0.0.1}; export PORT=${PORT:-3000}; export MOCK_PORT=${QUIPUCORDS_SERVER_PORT:-9443}; run-p -l start:js start:open",
"start:js": "export NODE_ENV=development; weldable -l ts -x ./config/webpack.dev.js",
"start:open": "xdg-open $PROTOCOL://$HOST:$PORT/ || open $PROTOCOL://$HOST:$PORT/",
"start:stage": "export PROTOCOL=http; export HOST=127.0.0.1; export PORT=${PORT:-3000}; export MOCK_PORT=${MOCK_PORT:-8000}; run-p -l api:stage start:js start:open",
Expand Down
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 @@
[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 All @@ -358,7 +369,7 @@
}
return callbackSuccess(response, reportId);
},
[apiCall, callbackSuccess, callbackError]

Check warning on line 372 in src/hooks/useScanApi.ts

View workflow job for this annotation

GitHub Actions / Integration (18.x)

React Hook useCallback has a missing dependency: 'callbackErrorNoReport'. Either include it or remove the dependency array

Check warning on line 372 in src/hooks/useScanApi.ts

View workflow job for this annotation

GitHub Actions / Integration (20.x)

React Hook useCallback has a missing dependency: 'callbackErrorNoReport'. Either include it or remove the dependency array
);

return {
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
4 changes: 2 additions & 2 deletions tests/__snapshots__/code.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ exports[`General code checks should only have specific console.[warn|log|info|er
"hooks/useScanApi.ts:195: console.log(missingScansMsg);",
"hooks/useScanApi.ts:229: console.error(error);",
"hooks/useScanApi.ts:283: console.error(error);",
"hooks/useScanApi.ts:356: console.error(error);",
"hooks/useScanApi.ts:401: console.error(error);",
"hooks/useScanApi.ts:367: console.error(error);",
"hooks/useScanApi.ts:412: console.error(error);",
"hooks/useSourceApi.ts:63: console.log(missingSourcesMsg);",
"hooks/useSourceApi.ts:81: console.log(missingSourcesMsg);",
"hooks/useSourceApi.ts:127: console.error(error);",
Expand Down
Loading