Skip to content

Commit

Permalink
Consider open milestone without deadline as currently active (CATcher…
Browse files Browse the repository at this point in the history
…-org#359)

For open milestones, only those with deadlines were considered as currently
active. This led to setting a closed milestone with the latest deadline as
currently active when there is an open milestone without deadline.

Let's update the selection logic to also include open milestones
without deadlines.
  • Loading branch information
NereusWB922 authored Apr 10, 2024
1 parent 709afa7 commit a5e695a
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions src/app/core/services/milestone.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,37 @@ export class MilestoneService {
}

/**
* Gets the open milestone with the earliest deadline.
* Returns null if there is no open milestone with deadline.
* Returns the open milestone with earliest deadline.
* If no deadline exists, returns milestone with alphabetically smallest title.
* Returns null if there are no open milestones.
*/
getEarliestOpenMilestone(): Milestone {
let earliestOpenMilestone: Milestone = null;
for (const milestone of this.milestones) {
if (!milestone.deadline || milestone.state !== 'open') {
continue;
const openMilestones: Milestone[] = this.milestones.filter((milestone: Milestone) => milestone.state === 'open');

if (openMilestones.length === 0) {
return null;
}

const target = openMilestones.reduce((prev, curr) => {
if (prev === null) {
return curr;
}
if (earliestOpenMilestone === null) {
earliestOpenMilestone = milestone;
} else if (milestone.deadline < earliestOpenMilestone.deadline) {
earliestOpenMilestone = milestone;

if (prev.deadline !== curr.deadline) {
if (!prev.deadline) {
return curr;
}
if (!curr.deadline) {
return prev;
}
return prev.deadline < curr.deadline ? prev : curr;
}
}
return earliestOpenMilestone;

// Both without due date or with the same due date
return prev.title.localeCompare(curr.title) < 0 ? prev : curr;
}, null);

return target;
}

/**
Expand Down

0 comments on commit a5e695a

Please sign in to comment.