Skip to content

Commit

Permalink
🐛 Update the enabled check for the Analysis button (#1977)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
sjd78 authored Jun 21, 2024
1 parent 4a4102f commit 172710a
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 172710a

Please sign in to comment.