Skip to content

Commit

Permalink
Merge branch 'main' into refreshTasks
Browse files Browse the repository at this point in the history
  • Loading branch information
sjd78 authored Jun 24, 2024
2 parents bbfa0c3 + 172710a commit 4650252
Showing 1 changed file with 25 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -785,9 +796,7 @@ export const ApplicationsTable: React.FC = () => {
onClick={() => {
setAnalyzeModalOpen(true);
}}
isDisabled={
selectedRows.length < 1 || isAnalyzingDisabled()
}
isDisabled={!isAnalyzingAllowed()}
>
{t("actions.analyze")}
</Button>
Expand Down

0 comments on commit 4650252

Please sign in to comment.