Skip to content

Commit 0150b6e

Browse files
authored
Merge pull request #8 from spack/sidebar-spec-counts
Sidebar spec counts
2 parents 49ebec6 + 6eca1a0 commit 0150b6e

2 files changed

Lines changed: 30 additions & 16 deletions

File tree

‎data.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,14 @@ def get_data(release, stack, package):
9797
uid=package_name,
9898
url=f'https://packages.spack.io/package.html?name={package_name}',
9999
releases=set(),
100-
specs=set(),
100+
specs={},
101101
)
102102
packages[package_name]['releases'].add(release_name)
103+
if release_name not in packages[package_name]['specs']:
104+
packages[package_name]['specs'][release_name] = set()
103105

104106
spec_hash = spec['hash']
105-
packages[package_name]['specs'].add(spec_hash)
107+
packages[package_name]['specs'][release_name].add(spec_hash)
106108
if spec_hash not in specs:
107109
arch = spec['arch']
108110
target = arch['target']

‎templates/static/script.js‎

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ function showContent(content_id) {
104104
function setPackageName(name) {
105105
setTextByClassName('package-name', name)
106106
if (specData) {
107-
currentSpecs = packageData[packageName].specs.map((hash) => specData[hash]);
107+
const allSpecHashes = Object.values(packageData[name].specs).flat();
108+
currentSpecs = allSpecHashes.map((hash) => specData[hash]);
108109
setTextByClassName('num-specs', currentSpecs.length.toLocaleString())
109110
updateBadgeOptions();
110111
}
@@ -130,7 +131,8 @@ function computePackageAttrValueSpecs() {
130131
packageAttrValueSpecs = {};
131132
for (const pName in packageData) {
132133
packageAttrValueSpecs[pName] = {};
133-
for (const specHash of packageData[pName].specs) {
134+
const allSpecHashes = Object.values(packageData[pName].specs).flat();
135+
for (const specHash of allSpecHashes) {
134136
for (const key in specData[specHash]) {
135137
if (!packageAttrValueSpecs[pName][key]) packageAttrValueSpecs[pName][key] = {};
136138
let values = specData[specHash][key];
@@ -330,7 +332,12 @@ function filterSidebar() {
330332
match &&= matchComplete && matchingSpecs && matchingSpecs.size > 0;
331333
specCount.innerHTML = matchComplete && matchingSpecs ? matchingSpecs.size : 0
332334
} else {
333-
specCount.innerHTML = packageData[item.package].specs.length;
335+
if (item.release) {
336+
specCount.innerHTML = packageData[item.package].specs[item.release].length;
337+
} else {
338+
const allSpecHashes = Object.values(packageData[item.package].specs).flat();
339+
specCount.innerHTML = allSpecHashes.length;
340+
}
334341
}
335342
if (match) {
336343
resultsFound = true;
@@ -342,11 +349,12 @@ function filterSidebar() {
342349
}
343350
})
344351
Array.from(document.getElementsByClassName('sidebar-group')).forEach((group) => {
345-
const childContainer = $(group).find('ul').get(0);
346-
const childCounter = $(group).find('.child-counter').get(0);
347-
const matchedChildren = Array.from(childContainer.children).filter((child) => !child.classList.contains('hidden'));
348-
childCounter.innerHTML = matchedChildren.length.toLocaleString();
349-
if (matchedChildren.length && (showDevs || !group.release.includes('develop'))) {
352+
const specCounts = $(group).find('ul').children().not('.hidden').find('.spec-counter').map(
353+
(_, item) => parseInt($(item).text())
354+
).get()
355+
const specSum = specCounts.reduce((acc, curr) => acc + curr, 0);
356+
$(group).find('.child-counter').text(specSum);
357+
if (specCounts.length && (showDevs || !group.release.includes('develop'))) {
350358
group.classList.remove('hidden');
351359
if (emphasisString.length > 0) group.classList.remove('collapsed');
352360
} else {
@@ -406,9 +414,13 @@ function createSidebarItem(pkg, releaseName) {
406414
nameLabel.innerHTML = pkg.uid;
407415
item.appendChild(nameLabel);
408416
const numSpecsLabel = document.createElement('span');
409-
numSpecsLabel.classList.add('text-muted-foreground');
410-
numSpecsLabel.innerHTML = pkg.specs.length;
411-
if (releaseName) numSpecsLabel.classList.add('hidden');
417+
numSpecsLabel.classList.add('text-muted-foreground', 'spec-counter');
418+
if (releaseName) {
419+
numSpecsLabel.innerHTML = pkg.specs[releaseName].length;
420+
} else {
421+
const allSpecHashes = Object.values(pkg.specs).flat();
422+
numSpecsLabel.innerHTML = allSpecHashes.length;
423+
}
412424
item.appendChild(numSpecsLabel);
413425
item.onclick = (e) => {
414426
e.stopPropagation();
@@ -451,9 +463,9 @@ function createSidebarGroup(groupName) {
451463
groupNameLabel.classList.add('truncate', 'font-medium', 'text-sm');
452464
groupNameLabel.innerHTML = groupName;
453465
groupButton.appendChild(groupNameLabel);
454-
const groupPackageCountLabel = document.createElement('span');
455-
groupPackageCountLabel.classList.add('ml-auto', 'text-xs', 'text-muted-foreground', 'child-counter');
456-
groupButton.appendChild(groupPackageCountLabel);
466+
const groupSpecCountLabel = document.createElement('span');
467+
groupSpecCountLabel.classList.add('ml-auto', 'text-xs', 'text-muted-foreground', 'child-counter');
468+
groupButton.appendChild(groupSpecCountLabel);
457469
groupContainer.appendChild(groupButton);
458470
group.appendChild(groupContainer);
459471
const childrenContainer = document.createElement('ul');

0 commit comments

Comments
 (0)