diff --git a/client/src/app/pages/applications/applications-table/applications-table.tsx b/client/src/app/pages/applications/applications-table/applications-table.tsx index 3146dd857..dfa9d137d 100644 --- a/client/src/app/pages/applications/applications-table/applications-table.tsx +++ b/client/src/app/pages/applications/applications-table/applications-table.tsx @@ -608,23 +608,34 @@ export const ApplicationsTable: React.FC = () => { const dropdownItems = [...importDropdownItems, ...applicationDropdownItems]; - const isAnalyzingDisabled = () => { - if (tasks.length === 0) { + /** + * Analysis on the selected applications should be allowed if: + * - At least 1 application is selected + * - No analysis is in-flight for the selected applications (only 1 analysis at a time) + */ + const isAnalyzingAllowed = () => { + if (selectedRows.length === 0) { return false; } - const allowedStates = ["Succeeded", "Failed", null, ""]; - - const candidateTasks = selectedRows.filter((app) => { - const hasAllowedState = tasks.some( - (task) => - task.application?.id === app.id && - allowedStates.includes(task.state || "") - ); - return !hasAllowedState; - }); + if (tasks.length === 0) { + return true; + } - return candidateTasks.length > 0; + const selectedAppIds = selectedRows.map(({ id }) => id); + const tasksForSelected = tasks.filter( + (task) => + (task.kind ?? task.addon) === "analyzer" && + selectedAppIds.includes(task.application.id) + ); + const terminalStates = ["Succeeded", "Failed", "Canceled", ""]; + + return ( + tasksForSelected.length === 0 || + tasksForSelected.every(({ state }) => + terminalStates.includes(state ?? "") + ) + ); }; const hasExistingAnalysis = selectedRows.some((app) => @@ -785,9 +796,7 @@ export const ApplicationsTable: React.FC = () => { onClick={() => { setAnalyzeModalOpen(true); }} - isDisabled={ - selectedRows.length < 1 || isAnalyzingDisabled() - } + isDisabled={!isAnalyzingAllowed()} > {t("actions.analyze")}