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

Keep milestones when switching repo #311

Merged
merged 6 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
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
31 changes: 31 additions & 0 deletions src/app/core/services/filters.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
import { Sort } from '@angular/material/sort';
import { BehaviorSubject, pipe } from 'rxjs';
import { SimpleLabel } from '../models/label.model';
import { Milestone } from '../models/milestone.model';

export type Filter = {
title: string;
Expand Down Expand Up @@ -35,8 +36,12 @@ export const DEFAULT_FILTER: Filter = {
export class FiltersService {
public filter$ = new BehaviorSubject<Filter>(DEFAULT_FILTER);

// Helps in determining whether all milestones were selected from previous repo during sanitization of milestones
private previousMilestonesLength = 0;

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

updateFilters(newFilters: Partial<Filter>): void {
Expand Down Expand Up @@ -68,4 +73,30 @@ export class FiltersService {

this.updateFilters({ labels: newLabels, hiddenLabels: newHiddenLabels, deselectedLabels: newDeselectedLabels });
}

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)) {
newMilestones.push(milestone);
}
}

// No applicable milestones, reset to all milestones selected
if (newMilestones.length === 0) {
newMilestones.push(...allMilestonesSet);
}

this.updateFilters({ milestones: newMilestones });
this.previousMilestonesLength = allMilestones.length;
}
}
2 changes: 1 addition & 1 deletion src/app/shared/filter-bar/filter-bar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class FilterBarComponent implements OnInit, OnDestroy {
this.milestoneSubscription = this.milestoneService.fetchMilestones().subscribe(
(response) => {
this.logger.debug('IssuesViewerComponent: Fetched milestones from Github');
this.filtersService.updateFilters({ milestones: this.milestoneService.milestones.map((milestone) => milestone.title) });
this.filtersService.sanitizeMilestones(this.milestoneService.milestones);
},
(err) => {},
() => {}
Expand Down
Loading