Skip to content

Commit ed6418b

Browse files
authored
Fix incorrect behaviour when filtering by assignee in issues with multiple assignees (#415)
Hide assignees not selected in filter For issues with multiple assignees, having one of the assignees selected in the filter displays all other assignees as groups. This is misleading behaviour since the assignees that are not selected are expected to be hidden. Let's add a check for if the group is selected in the filter before displaying the data.
1 parent a9fd66c commit ed6418b

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

src/app/core/models/github-user.model.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,27 @@ export class GithubUser implements RawGithubUser, Group {
5252
Object.assign(this, rawData);
5353
}
5454

55+
/*
56+
This method is used to enable comparisons between
57+
a Group and the filtering criteria, which is stored
58+
as a string, in IssuesDataTable.ts
59+
*/
60+
static fromUsername(username: string) {
61+
return new GithubUser({
62+
login: username,
63+
avatar_url: '',
64+
created_at: '',
65+
html_url: '',
66+
name: '',
67+
node_id: '',
68+
two_factor_authentication: false,
69+
site_admin: false,
70+
type: '',
71+
updated_at: '',
72+
url: ''
73+
});
74+
}
75+
5576
equals(other: any) {
5677
if (!(other instanceof GithubUser)) {
5778
return false;

src/app/core/models/milestone.model.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ export class Milestone implements Group {
1818
this.number = milestone.number ? +milestone.number : undefined;
1919
}
2020

21+
/*
22+
This method is used to enable comparisons between
23+
a Group and the filtering criteria, which is stored
24+
as a string, in IssuesDataTable.ts
25+
*/
26+
static fromTitle(title: string): Milestone {
27+
return new Milestone({ title, state: '' });
28+
}
29+
2130
public equals(other: any) {
2231
if (!(other instanceof Milestone)) {
2332
return false;

src/app/shared/issue-tables/IssuesDataTable.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import { DataSource } from '@angular/cdk/table';
22
import { MatPaginator } from '@angular/material/paginator';
33
import { BehaviorSubject, merge, Observable, Subscription } from 'rxjs';
44
import { map } from 'rxjs/operators';
5+
import { GithubUser } from '../../core/models/github-user.model';
56
import { Group } from '../../core/models/github/group.interface';
67
import { Issue } from '../../core/models/issue.model';
8+
import { Milestone } from '../../core/models/milestone.model';
79
import { AssigneeService } from '../../core/services/assignee.service';
810
import { Filter, FiltersService } from '../../core/services/filters.service';
911
import { GroupingContextService } from '../../core/services/grouping/grouping-context.service';
@@ -23,6 +25,21 @@ export class IssuesDataTable extends DataSource<Issue> implements FilterableSour
2325

2426
public isLoading$ = this.issueService.isLoading.asObservable();
2527

28+
private static isGroupInFilter(group: Group, filter: Filter): boolean {
29+
const groupFilterAsGithubUser = filter.assignees.map((selectedAssignee) => {
30+
return GithubUser.fromUsername(selectedAssignee);
31+
});
32+
const groupFilterAsMilestone = filter.milestones.map((selectedMilestone) => {
33+
return Milestone.fromTitle(selectedMilestone);
34+
});
35+
36+
const isGroupInFilter =
37+
groupFilterAsGithubUser.some((githubUser) => group?.equals(githubUser)) ||
38+
groupFilterAsMilestone.some((milestone) => group?.equals(milestone));
39+
40+
return isGroupInFilter;
41+
}
42+
2643
constructor(
2744
private issueService: IssueService,
2845
private groupingContextService: GroupingContextService,
@@ -63,6 +80,11 @@ export class IssuesDataTable extends DataSource<Issue> implements FilterableSour
6380
.pipe(
6481
// maps each change in display value to new issue ordering or filtering
6582
map(() => {
83+
if (!IssuesDataTable.isGroupInFilter(this.group, this.filter)) {
84+
this.count = 0;
85+
return [];
86+
}
87+
6688
let data = <Issue[]>Object.values(this.issueService.issues$.getValue()).reverse();
6789
if (this.defaultFilter) {
6890
data = data.filter(this.defaultFilter);

0 commit comments

Comments
 (0)