Skip to content

Commit bacbf5b

Browse files
ErwanRauloRaulo Erwan.
andauthored
feat: highlight packages (#740)
Co-authored-by: Raulo Erwan. <erwan.raulo.externe@emeria.eu>
1 parent 43a2263 commit bacbf5b

21 files changed

Lines changed: 262 additions & 85 deletions

File tree

.changeset/little-light-bulb.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@nodesecure/vis-network": minor
3+
---
4+
5+
Visualize highlited packages with dashed yellow border
6+

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ Type a package name directly to search, or prefix with a filter name followed by
151151
- `ext` — file extension present in the package (e.g. `.js`, `.ts`).
152152
- `builtin` — Node.js core module used by the package (e.g. `fs`, `path`).
153153
- `size` — size range (see [size-satisfies](https://github.com/NodeSecure/size-satisfies#usage-example), e.g. `>50kb`, `10kb..200kb`).
154+
- `highlighted` — all highlighted packages by default.
154155

155156
## FAQ
156157

i18n/arabic.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ const ui = {
247247
legend: {
248248
default: "الحزمة بخير.",
249249
warn: "الحزمة بها تحذيرات.",
250-
friendly: "الحزمة تتم صيانتها بواسطة نفس مؤلفي الحزمة الجذرية."
250+
friendly: "الحزمة تتم صيانتها بواسطة نفس مؤلفي الحزمة الجذرية.",
251+
highlighted: "الحزمة جزء من الحزم المميزة"
251252
},
252253
lockedNavigation: {
253254
next: "التالي",

i18n/english.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,13 +322,15 @@ const ui = {
322322
author: "name or email",
323323
ext: "file extension",
324324
builtin: "node.js module",
325-
size: "e.g. >50kb"
325+
size: "e.g. >50kb",
326+
highlighted: "all"
326327
}
327328
},
328329
legend: {
329330
default: "The package is fine.",
330331
warn: "The package has warnings.",
331-
friendly: "The package is maintained by the same authors as the root package."
332+
friendly: "The package is maintained by the same authors as the root package.",
333+
highlighted: "The package is part of highlighted packages"
332334
},
333335
lockedNavigation: {
334336
next: "Next",

i18n/french.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,13 +322,15 @@ const ui = {
322322
author: "nom ou email",
323323
ext: "extension de fichier",
324324
builtin: "module node.js",
325-
size: "ex. >50kb"
325+
size: "ex. >50kb",
326+
highlighted: "all"
326327
}
327328
},
328329
legend: {
329330
default: "Rien à signaler.",
330331
warn: "La dépendance contient des menaces.",
331-
friendly: "La dépendance est maintenu par des auteurs du package principal."
332+
friendly: "La dépendance est maintenu par des auteurs du package principal.",
333+
highlighted: "Le package fait partie des packages mis en évidence"
332334
},
333335
lockedNavigation: {
334336
next: "Suivant",

i18n/turkish.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ const ui = {
249249
legend: {
250250
default: "Paket sorunsuz.",
251251
warn: "Pakette uyarılar var.",
252-
friendly: "Paket, kök paketin yazarlarıyla aynı kişiler tarafından bakılmaktadır."
252+
friendly: "Paket, kök paketin yazarlarıyla aynı kişiler tarafından bakılmaktadır.",
253+
highlighted: "Paket, vurgulanan paketlerin bir parçasıdır"
253254
},
254255
lockedNavigation: {
255256
next: "Sonraki",

public/components/command-palette/command-palette.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
FILTER_HAS_HELPERS,
1212
FILTER_MULTI_SELECT,
1313
PRESETS,
14+
FILTER_INSTANT_CONFIRM,
1415
computeMatches,
1516
getHelperValues
1617
} from "./filters.js";
@@ -97,12 +98,13 @@ class CommandPalette extends LitElement {
9798
#init = ({ detail: { linker, packages, network } }) => {
9899
this.#linker = linker;
99100
this.#network = network;
100-
this.#packages = packages.map(({ id, name, version, flags }) => {
101+
this.#packages = packages.map(({ id, name, version, flags, isHighlighted }) => {
101102
return {
102103
id: String(id),
103104
name,
104105
version,
105-
flags
106+
flags,
107+
isHighlighted
106108
};
107109
});
108110
};
@@ -326,10 +328,15 @@ class CommandPalette extends LitElement {
326328

327329
#selectHelper(helper) {
328330
if (helper.type === "filter") {
329-
this.inputValue = `${helper.value}:`;
330-
this.activeFilter = helper.value;
331-
this.selectedIndex = -1;
332-
this.results = [];
331+
if (FILTER_INSTANT_CONFIRM.has(helper.value)) {
332+
this.#addQuery(helper.value, "all");
333+
}
334+
else {
335+
this.inputValue = `${helper.value}:`;
336+
this.activeFilter = helper.value;
337+
this.selectedIndex = -1;
338+
this.results = [];
339+
}
333340
}
334341
else {
335342
this.#addQuery(this.activeFilter, helper.value);

public/components/command-palette/filters.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const VERSION_PRESETS = [
2020
{ label: "≥ 1.0", value: ">=1.0.0" },
2121
{ label: "< 1.0", value: "<1.0.0" }
2222
];
23-
export const FILTERS_NAME = new Set(["package", "version", "flag", "license", "author", "ext", "builtin", "size"]);
23+
export const FILTERS_NAME = new Set(["package", "version", "flag", "license", "author", "ext", "builtin", "size", "highlighted"]);
2424
export const PRESETS = [
2525
{ id: "has_vulnerabilities", filter: "flag", value: "hasVulnerabilities" },
2626
{ id: "has_scripts", filter: "flag", value: "hasScript" },
@@ -32,6 +32,8 @@ export const PRESETS = [
3232
export const FILTER_HAS_HELPERS = new Set(["license", "ext", "builtin", "author"]);
3333
// Filters where the mode persists after selection (multi-select)
3434
export const FILTER_MULTI_SELECT = new Set(["flag"]);
35+
// Filters that auto-confirm immediately on selection (no text input needed)
36+
export const FILTER_INSTANT_CONFIRM = new Set(["highlighted"]);
3537

3638
/**
3739
* Returns per-flag package counts across the full linker.
@@ -243,6 +245,8 @@ function matchesFilter(opt, filterName, inputValue) {
243245
}
244246
case "flag":
245247
return opt.flags.includes(inputValue);
248+
case "highlighted":
249+
return inputValue === "all" ? opt.isHighlighted === true : opt.isHighlighted !== true;
246250
default:
247251
return false;
248252
}

public/components/legend/legend.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class Legend extends LitElement {
9090
${this.#createLegendBoxElement(colors.WARN, legend.warn)}
9191
${this.#createLegendBoxElement(colors.FRIENDLY, legend.friendly)}
9292
${this.#createLegendBoxElement(colors.DEFAULT, legend.default)}
93+
${this.#createLegendBoxElement(colors.HIGHLIGHTED, legend.highlighted)}
9394
</div>
9495
`;
9596
}
@@ -98,7 +99,7 @@ class Legend extends LitElement {
9899
theme,
99100
text
100101
) {
101-
const style = `background-color: ${theme.color}; color: ${theme.font.color};`;
102+
const style = `background-color: ${theme.color}; color: ${(theme.font ?? COLORS.LIGHT.DEFAULT.font).color};`;
102103

103104
return html`
104105
<div class="legend-box" style=${style}>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ width: 16px;
238238
const { packages, email, url = null, npmAvatar } = data;
239239
const personClasses = {
240240
person: true,
241-
highlighted: this.secureDataSet.isHighlighted(data)
241+
highlighted: this.secureDataSet.isHighlightedContact(data)
242242
};
243243
244244
return html`
@@ -289,9 +289,9 @@ width: 16px;
289289

290290
#highlightContacts(authors) {
291291
const highlightedAuthors = authors
292-
.filter(([_, contact]) => this.secureDataSet.isHighlighted(contact));
292+
.filter(([_, contact]) => this.secureDataSet.isHighlightedContact(contact));
293293

294-
const authorsRest = authors.filter(([_, contact]) => !this.secureDataSet.isHighlighted(contact));
294+
const authorsRest = authors.filter(([_, contact]) => !this.secureDataSet.isHighlightedContact(contact));
295295

296296
return [...highlightedAuthors, ...authorsRest];
297297
}

0 commit comments

Comments
 (0)