Skip to content

Commit

Permalink
Split 'Without a milestone' option (CATcher-org#315)
Browse files Browse the repository at this point in the history
Co-authored-by: Misra Aditya <[email protected]>
Co-authored-by: nknguyenhc <[email protected]>
  • Loading branch information
3 people authored Mar 29, 2024
1 parent 83dcdae commit b1f3eed
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 14 deletions.
7 changes: 5 additions & 2 deletions src/app/core/models/issue.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ export class Issue {
this.title = githubIssue.title;
this.hiddenDataInDescription = new HiddenData(githubIssue.body);
this.description = Issue.updateDescription(this.hiddenDataInDescription.originalStringWithoutHiddenData);
// githubIssue without milestone will be set to default milestone
this.milestone = githubIssue.milestone ? new Milestone(githubIssue.milestone) : Milestone.DefaultMilestone;
this.state = githubIssue.state;
this.stateReason = githubIssue.stateReason;
this.issueOrPr = githubIssue.issueOrPr;
Expand All @@ -94,6 +92,11 @@ export class Issue {
this.assignees = githubIssue.assignees.map((assignee) => assignee.login);
this.githubLabels = githubIssue.labels;
this.labels = githubIssue.labels.map((label) => label.name);
this.milestone = githubIssue.milestone
? new Milestone(githubIssue.milestone)
: this.issueOrPr === 'Issue'
? Milestone.IssueWithoutMilestone
: Milestone.PRWithoutMilestone;
}

public static createPhaseBugReportingIssue(githubIssue: GithubIssue): Issue {
Expand Down
3 changes: 2 additions & 1 deletion src/app/core/models/milestone.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { Group } from './github/group.interface';
* Represents a milestone and its attributes fetched from Github.
*/
export class Milestone implements Group {
static DefaultMilestone: Milestone = new Milestone({ title: 'Without a milestone', state: null });
static IssueWithoutMilestone: Milestone = new Milestone({ title: 'Issue without a milestone', state: null });
static PRWithoutMilestone: Milestone = new Milestone({ title: 'PR without a milestone', state: null });
title: string;
state: string;

Expand Down
8 changes: 5 additions & 3 deletions src/app/core/services/filters.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,14 @@ export class FiltersService {
}

sanitizeMilestones(allMilestones: Milestone[]) {
const allMilestonesSet = new Set(allMilestones.map((milestone) => milestone.title));
const milestones = allMilestones.map((milestone) => milestone.title);
milestones.push(Milestone.IssueWithoutMilestone.title, Milestone.PRWithoutMilestone.title);
const allMilestonesSet = new Set(milestones);

// 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;
this.previousMilestonesLength = allMilestonesSet.size;
return;
}

Expand All @@ -97,6 +99,6 @@ export class FiltersService {
}

this.updateFilters({ milestones: newMilestones });
this.previousMilestonesLength = allMilestones.length;
this.previousMilestonesLength = allMilestonesSet.size;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ export class MilestoneGroupingStrategy implements GroupingStrategy {
* hidden group list if empty.
*/
isInHiddenList(group: Milestone): boolean {
return group !== Milestone.DefaultMilestone;
return group !== Milestone.IssueWithoutMilestone && group !== Milestone.PRWithoutMilestone;
}
}
2 changes: 0 additions & 2 deletions src/app/core/services/milestone.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ export class MilestoneService {
}
milestoneData.sort((a: Milestone, b: Milestone) => a.title.localeCompare(b.title));

// add default milestone for untracked issues/PRs at the end
milestoneData.push(Milestone.DefaultMilestone);
return milestoneData;
}
}
2 changes: 2 additions & 0 deletions src/app/shared/filter-bar/filter-bar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@
<mat-option *ngFor="let milestone of this.milestoneService.milestones" [value]="milestone.title">
{{ milestone.title }}
</mat-option>
<mat-option *ngIf="isFilterIssue()" [value]="'Issue without a milestone'">Issues without a milestone</mat-option>
<mat-option *ngIf="isFilterPullRequest()" [value]="'PR without a milestone'">PRs without a milestone</mat-option>
</mat-select>
</mat-form-field>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/model/issue.model.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('Issue model class', () => {
it('should set milestone to default milestone for issue without milestone', () => {
const issue = Issue.createPhaseBugReportingIssue(ISSUE_WITHOUT_MILESTONE);

expect(issue.milestone).toEqual(Milestone.DefaultMilestone);
expect(issue.milestone).toEqual(Milestone.IssueWithoutMilestone);
});

it('should set assignees correctly for issue with assignees', () => {
Expand Down
7 changes: 3 additions & 4 deletions tests/services/milestone.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('MilestoneService', () => {
githubServiceSpy.fetchAllMilestones.and.returnValue(of(mockMilestones));
milestoneService.fetchMilestones().subscribe((response) => {
expect(githubServiceSpy.fetchAllMilestones).toHaveBeenCalled();
expect(milestoneService.milestones.length).toBe(3);
expect(milestoneService.milestones.length).toBe(2);
expect(milestoneService.milestones[0].title).toBe('Milestone 1');
expect(milestoneService.hasNoMilestones).toBeFalse();

Expand All @@ -30,7 +30,7 @@ describe('MilestoneService', () => {
githubServiceSpy.fetchAllMilestones.and.returnValue(of([]));
milestoneService.fetchMilestones().subscribe((response) => {
expect(githubServiceSpy.fetchAllMilestones).toHaveBeenCalled();
expect(milestoneService.milestones.length).toBe(1);
expect(milestoneService.milestones.length).toBe(0);
expect(milestoneService.hasNoMilestones).toBeTrue();

done();
Expand All @@ -47,9 +47,8 @@ describe('MilestoneService', () => {
expect(milestone).toBeInstanceOf(Milestone);
}

expect(parsedMilestones.length).toBe(3);
expect(parsedMilestones.length).toBe(2);
expect(parsedMilestones[0].title).toBe('Milestone 1');
expect(parsedMilestones[parsedMilestones.length - 1]).toBe(Milestone.DefaultMilestone);
});
});
});

0 comments on commit b1f3eed

Please sign in to comment.