-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[angular-ngrx-scss] issues tab (#1941)
* wip: issues tab * chore: cleanup and comments * feat: use search api, connect filters * fix: use interface in test * fix: make pagination fetch correct page --------- Co-authored-by: Jan Kaiser <[email protected]>
- Loading branch information
Showing
26 changed files
with
637 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 19 additions & 6 deletions
25
angular-ngrx-scss/src/app/issues/components/issues-header/issues-header.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,42 @@ | ||
<div class="filters-container"> | ||
<div class="issue-status"> | ||
<a href="" class="active"> | ||
<span class="icon" appOcticon="no-entry" size="16"></span> | ||
<span>412 Open</span> | ||
</a> | ||
<a href=""> | ||
<button [ngClass]="{ active: viewState === 'open' }" (click)="selectOpen()"> | ||
<span class="icon" appOcticon="check" size="16"></span | ||
><span>4877 Open</span></a | ||
><span>{{ openIssues?.total ?? 0 }} Open</span> | ||
</button> | ||
<button | ||
[ngClass]="{ active: viewState === 'closed' }" | ||
(click)="selectClosed()" | ||
> | ||
<span class="icon" appOcticon="no-entry" size="16"></span> | ||
<span>{{ closedIssues?.total ?? 0 }} Closed</span> | ||
</button> | ||
</div> | ||
<div class="issue-filters"> | ||
<app-filter-dropdown | ||
name="Label" | ||
description="Select label" | ||
[isRepo]="true" | ||
[items]="(labels$ | async) || []" | ||
[toggle]="true" | ||
(setFilter)="setLabel($event)" | ||
[current]="filterParams.labels" | ||
></app-filter-dropdown> | ||
<app-filter-dropdown | ||
name="Milestones" | ||
description="Select milestone" | ||
[isRepo]="true" | ||
[items]="(milestones$ | async) || []" | ||
(setFilter)="setMilestone($event)" | ||
[current]="filterParams.milestone" | ||
></app-filter-dropdown> | ||
<app-filter-dropdown | ||
name="Sort" | ||
description="Select sort" | ||
[isRepo]="true" | ||
[items]="sortOptions" | ||
(setFilter)="setSort($event)" | ||
[current]="filterParams.sort" | ||
></app-filter-dropdown> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 95 additions & 2 deletions
97
angular-ngrx-scss/src/app/issues/components/issues-header/issues-header.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,101 @@ | ||
import { Component } from '@angular/core'; | ||
import { Component, EventEmitter, Input, Output } from '@angular/core'; | ||
import { Store } from '@ngrx/store'; | ||
import { Observable, map } from 'rxjs'; | ||
import { Sort } from 'src/app/repository/services/repository.interfaces'; | ||
import { FilterOption } from 'src/app/shared/components/filter-dropdown/filter-dropdown.component'; | ||
import { SORTING_OPTIONS } from 'src/app/shared/constants'; | ||
import { | ||
ISSUE_STATE, | ||
RepoIssues, | ||
fetchIssues, | ||
selectLabels, | ||
selectMilestones, | ||
} from 'src/app/state/repository'; | ||
|
||
@Component({ | ||
selector: 'app-issues-header', | ||
templateUrl: './issues-header.component.html', | ||
styleUrls: ['./issues-header.component.scss'], | ||
}) | ||
export class IssuesHeaderComponent {} | ||
export class IssuesHeaderComponent { | ||
@Input() owner!: string; | ||
|
||
@Input() repoName!: string; | ||
|
||
filterParams: { labels?: string; milestone?: string; sort: Sort } = { | ||
sort: 'created', | ||
}; | ||
|
||
sortOptions: FilterOption[] = SORTING_OPTIONS; | ||
|
||
milestones$: Observable<FilterOption[]> = this.store | ||
.select(selectMilestones) | ||
.pipe( | ||
map((milestones) => | ||
milestones.map((milestone) => ({ | ||
label: milestone.title, | ||
value: milestone.title, | ||
})), | ||
), | ||
); | ||
|
||
labels$: Observable<FilterOption[]> = this.store | ||
.select(selectLabels) | ||
.pipe( | ||
map((labels) => | ||
labels.map((label) => ({ label: label.name, value: label.name })), | ||
), | ||
); | ||
|
||
@Input() viewState: ISSUE_STATE = 'open'; | ||
|
||
@Input() | ||
openIssues: RepoIssues | null = null; | ||
|
||
@Input() | ||
closedIssues: RepoIssues | null = null; | ||
|
||
@Output() viewStateChange = new EventEmitter<ISSUE_STATE>(); | ||
|
||
constructor(private store: Store) {} | ||
|
||
selectOpen() { | ||
this.viewStateChange.emit('open'); | ||
} | ||
|
||
selectClosed() { | ||
this.viewStateChange.emit('closed'); | ||
} | ||
|
||
setLabel(label: string) { | ||
this.filterParams.labels = label; | ||
this.refetchIssues(); | ||
} | ||
|
||
setMilestone(milestone: string) { | ||
this.filterParams.milestone = milestone; | ||
this.refetchIssues(); | ||
} | ||
|
||
setSort(sort: string) { | ||
this.filterParams.sort = sort as Sort; | ||
this.refetchIssues(); | ||
} | ||
|
||
private refetchIssues() { | ||
this.store.dispatch( | ||
fetchIssues({ | ||
owner: this.owner, | ||
repoName: this.repoName, | ||
params: { state: 'open', ...this.filterParams }, | ||
}), | ||
); | ||
this.store.dispatch( | ||
fetchIssues({ | ||
owner: this.owner, | ||
repoName: this.repoName, | ||
params: { state: 'closed', ...this.filterParams }, | ||
}), | ||
); | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
angular-ngrx-scss/src/app/issues/components/issues-list/issues-list.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
angular-ngrx-scss/src/app/issues/components/issues-list/issues-list.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { Component, Input } from '@angular/core'; | ||
import { Issue } from 'src/app/repository/services/repository.interfaces'; | ||
import { RepoIssues } from 'src/app/state/repository'; | ||
|
||
@Component({ | ||
selector: 'app-issues-list', | ||
templateUrl: './issues-list.component.html', | ||
}) | ||
export class IssuesListComponent { | ||
@Input() issues: Issue[] = []; | ||
@Input() issues: RepoIssues | null = null; | ||
} |
24 changes: 21 additions & 3 deletions
24
angular-ngrx-scss/src/app/issues/components/issues.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,23 @@ | ||
<div class="container issues-container"> | ||
<app-issues-header></app-issues-header> | ||
<app-issues-list></app-issues-list> | ||
<app-issues-header | ||
[viewState]="viewState" | ||
[openIssues]="openIssues$ | async" | ||
[closedIssues]="closedIssues$ | async" | ||
[owner]="owner" | ||
[repoName]="repoName" | ||
(viewStateChange)="viewStateChange($event)" | ||
></app-issues-header> | ||
<app-issues-list | ||
[issues]=" | ||
viewState === 'open' ? (openIssues$ | async) : (closedIssues$ | async) | ||
" | ||
></app-issues-list> | ||
</div> | ||
<app-pagination></app-pagination> | ||
<app-pagination | ||
[params]=" | ||
viewState === 'open' | ||
? (openIssuesPaginationParams$ | async) | ||
: (closedIssuesPaginationParams$ | async) | ||
" | ||
(pageChange)="pageChange($event)" | ||
></app-pagination> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ | |
.issues-container { | ||
border-radius: variables.$padding; | ||
border: 1px solid variables.$gray200; | ||
margin: 1rem auto; | ||
} |
64 changes: 62 additions & 2 deletions
64
angular-ngrx-scss/src/app/issues/components/issues.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,68 @@ | ||
import { Component } from '@angular/core'; | ||
import { Component, OnInit } from '@angular/core'; | ||
import { ActivatedRoute } from '@angular/router'; | ||
import { Store } from '@ngrx/store'; | ||
import { | ||
ISSUE_STATE, | ||
fetchIssues, | ||
selectClosedIssuePaginationParams, | ||
selectClosedIssues, | ||
selectOpenIssuePaginationParams, | ||
selectOpenIssues, | ||
} from 'src/app/state/repository'; | ||
|
||
@Component({ | ||
selector: 'app-issues', | ||
templateUrl: './issues.component.html', | ||
styleUrls: ['./issues.component.scss'], | ||
}) | ||
export class IssuesComponent {} | ||
export class IssuesComponent implements OnInit { | ||
owner!: string; | ||
repoName!: string; | ||
openIssues$ = this.store.select(selectOpenIssues); | ||
closedIssues$ = this.store.select(selectClosedIssues); | ||
viewState: ISSUE_STATE = 'open'; | ||
|
||
openIssuesPaginationParams$ = this.store.select( | ||
selectOpenIssuePaginationParams, | ||
); | ||
closedIssuesPaginationParams$ = this.store.select( | ||
selectClosedIssuePaginationParams, | ||
); | ||
|
||
constructor(private route: ActivatedRoute, private store: Store) {} | ||
|
||
ngOnInit(): void { | ||
this.owner = this.route.snapshot.paramMap.get('owner') as string; | ||
this.repoName = this.route.snapshot.paramMap.get('repo') as string; | ||
|
||
this.store.dispatch( | ||
fetchIssues({ | ||
owner: this.owner, | ||
repoName: this.repoName, | ||
params: { state: 'open' }, | ||
}), | ||
); | ||
|
||
this.store.dispatch( | ||
fetchIssues({ | ||
owner: this.owner, | ||
repoName: this.repoName, | ||
params: { state: 'closed' }, | ||
}), | ||
); | ||
} | ||
|
||
pageChange(page: number) { | ||
this.store.dispatch( | ||
fetchIssues({ | ||
owner: this.owner, | ||
repoName: this.repoName, | ||
params: { state: this.viewState, page }, | ||
}), | ||
); | ||
} | ||
|
||
viewStateChange(viewState: ISSUE_STATE) { | ||
this.viewState = viewState; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
angular-ngrx-scss/src/app/repository/components/repo-header/repo-header.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.