Skip to content

Commit 3b755a4

Browse files
authored
refactor(frontend): streamline ecosystem auto-expand logic (#4045)
Refactors the Ecosystem Header expand/collapse logic for cases where multi-ecosystem vulnerabilities with large package counts stay collapsed by default. Single-ecosystem vulns behave as before. This helps avoid endless vertical scrolling for cases like: [RHSA-2025:16669](https://osv.dev/vulnerability/RHSA-2025:16669)
1 parent 43a6878 commit 3b755a4

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

gcp/website/frontend3/src/templates/vulnerability.html

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -497,23 +497,36 @@ <h3 class="mdc-layout-grid__cell--span-3">
497497
document.addEventListener('turbo:load', function() {
498498
const ECOSYSTEM_EXPAND_THRESHOLD = 10;
499499
const PACKAGE_EXPAND_THRESHOLD = 7;
500+
const ECOSYSTEM_PACKAGE_COLLAPSE_THRESHOLD = 9;
500501

501502
/**
502503
* Sets up the vertical, grouped layout for vulnerability packages.
503-
* - All ecosystem headers are expanded if their total count is below `ECOSYSTEM_EXPAND_THRESHOLD`.
504+
* - All ecosystem headers are expanded if their total count is below `ECOSYSTEM_EXPAND_THRESHOLD`,
505+
* and if their total packages count is below `ECOSYSTEM_PACKAGE_COLLAPSE_THRESHOLD`.
504506
* - Within each ecosystem, all package headers are expanded if their count is below `PACKAGE_EXPAND_THRESHOLD`.
505507
*/
506508
function setupVerticalLayout() {
507509
const ecosystemHeaders = document.querySelectorAll('.vulnerability-packages.force-collapse .package-header');
508510
if (!ecosystemHeaders.length) return;
509511

510-
if (ecosystemHeaders.length < ECOSYSTEM_EXPAND_THRESHOLD) {
511-
ecosystemHeaders.forEach(header => {
512-
if (header.getAttribute('aria-expanded') === 'false') {
513-
header.click();
514-
}
515-
});
516-
}
512+
const shouldExpandEcosystems = ecosystemHeaders.length < ECOSYSTEM_EXPAND_THRESHOLD;
513+
514+
ecosystemHeaders.forEach(header => {
515+
const panel = header.nextElementSibling;
516+
const packageHeaders = panel ? panel.querySelectorAll('.package-name-title') : [];
517+
const hasManyPackages =
518+
ecosystemHeaders.length > 1 && packageHeaders.length > ECOSYSTEM_PACKAGE_COLLAPSE_THRESHOLD;
519+
520+
const shouldExpandHeader =
521+
shouldExpandEcosystems &&
522+
header.getAttribute('aria-expanded') === 'false' &&
523+
panel !== null &&
524+
!hasManyPackages;
525+
526+
if (shouldExpandHeader) {
527+
header.click();
528+
}
529+
});
517530

518531
const ecosystemPanels = document.querySelectorAll('.ecosystem-content-panel');
519532
ecosystemPanels.forEach(panel => {

0 commit comments

Comments
 (0)