Skip to content

Commit 8bd898b

Browse files
Merge pull request #424 from iFixit/commented-on
Participants: Add a UI component
2 parents eac6f33 + 27cbb50 commit 8bd898b

12 files changed

Lines changed: 107 additions & 3 deletions

File tree

frontend/dummy-pulls.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@
167167
"base": {
168168
"ref": "master"
169169
},
170+
"participants": ["ianrohde", "Another"],
170171
"user": {
171172
"login": "ianrohde"
172173
},
@@ -457,6 +458,7 @@
457458
"body": "pull request dummy body",
458459
"created_at": "2020-10-28T01:02:33.000Z",
459460
"updated_at": "2020-11-10T22:16:17.000Z",
461+
"participants": ["danielbeardsley", "someone else"],
460462
"closed_at": null,
461463
"merged_at": null,
462464
"difficulty": null,
@@ -4702,6 +4704,7 @@
47024704
"base": {
47034705
"ref": "master"
47044706
},
4707+
"participants": ["BaseInfinity", "other", "another"],
47054708
"user": {
47064709
"login": "BaseInfinity"
47074710
},
@@ -4991,6 +4994,7 @@
49914994
"base": {
49924995
"ref": "master"
49934996
},
4997+
"participants": ["evannoronha", "someone else"],
49944998
"user": {
49954999
"login": "evannoronha"
49965000
},

frontend/src/pull-card/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Pull } from "../pull";
22
import { CommitStatuses } from "./commit-statuses";
3+
import { Participants } from "./participants";
34
import { Age } from "./age";
45
import { Flags } from "./flags";
56
import { Avatar } from "./avatar";
@@ -68,6 +69,7 @@ export const PullCard = memo(function PullCard({
6869

6970
return (
7071
<Card ref={cardRef} display={show ? undefined : "none"}>
72+
<Participants pull={pull} />
7173
<RefreshButton pull={pull} />
7274
<CommitStatuses pull={pull} />
7375
<Box>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { Pull } from "../pull";
2+
import {
3+
Box
4+
} from "@chakra-ui/react";
5+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
6+
import {
7+
faUser,
8+
faUsers,
9+
} from "@fortawesome/free-solid-svg-icons";
10+
11+
export function Participants({ pull }: { pull: Pull }) {
12+
if (!pull.participants?.length) {
13+
return null;
14+
}
15+
return (
16+
<Box position="absolute" top="2px" right="5px">
17+
<FontAwesomeIcon
18+
icon={pull.participants.length > 1 ? faUsers : faUser}
19+
title={tooltip(pull)}
20+
color={pull.participating() ? "var(--participants-including-me)" : "var(--participants-without-me)"}
21+
/>
22+
</Box>
23+
);
24+
}
25+
26+
function tooltip(pull: Pull) {
27+
if (pull.participants.length == 1) {
28+
return pull.participating() ?
29+
"Only you participating" :
30+
"1 participant"
31+
} else {
32+
return pull.participating() ?
33+
`${pull.participants.length} participants (including you)` :
34+
`${pull.participants.length} participants`;
35+
}
36+
}
37+

frontend/src/pull.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ export class Pull extends PullData {
4949
this.hasCurrentSig(getUser()) ||
5050
this.hasOutdatedSig(getUser()) ||
5151
this.hasMyDevBlock() ||
52-
this.hasMyDeployBlock()
52+
this.hasMyDeployBlock() ||
53+
this.participating()
5354
);
5455
}
5556

@@ -79,6 +80,10 @@ export class Pull extends PullData {
7980
);
8081
}
8182

83+
participating(): boolean {
84+
return this.participants && this.participants.includes(getUser());
85+
}
86+
8287
hasMyDevBlock(): boolean {
8388
return this.getDevBlock()?.data.user.login == getUser();
8489
}

frontend/src/theme/day_theme.less

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ body[data-theme="day_theme"] {
175175
--refresh-background: @white;
176176
--refresh-hover: @blue;
177177

178+
--participants-without-me: @grey;
179+
--participants-including-me: @blue;
180+
178181
// Lines Changed
179182
--additions: darken(@green, 10%);
180183
--deletions: @red;

frontend/src/theme/night_theme.less

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ body[data-theme="night_theme"] {
168168
--refresh-background: @steel;
169169
--refresh-hover: @blue;
170170

171+
--participants-without-me: darken(@grey, 15%);
172+
--participants-including-me: @blue;
173+
171174
--copy-branch: darken(@grey, 15%);
172175
--copy-branch-hover: @blue;
173176

frontend/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,5 @@ export class PullData {
124124
commit_statuses: CommitStatus[];
125125
};
126126
labels: Label[];
127+
participants: string[];
127128
}

frontend/test/named-pulls.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,39 @@ export const MyOwn = <PullData[]>[
390390
}),
391391
];
392392

393+
export const Participants = <PullData[]>[
394+
pullData({
395+
number: 1,
396+
title: "No participants",
397+
cr_req: 0,
398+
participants: [],
399+
}),
400+
pullData({
401+
number: 2,
402+
title: "One participant",
403+
cr_req: 0,
404+
participants: ["Other"],
405+
}),
406+
pullData({
407+
number: 3,
408+
title: "Multiple participants",
409+
cr_req: 0,
410+
participants: ["User2", "User3"],
411+
}),
412+
pullData({
413+
number: 4,
414+
title: "Only me participating",
415+
cr_req: 0,
416+
participants: [getUser()],
417+
}),
418+
pullData({
419+
number: 5,
420+
title: "multiple participants (including me)",
421+
cr_req: 0,
422+
participants: ["User2", "User3", getUser()],
423+
}),
424+
];
425+
393426
export const KitchenSink = <PullData[]>[
394427
pullData({
395428
title: "Pull With Lots of flags and such and a really long title",
@@ -428,5 +461,6 @@ export const KitchenSink = <PullData[]>[
428461
created_at: daysAgo(1 / 24),
429462
}),
430463
],
464+
participants: ["other person", getUser()],
431465
}),
432466
];

frontend/test/pull-card-demo.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
Labels,
1818
Draft,
1919
MyOwn,
20+
Participants,
2021
KitchenSink,
2122
} from "./named-pulls";
2223
import { PullCard } from "../src/pull-card";
@@ -50,6 +51,7 @@ function PullCardDemo() {
5051
<Row title="Labels" pullDatas={Labels} />
5152
<Row title="Draft" pullDatas={Draft} />
5253
<Row title="My Own" pullDatas={MyOwn} />
54+
<Row title="Participants" pullDatas={Participants} />
5355
<Row title="Kitchen Sink (all the things)" pullDatas={KitchenSink} linesChanged={true}/>
5456
</ChakraProvider>
5557
);

frontend/test/pull-data-parts.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export function pullData(p: DeepPartial<PullData>): PullData {
7777
return <PullData>{
7878
repo: repo,
7979
repoSpec: p.repoSpec || null,
80-
number: pullNumber(),
80+
number: p.number || pullNumber(),
8181
state: "open",
8282
draft: p.draft,
8383
title: p.title || "Young pull with no CR / QA",
@@ -113,6 +113,7 @@ export function pullData(p: DeepPartial<PullData>): PullData {
113113
commit_statuses: p.status?.commit_statuses || [],
114114
},
115115
labels: p.labels || [],
116+
participants: p.participants || [],
116117
};
117118
}
118119

0 commit comments

Comments
 (0)