Skip to content

Commit d04b30b

Browse files
committed
feat(maintainers): can highlight by email
1 parent ec6c0f4 commit d04b30b

File tree

5 files changed

+78
-12
lines changed

5 files changed

+78
-12
lines changed

public/components/views/home/maintainers/maintainers.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ body.dark .home--maintainers>.person {
3030
background: linear-gradient(to bottom, rgb(230, 240, 250) 0%, rgb(220, 235, 245) 100%);
3131
}
3232

33+
body.dark .home--maintainers > .highlighted {
34+
background: linear-gradient(to right, rgb(11, 3, 31) 0%, rgba(46, 10, 10, 0.8) 100%);
35+
}
36+
3337
.home--maintainers>.person:hover {
3438
border-color: var(--secondary-darker);
3539
cursor: pointer;

public/components/views/home/maintainers/maintainers.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,24 @@ export class Maintainers {
2626
}
2727

2828
render() {
29-
const highlightedContacts = new Set(this.secureDataSet.data.highlighted.contacts
30-
.map(({ name }) => name));
3129
const authors = this.#highlightContacts([...this.secureDataSet.authors.entries()]
32-
.sort((left, right) => right[1].packages.size - left[1].packages.size),
33-
highlightedContacts);
30+
.sort((left, right) => right[1].packages.size - left[1].packages.size));
3431

3532
document.getElementById("authors-count").innerHTML = authors.length;
3633
document.querySelector(".home--maintainers")
37-
.appendChild(this.generate(authors, highlightedContacts));
34+
.appendChild(this.generate(authors));
3835
}
3936

40-
#highlightContacts(authors, highlightedContacts) {
41-
const highlightedAuthors = authors.filter(([name]) => highlightedContacts.has(name));
42-
const authorsRest = authors.filter(([name]) => !highlightedContacts.has(name));
37+
#highlightContacts(authors) {
38+
const highlightedAuthors = authors
39+
.filter(([_, contact]) => this.secureDataSet.isHighlighted(contact));
40+
41+
const authorsRest = authors.filter(([_, contact]) => !this.secureDataSet.isHighlighted(contact));
4342

4443
return [...highlightedAuthors, ...authorsRest];
4544
}
4645

47-
generate(authors, highlightedContacts) {
46+
generate(authors) {
4847
const fragment = document.createDocumentFragment();
4948
const hideItems = authors.length > this.maximumMaintainers;
5049

@@ -71,7 +70,7 @@ export class Maintainers {
7170
})
7271
]
7372
});
74-
if (highlightedContacts.has(name)) {
73+
if (this.secureDataSet.isHighlighted(data)) {
7574
person.classList.add("highlighted");
7675
}
7776
if (hideItems && id >= this.maximumMaintainers) {

workspaces/vis-network/src/dataset.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ export default class NodeSecureDataSet extends EventTarget {
1313
* @param {string[]} [options.warningsToIgnore=[]]
1414
* @param {"light"|"dark"} [options.theme]
1515
*/
16+
17+
#highligthedContacts;
18+
1619
constructor(options = {}) {
1720
super();
1821
const {
1922
flagsToIgnore = [],
2023
warningsToIgnore = [],
2124
theme = "light"
2225
} = options;
23-
2426
this.flagsToIgnore = new Set(flagsToIgnore);
2527
this.warningsToIgnore = new Set(warningsToIgnore);
2628
this.theme = theme;
@@ -76,6 +78,18 @@ export default class NodeSecureDataSet extends EventTarget {
7678

7779
this.warnings = data.warnings;
7880

81+
this.#highligthedContacts = data.highlighted.contacts
82+
.reduce((acc, { name, email }) => {
83+
if (name) {
84+
acc.names.add(name);
85+
}
86+
if (email) {
87+
acc.emails.add(email);
88+
}
89+
90+
return acc;
91+
}, { names: new Set(), emails: new Set() });
92+
7993
const dataEntries = Object.entries(data.dependencies);
8094
this.dependenciesCount = dataEntries.length;
8195

@@ -210,4 +224,8 @@ export default class NodeSecureDataSet extends EventTarget {
210224

211225
return { nodes, edges };
212226
}
227+
228+
isHighlighted(contact) {
229+
return this.#highligthedContacts.names.has(contact.name) || this.#highligthedContacts.emails.has(contact.email);
230+
}
213231
}

workspaces/vis-network/test/dataset-payload.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,37 @@
11
{
22
"id": "abcde",
33
"rootDepencyName": "pkg1",
4+
"highlighted": {
5+
"contacts": [
6+
{
7+
"email": "[email protected]",
8+
"dependencies": [
9+
"frequency-set",
10+
"sec-literal",
11+
"js-x-ray"
12+
]
13+
},
14+
{
15+
"name": "Rich Harris",
16+
"email": "[email protected]",
17+
"dependencies": [
18+
"frequency-set",
19+
"sec-literal",
20+
"js-x-ray"
21+
]
22+
},
23+
{
24+
"name": "Sindre Sorhus",
25+
"dependencies": [
26+
"is-svg",
27+
"ansi-regex",
28+
"strip-ansi",
29+
"is-fullwidth-code-point",
30+
"string-width"
31+
]
32+
}
33+
]
34+
},
435
"dependencies": {
536
"pkg2": {
637
"versions": {

workspaces/vis-network/test/dataset.test.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const dataSetPayload = await getDataSetPayload();
1111
test("NodeSecureDataSet.init with given payload", async() => {
1212
const nsDataSet = new NodeSecureDataSet();
1313
await nsDataSet.init(dataSetPayload);
14-
1514
assert.equal(nsDataSet.data, dataSetPayload, "should set data");
1615
});
1716

@@ -41,6 +40,21 @@ test("NodeSecureDataSet.computeExtensions", () => {
4140
assert.equal(nsDataSet.extensions[".js"], 2, "should have 2 '.js' extensions'");
4241
});
4342

43+
test("NodeSecureDataSet.isHighlighted", async() => {
44+
const nsDataSet = new NodeSecureDataSet();
45+
await nsDataSet.init(dataSetPayload);
46+
assert.equal(nsDataSet.isHighlighted({ name: "Unknown" }), false, "should not be hightlighted");
47+
assert.equal(nsDataSet.isHighlighted({ name: "Sindre Sorhus" }), true, "name: Sindre Sorhus should be hightlighted");
48+
assert.equal(nsDataSet.isHighlighted({ name: "Rich Harris" }), true, "name: Rich Harris should be hightlighted");
49+
assert.equal(nsDataSet.isHighlighted({ email: "[email protected]" }),
50+
true,
51+
"email: [email protected] should be hightlighted");
52+
53+
assert.equal(nsDataSet.isHighlighted({ email: "[email protected]" }),
54+
true,
55+
"email: [email protected] should be hightlighted");
56+
});
57+
4458
test("NodeSecureDataSet.computeLicenses", () => {
4559
const nsDataSet = new NodeSecureDataSet();
4660
nsDataSet.computeLicense("MIT");

0 commit comments

Comments
 (0)