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 1 commit
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,32 @@ 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, ""];
if (tasks.length === 0) {
return true;
}

const candidateTasks = selectedRows.filter((app) => {
const hasAllowedState = tasks.some(
(task) =>
task.application?.id === app.id &&
allowedStates.includes(task.state || "")
);
return !hasAllowedState;
});
const selectedAppIds = selectedRows.map(({ id }) => id);
const tasksForSelected = tasks.filter((task) =>
selectedAppIds.includes(task.application.id)
);
const allowedStates = ["Succeeded", "Failed", null, ""];
sjd78 marked this conversation as resolved.
Show resolved Hide resolved

return candidateTasks.length > 0;
return (
tasksForSelected.length === 0 ||
tasksForSelected.every(({ state }) =>
allowedStates.includes(state as string)
)
);
};

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