Skip to content

Commit 4650252

Browse files
authored
Merge branch 'main' into refreshTasks
2 parents bbfa0c3 + 172710a commit 4650252

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

client/src/app/pages/applications/applications-table/applications-table.tsx

+25-16
Original file line numberDiff line numberDiff line change
@@ -608,23 +608,34 @@ export const ApplicationsTable: React.FC = () => {
608608

609609
const dropdownItems = [...importDropdownItems, ...applicationDropdownItems];
610610

611-
const isAnalyzingDisabled = () => {
612-
if (tasks.length === 0) {
611+
/**
612+
* Analysis on the selected applications should be allowed if:
613+
* - At least 1 application is selected
614+
* - No analysis is in-flight for the selected applications (only 1 analysis at a time)
615+
*/
616+
const isAnalyzingAllowed = () => {
617+
if (selectedRows.length === 0) {
613618
return false;
614619
}
615620

616-
const allowedStates = ["Succeeded", "Failed", null, ""];
617-
618-
const candidateTasks = selectedRows.filter((app) => {
619-
const hasAllowedState = tasks.some(
620-
(task) =>
621-
task.application?.id === app.id &&
622-
allowedStates.includes(task.state || "")
623-
);
624-
return !hasAllowedState;
625-
});
621+
if (tasks.length === 0) {
622+
return true;
623+
}
626624

627-
return candidateTasks.length > 0;
625+
const selectedAppIds = selectedRows.map(({ id }) => id);
626+
const tasksForSelected = tasks.filter(
627+
(task) =>
628+
(task.kind ?? task.addon) === "analyzer" &&
629+
selectedAppIds.includes(task.application.id)
630+
);
631+
const terminalStates = ["Succeeded", "Failed", "Canceled", ""];
632+
633+
return (
634+
tasksForSelected.length === 0 ||
635+
tasksForSelected.every(({ state }) =>
636+
terminalStates.includes(state ?? "")
637+
)
638+
);
628639
};
629640

630641
const hasExistingAnalysis = selectedRows.some((app) =>
@@ -785,9 +796,7 @@ export const ApplicationsTable: React.FC = () => {
785796
onClick={() => {
786797
setAnalyzeModalOpen(true);
787798
}}
788-
isDisabled={
789-
selectedRows.length < 1 || isAnalyzingDisabled()
790-
}
799+
isDisabled={!isAnalyzingAllowed()}
791800
>
792801
{t("actions.analyze")}
793802
</Button>

0 commit comments

Comments
 (0)