Skip to content

Commit

Permalink
Add sorting by Status (CATcher-org#318)
Browse files Browse the repository at this point in the history
Co-authored-by: Misra Aditya <[email protected]>
Co-authored-by: Nguyen <[email protected]>
  • Loading branch information
3 people authored Mar 29, 2024
1 parent cd4614f commit 0867e1c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/app/shared/filter-bar/filter-bar.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
<mat-option value="date">
<span mat-sort-header="date">Date Updated</span>
</mat-option>
<mat-option value="status">
<span mat-sort-header="status">Status</span>
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field appearance="standard">
Expand Down
23 changes: 23 additions & 0 deletions src/app/shared/issue-tables/issue-sorter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export function applySort(sort: Sort, data: Issue[]): Issue[] {
return data.sort((a, b) => direction * compareByIntegerValue(a.id, b.id));
case 'date':
return data.sort((a, b) => direction * compareByDateValue(a.updated_at, b.updated_at));
case 'status':
return data.sort((a, b) => direction * compareByIssueType(a, b));
default:
// title, responseTag are string values
return data.sort((a, b) => direction * compareByStringValue(a[sort.active], b[sort.active]));
Expand All @@ -33,3 +35,24 @@ function compareByIntegerValue(valueA: number, valueB: number): number {
function compareByDateValue(valueA: string, valueB: string): number {
return moment(valueA).isBefore(valueB) ? -1 : 1;
}

function compareByIssueType(valueA: Issue, valueB: Issue): number {
const sortOrder = {
'OPEN PullRequest': 0,
'OPEN Issue': 1,
'MERGED PullRequest': 2,
'CLOSED Issue': 3,
'CLOSED PullRequest': 4
};

const aOrder = sortOrder[valueA.state + ' ' + valueA.issueOrPr] || -1;
const bOrder = sortOrder[valueB.state + ' ' + valueB.issueOrPr] || -1;

if (aOrder === bOrder) {
return compareByStringValue(valueA.title, valueB.title);
} else if (aOrder > bOrder) {
return 1;
} else {
return -1;
}
}

0 comments on commit 0867e1c

Please sign in to comment.