From 172710afa3800c5332b0ee157156df92b214a6ef Mon Sep 17 00:00:00 2001 From: Scott Dickerson Date: Fri, 21 Jun 2024 15:38:51 -0400 Subject: [PATCH] :bug: Update the enabled check for the Analysis button (#1977) On the application table, update the analysis button's enable/disable check such that analysis is only allowed to be started when all of the tasks for the selected applications are in a terminal state (they are not in-flight/queued). Fixes: #1976 --------- Signed-off-by: Scott J Dickerson --- .../applications-table/applications-table.tsx | 41 +++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) 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")}