Skip to content

Commit

Permalink
Add ability to cancel all running apps from selected items
Browse files Browse the repository at this point in the history
Signed-off-by: MiriSafra <[email protected]>
  • Loading branch information
MiriSafra committed Sep 18, 2024
1 parent f389539 commit 3302462
Showing 1 changed file with 29 additions and 4 deletions.
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<
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 &&
selectedRows.some((application: DecoratedApplication) =>
isTaskCancellable(application)
)
? [
<DropdownItem
key="applications-bulk-cancel"
isDisabled={selectedRows.length < 1}
onClick={() => {
handleCancelBulkAnalysis();
}}
>
{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

0 comments on commit 3302462

Please sign in to comment.