Skip to content

Commit

Permalink
👻 Update check for running analysis / cancel analysis (#1885)
Browse files Browse the repository at this point in the history
This PR narrows down the check for analysis tasks that are cancellable.
Also the logic is updated and flipped for "disabling" the creation of a
new analysis task. Analysis tasks should be creatable when there are no
states for tasks outside of "succeeded" or "failed". This will future
proof against any other additional task states that may be added in the
future. The "scheduled" state was just added for 0.4 & is the motivation
behind this PR ( as requested by @jortel )

Signed-off-by: Ian Bolton <[email protected]>
  • Loading branch information
ibolton336 authored Jun 20, 2024
1 parent 2bd0d6f commit 349911b
Showing 1 changed file with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,7 @@ export const ApplicationsTable: React.FC = () => {

const isTaskCancellable = (application: Application) => {
const task = getTask(application);
if (task?.state && task.state.match(/(Created|Running|Ready|Pending)/))
return true;
return false;
return task?.state && !["Succeeded", "Failed"].includes(task.state);
};

const cancelAnalysis = (row: Application) => {
Expand Down Expand Up @@ -610,18 +608,23 @@ export const ApplicationsTable: React.FC = () => {

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

const isAnalyzingAllowed = () => {
const candidateTasks = selectedRows.filter(
(app) =>
!tasks.some(
(task) =>
task.application?.id === app.id &&
task.state?.match(/(Created|Running|Ready|Pending)/)
)
);

if (candidateTasks.length === selectedRows.length) return true;
return false;
const isAnalyzingDisabled = () => {
if (tasks.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;
});

return candidateTasks.length > 0;
};

const hasExistingAnalysis = selectedRows.some((app) =>
Expand Down Expand Up @@ -783,7 +786,7 @@ export const ApplicationsTable: React.FC = () => {
setAnalyzeModalOpen(true);
}}
isDisabled={
selectedRows.length < 1 || !isAnalyzingAllowed()
selectedRows.length < 1 || isAnalyzingDisabled()
}
>
{t("actions.analyze")}
Expand Down

0 comments on commit 349911b

Please sign in to comment.