Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Update the enabled check for the Analysis button #1977

Merged
merged 3 commits into from
Jun 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading