Skip to content

Commit c17f748

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

File tree

5 files changed

+72
-12
lines changed

5 files changed

+72
-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 bottom, #4b3d6a 0%, #342a4d 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: 18 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,17 @@ 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+
return acc
90+
}, {names: new Set(), emails: new Set()});
91+
7992
const dataEntries = Object.entries(data.dependencies);
8093
this.dependenciesCount = dataEntries.length;
8194

@@ -210,4 +223,8 @@ export default class NodeSecureDataSet extends EventTarget {
210223

211224
return { nodes, edges };
212225
}
226+
227+
isHighlighted(contact){
228+
return this.#highligthedContacts.names.has(contact.name) || this.#highligthedContacts.emails.has(contact.email);
229+
}
213230
}

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: 10 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,16 @@ 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]"}), true, "email: [email protected] should be hightlighted");
50+
assert.equal(nsDataSet.isHighlighted({email: "[email protected]"}), true, "email: [email protected] should be hightlighted");
51+
});
52+
4453
test("NodeSecureDataSet.computeLicenses", () => {
4554
const nsDataSet = new NodeSecureDataSet();
4655
nsDataSet.computeLicense("MIT");

0 commit comments

Comments
 (0)