豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit ccf9d47

Browse files
josephperrottdevversion
authored andcommitted
feat(apps): Update label model to include font color (#520)
Update the label model to include the font color that is of good contrast for the labels background color. PR Close #520
1 parent b6a8e9e commit ccf9d47

File tree

6 files changed

+66
-25
lines changed

6 files changed

+66
-25
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import {PullRequest as SharedPullRequest} from '../../../shared/models/app-models';
2+
3+
export class PullRequest extends SharedPullRequest {}

apps/shared/models/base.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@ export abstract class BaseModel<T> {
1414
this.setData(data);
1515
}
1616

17-
protected setData(data: T) {
18-
this.data = data;
19-
}
17+
protected setData(data: T) {}
2018

21-
static getByReference<T>(ref: FirestoreReference<T>): TypeFromFirestoreRef<typeof ref> {
19+
static getByReference<T>(ref: FirestoreReference<T>): Promise<TypeFromFirestoreRef<typeof ref>> {
2220
return this.prototype.getByReference(ref);
2321
}
2422

apps/shared/models/label.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
import {Label as GithubLabel} from '@octokit/webhooks-types';
22
import {GithubBaseModel, GithubHelperFunctions, toFirestoreReference} from './base';
3+
import contrast from 'font-color-contrast';
34

45
export interface FirestoreLabel {
56
name: string;
67
color: string;
78
}
89

910
export class Label extends GithubBaseModel<FirestoreLabel> {
10-
readonly name = this.data.name;
11-
readonly color = this.data.color;
11+
name!: string;
12+
color!: string;
13+
fontColor!: string;
14+
15+
override setData(data: FirestoreLabel) {
16+
this.name = data.name;
17+
this.color = data.color;
18+
this.fontColor = contrast(data.color, 0.6);
19+
}
1220

1321
static override githubHelpers: GithubHelperFunctions<Label, GithubLabel, FirestoreLabel> = {
1422
buildRefString(model: GithubLabel) {

apps/shared/models/pull-request.ts

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,48 @@ export interface FirestorePullRequest {
3333
}
3434

3535
export class PullRequest extends GithubBaseModel<FirestorePullRequest> {
36-
readonly owner = this.data.owner;
37-
readonly repo = this.data.repo;
38-
readonly node = this.data.node;
39-
readonly state = this.data.state;
40-
readonly authorAssociation = this.data.authorAssociation;
41-
readonly changeFiles = this.data.changedFiles;
42-
readonly closedAt = this.data.closedAt;
43-
readonly commits = this.data.commits;
44-
readonly createdAt = this.data.createdAt;
45-
readonly draft = this.data.draft;
46-
readonly labels = this.data.labels;
47-
readonly maintainerCanModify = this.data.maintainerCanModify;
48-
readonly number = this.data.number;
49-
readonly requestedReviewers = this.data.requestedReviewers;
50-
readonly title = this.data.title;
51-
readonly milestone = this.data.milestone;
52-
readonly assignees = this.data.assignees;
53-
readonly user = this.data.user;
54-
readonly commit = this.data.commit;
36+
owner!: string;
37+
repo!: string;
38+
node!: string;
39+
state!: string;
40+
authorAssociation!: string;
41+
changeFiles!: number;
42+
closedAt!: string | null;
43+
commits!: number;
44+
createdAt!: string;
45+
draft!: boolean;
46+
labels!: Label[];
47+
maintainerCanModify!: boolean;
48+
number!: number;
49+
requestedReviewers!: User[];
50+
title!: string;
51+
milestone!: Milestone | null;
52+
assignees!: User[];
53+
user!: User;
54+
commit!: string;
55+
target: undefined | string;
56+
57+
override async setData(data: FirestorePullRequest) {
58+
this.owner = data.owner;
59+
this.repo = data.repo;
60+
this.node = data.node;
61+
this.state = data.state;
62+
this.authorAssociation = data.authorAssociation;
63+
this.changeFiles = data.changedFiles;
64+
this.closedAt = data.closedAt;
65+
this.commits = data.commits;
66+
this.createdAt = data.createdAt;
67+
this.draft = data.draft;
68+
this.maintainerCanModify = data.maintainerCanModify;
69+
this.number = data.number;
70+
this.requestedReviewers = data.requestedReviewers as any;
71+
this.title = data.title;
72+
this.milestone = data.milestone as any;
73+
this.assignees = data.assignees as any;
74+
this.commit = data.commit;
75+
User.getByReference(data.user).then((u) => (this.user = u));
76+
Promise.all(data.labels.map((l) => Label.getByReference(l))).then((l) => (this.labels = l));
77+
}
5578

5679
static override githubHelpers: GithubHelperFunctions<
5780
PullRequest,

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
"firebase-admin": "^10.0.2",
112112
"firebase-functions": "^3.19.0",
113113
"firebase-tools": "^10.5.0",
114+
"font-color-contrast": "^11.1.0",
114115
"git-raw-commits": "^2.0.10",
115116
"glob": "7.2.0",
116117
"husky": "^7.0.1",

yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ __metadata:
465465
firebase-admin: ^10.0.2
466466
firebase-functions: ^3.19.0
467467
firebase-tools: ^10.5.0
468+
font-color-contrast: ^11.1.0
468469
git-raw-commits: ^2.0.10
469470
glob: 7.2.0
470471
husky: ^7.0.1
@@ -8235,6 +8236,13 @@ __metadata:
82358236
languageName: node
82368237
linkType: hard
82378238

8239+
"font-color-contrast@npm:^11.1.0":
8240+
version: 11.1.0
8241+
resolution: "font-color-contrast@npm:11.1.0"
8242+
checksum: 7c8af0690adc8ddfd8f3030bbce6d3345851fe78c0076fb5b3ab23568b241559fd2925f8923dc5e907faa4d49d79a03e5c04321b1551d04dbdd662a29857a968
8243+
languageName: node
8244+
linkType: hard
8245+
82388246
"foreground-child@npm:^2.0.0":
82398247
version: 2.0.0
82408248
resolution: "foreground-child@npm:2.0.0"

0 commit comments

Comments
 (0)