Skip to content

Commit

Permalink
Select all milestones if previously all selected
Browse files Browse the repository at this point in the history
  • Loading branch information
Arif-Khalid committed Mar 20, 2024
1 parent 45c0ebc commit aa1c98a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/app/core/services/filters.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ export class FiltersService {
public filter$ = new BehaviorSubject<Filter>(DEFAULT_FILTER);

private _validateFilter = pipe(this.updateStatusPairing, this.updateTypePairing);
private previousMilestonesLength = 0;

clearFilters(): void {
this.filter$.next(DEFAULT_FILTER);
this.previousMilestonesLength = 0;
}

updateFilters(newFilters: Partial<Filter>): void {
Expand Down Expand Up @@ -69,6 +71,13 @@ export class FiltersService {
sanitizeMilestones(allMilestones: Milestone[]) {
const allMilestonesSet = new Set(allMilestones.map((milestone) => milestone.title));

// All previous milestones were selected, reset to all new milestones selected
if (this.filter$.value.milestones.length === this.previousMilestonesLength) {
this.updateFilters({ milestones: [...allMilestonesSet] });
this.previousMilestonesLength = allMilestones.length;
return;
}

const newMilestones: string[] = [];
for (const milestone of this.filter$.value.milestones) {
if (allMilestonesSet.has(milestone)) {
Expand All @@ -82,6 +91,7 @@ export class FiltersService {
}

this.updateFilters({ milestones: newMilestones });
this.previousMilestonesLength = allMilestones.length;
}

/**
Expand Down

0 comments on commit aa1c98a

Please sign in to comment.