Skip to content

Commit

Permalink
feat(apps): create target column
Browse files Browse the repository at this point in the history
Create a column which displays the current target of the pull request
  • Loading branch information
josephperrott committed Apr 20, 2022
1 parent e3386cc commit 6390a7e
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 4 deletions.
3 changes: 2 additions & 1 deletion apps/prs/src/app/pr-table/columns/columns.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import {CommonModule} from '@angular/common';

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

@NgModule({
declarations: [SummaryColumn, StatusColumn],
declarations: [SummaryColumn, TargetColumn, 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>Target</mat-header-cell>
<mat-cell *matCellDef="let row">
{{getTargetText(row.target)}}
</mat-cell>
11 changes: 11 additions & 0 deletions apps/prs/src/app/pr-table/columns/target/target.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.mat-column-target {
max-width: 80px;

&.mat-header-cell {
justify-content: center;
}

&.mat-cell {
justify-content: center;
}
}
44 changes: 44 additions & 0 deletions apps/prs/src/app/pr-table/columns/target/target.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import {ChangeDetectionStrategy, Component} from '@angular/core';
import {BaseColumn} from '../base';

/** The targets available, and the text to show in the UI. */
const Targets = [
{
label: 'target: patch',
text: 'Patch',
},
{
label: 'target: minor',
text: 'Minor',
},
{
label: 'target: major',
text: 'Major',
},
{
label: 'target: lts',
text: 'LTS',
},
{
label: 'target: rc',
text: 'RC',
},
{
label: 'target: feature branch',
text: 'Feature Branch',
},
];

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

getTargetText(target: string) {
return Targets.find((t) => t.label === target)?.text ?? 'No Target';
}
}
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 @@ -11,6 +11,7 @@ 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';
import {TargetColumn} from './columns/target/target.component';

@Component({
selector: 'pr-table',
Expand All @@ -19,7 +20,7 @@ import {StatusColumn} from './columns/status/status.component';
})
export class PrTableComponent implements AfterViewInit {
/** The columns used in the PR table. */
columns: Type<BaseColumn>[] = [SummaryColumn, StatusColumn];
columns: Type<BaseColumn>[] = [SummaryColumn, StatusColumn, TargetColumn];
/** Data source for the table providing the list of pull requests/ */
dataSource: MatTableDataSource<PullRequest> = new MatTableDataSource();
/** The table. */
Expand Down
10 changes: 9 additions & 1 deletion apps/prs/src/models/pull-request.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import {PullRequest as SharedPullRequest} from '../../../shared/models/app-models';
import {FirestorePullRequest} from '../../../shared/models/pull-request';

export class PullRequest extends SharedPullRequest {}
export class PullRequest extends SharedPullRequest {
target: string | undefined;

override async setData(data: FirestorePullRequest) {
await super.setData(data);
this.target = this.labels.find((l) => l?.name?.startsWith('target:'))?.name || '';
}
}
1 change: 0 additions & 1 deletion apps/shared/models/pull-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export class PullRequest extends GithubBaseModel<FirestorePullRequest> {
assignees!: User[];
user!: User;
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)];
Expand Down

0 comments on commit 6390a7e

Please sign in to comment.