Skip to content

Commit

Permalink
feat(apps): create status column
Browse files Browse the repository at this point in the history
Create a column to display the overall pull request status
  • Loading branch information
josephperrott committed Apr 19, 2022
1 parent 2a9fe46 commit a5dd094
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 3 deletions.
6 changes: 4 additions & 2 deletions apps/prs/src/app/pr-table/columns/columns.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import {CommonModule} from '@angular/common';

import {MatTableModule} from '@angular/material/table';
import {SummaryColumn} from './summary/summary.component';
import {StatusColumn} from './status/status.component';
import {MatIconModule} from '@angular/material/icon';

@NgModule({
declarations: [SummaryColumn],
imports: [CommonModule, MatTableModule],
declarations: [SummaryColumn, StatusColumn],
imports: [CommonModule, MatTableModule, MatIconModule],
})
export class ColumnsModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<mat-header-cell *matHeaderCellDef>Status</mat-header-cell>
<mat-cell *matCellDef="let pr">
<mat-icon class="{{pr.status}}">{{getStatusIconForStatus(pr.status)}}</mat-icon>
</mat-cell>
19 changes: 19 additions & 0 deletions apps/prs/src/app/pr-table/columns/status/status.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.mat-column-status {
&.mat-header-cell {
}

&.mat-cell {
.pending {
color: rgba(229, 196, 12, 0.44);
}

.success {
color: rgba(0, 128, 0, 0.44);
}

.error,
.failure {
color: rgba(255, 23, 23, 0.44);
}
}
}
27 changes: 27 additions & 0 deletions apps/prs/src/app/pr-table/columns/status/status.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {ChangeDetectionStrategy, Component} from '@angular/core';
import {StatusEvent} from '@octokit/webhooks-types';
import {BaseColumn} from '../base';

@Component({
selector: 'status-column',
templateUrl: './status.component.html',
styleUrls: ['./status.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class StatusColumn extends BaseColumn {
name = 'status';

getStatusIconForStatus(state: StatusEvent['state']) {
switch (state) {
case 'pending':
return 'pending';
case 'success':
return 'check_circle';
case 'failure':
return 'error';
case 'error':
return 'error';
}
throw Error('An invalid state was provided for retrieving the icon.');
}
}
3 changes: 2 additions & 1 deletion apps/prs/src/app/pr-table/pr-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import {PullRequest} from '../../models/pull-request';
import {BaseColumn} from './columns/base';
import {SummaryColumn} from './columns/summary/summary.component';
import {StatusColumn} from './columns/status/status.component';

@Component({
selector: 'pr-table',
Expand All @@ -18,7 +19,7 @@ import {SummaryColumn} from './columns/summary/summary.component';
})
export class PrTableComponent implements AfterViewInit {
/** The columns used in the PR table. */
columns: Type<BaseColumn>[] = [SummaryColumn];
columns: Type<BaseColumn>[] = [SummaryColumn, StatusColumn];
/** Data source for the table providing the list of pull requests/ */
dataSource: MatTableDataSource<PullRequest> = new MatTableDataSource();
/** The table. */
Expand Down
3 changes: 3 additions & 0 deletions apps/shared/models/pull-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ export class PullRequest extends GithubBaseModel<FirestorePullRequest> {
commit!: string;
target: undefined | string;

// TODO: Determine the status icon via the data from firebase.
status = ['pending', 'success', 'failure', 'error'][Math.floor((Math.random() * 100) % 4)];

override async setData(data: FirestorePullRequest) {
this.owner = data.owner;
this.repo = data.repo;
Expand Down

0 comments on commit a5dd094

Please sign in to comment.