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

✨ Add cancel option for multiple analyses #2099

Merged
sjd78 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ export const ApplicationsTable: React.FC = () => {

const history = useHistory();
const token = keycloak.tokenParsed;

// ----- State for the modals
const [saveApplicationModalState, setSaveApplicationModalState] = useState<
"create" | DecoratedApplication | null
Expand Down Expand Up @@ -156,7 +155,9 @@ export const ApplicationsTable: React.FC = () => {
const [applicationsToDelete, setApplicationsToDelete] = useState<
DecoratedApplication[]
>([]);

const [applicationsToCancel, setApplicationsToCancel] = useState<
sjd78 marked this conversation as resolved.
Show resolved Hide resolved
DecoratedApplication[]
>([]);
const [assessmentToDiscard, setAssessmentToDiscard] =
useState<DecoratedApplication | null>(null);

Expand Down Expand Up @@ -272,7 +273,6 @@ export const ApplicationsTable: React.FC = () => {
});
}
);

const discardReview = async (application: DecoratedApplication) => {
if (application.review) {
deleteReview({
Expand All @@ -297,7 +297,6 @@ export const ApplicationsTable: React.FC = () => {
});
}
);

const discardAssessment = async (application: DecoratedApplication) => {
if (application.assessments) {
application.assessments.forEach((assessment) => {
Expand Down Expand Up @@ -575,6 +574,23 @@ export const ApplicationsTable: React.FC = () => {
>
{t("actions.delete")}
</DropdownItem>,
...(tasksReadAccess && tasksWriteAccess
? [
<DropdownItem
key="applications-bulk-cancel"
isDisabled={
!selectedRows.some((application: DecoratedApplication) =>
rszwajko marked this conversation as resolved.
Show resolved Hide resolved
isTaskCancellable(application)
)
}
onClick={() => {
handleCancelBulkAnalysis();
rszwajko marked this conversation as resolved.
Show resolved Hide resolved
}}
>
{t("actions.cancelAnalysis")}
</DropdownItem>,
]
: []),
...(credentialsReadAccess
? [
<DropdownItem
Expand Down Expand Up @@ -638,6 +654,15 @@ export const ApplicationsTable: React.FC = () => {
})
);
};
const handleCancelBulkAnalysis = () => {
const runningAppsToCancel = selectedRows.filter((application) =>
isTaskCancellable(application)
);
setApplicationsToCancel(runningAppsToCancel);
runningAppsToCancel.forEach((application) => {
cancelAnalysis(application);
});
};

const assessSelectedApp = async (application: DecoratedApplication) => {
setApplicationToAssess(application);
Expand Down
Loading