Skip to content

Commit 78864eb

Browse files
committed
fix: show filtered versions claimed by tag rows in semver filter
Tag rows were hidden when their primary version didn't match the filter, even if child versions did. For example, filtering for `~3.4.0` on vue hid the `latest` row (pointing to 3.5.13), making 3.4.0 invisible since it was claimed by that tag and not in "Other versions". Now tag rows stay visible when any child version matches, and matching children are auto-expanded when a filter is active. Also fixes the test to exercise the real bug scenario (same-major child version).
1 parent d2fa466 commit 78864eb

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

app/components/Package/Versions.vue

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,10 @@ const visibleTagRows = computed(() => {
212212
? allTagRows.value
213213
: allTagRows.value.filter(row => !row.primaryVersion.deprecated)
214214
const rows = isFilterActive.value
215-
? rowsMaybeFilteredForDeprecation.filter(row =>
216-
filteredVersionSet.value.has(row.primaryVersion.version),
215+
? rowsMaybeFilteredForDeprecation.filter(
216+
row =>
217+
filteredVersionSet.value.has(row.primaryVersion.version) ||
218+
getTagVersions(row.tag).some(v => filteredVersionSet.value.has(v.version)),
217219
)
218220
: rowsMaybeFilteredForDeprecation
219221
const first = rows.slice(0, MAX_VISIBLE_TAGS)
@@ -231,7 +233,11 @@ const visibleTagRows = computed(() => {
231233
const hiddenTagRows = computed(() => {
232234
const hiddenRows = allTagRows.value.filter(row => !visibleTagRows.value.includes(row))
233235
const rows = isFilterActive.value
234-
? hiddenRows.filter(row => filteredVersionSet.value.has(row.primaryVersion.version))
236+
? hiddenRows.filter(
237+
row =>
238+
filteredVersionSet.value.has(row.primaryVersion.version) ||
239+
getTagVersions(row.tag).some(v => filteredVersionSet.value.has(v.version)),
240+
)
235241
: hiddenRows
236242
return rows
237243
})
@@ -688,7 +694,7 @@ function majorGroupContainsCurrent(group: (typeof otherMajorGroups.value)[0]): b
688694
<!-- Expanded versions -->
689695
<div
690696
v-if="
691-
expandedTags.has(row.tag) &&
697+
(expandedTags.has(row.tag) || isFilterActive) &&
692698
getExpandedTagVersions(row.tag, row.primaryVersion.version).length
693699
"
694700
class="ms-4 ps-2 border-is border-border space-y-0.5 pe-2"

test/nuxt/components/PackageVersions.spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,43 +1129,43 @@ describe('PackageVersions', () => {
11291129

11301130
it('loads all versions when a valid semver filter is entered', async () => {
11311131
mockFetchAllPackageVersions.mockResolvedValue([
1132-
{ version: '3.0.0', time: '2024-04-01T00:00:00.000Z', hasProvenance: false },
1133-
{ version: '2.1.0', time: '2024-03-01T00:00:00.000Z', hasProvenance: false },
1134-
{ version: '2.0.0', time: '2024-02-01T00:00:00.000Z', hasProvenance: false },
1135-
{ version: '1.5.0', time: '2024-01-15T00:00:00.000Z', hasProvenance: false },
1132+
{ version: '3.5.0', time: '2024-04-01T00:00:00.000Z', hasProvenance: false },
1133+
{ version: '3.4.0', time: '2024-03-01T00:00:00.000Z', hasProvenance: false },
1134+
{ version: '3.3.0', time: '2024-02-01T00:00:00.000Z', hasProvenance: false },
1135+
{ version: '2.0.0', time: '2024-01-15T00:00:00.000Z', hasProvenance: false },
11361136
{ version: '1.0.0', time: '2024-01-01T00:00:00.000Z', hasProvenance: false },
11371137
])
11381138

1139-
// Only provide a subset of versions in props (simulating initial SSR payload)
1139+
// Only provide latest in props (simulating initial SSR payload)
11401140
const component = await mountSuspended(PackageVersions, {
11411141
props: {
11421142
packageName: 'test-package',
11431143
versions: {
1144-
'3.0.0': createVersion('3.0.0'),
1144+
'3.5.0': createVersion('3.5.0'),
11451145
},
1146-
distTags: { latest: '3.0.0' },
1147-
time: { '3.0.0': '2024-04-01T00:00:00.000Z' },
1146+
distTags: { latest: '3.5.0' },
1147+
time: { '3.5.0': '2024-04-01T00:00:00.000Z' },
11481148
},
11491149
})
11501150

1151-
// Filter for a version NOT in the initial props
1151+
// Filter for a version in the SAME major group as latest (claimed by the tag)
11521152
const input = component.find('input[type="text"]')
1153-
await input.setValue('1.5.0')
1153+
await input.setValue('~3.4.0')
11541154

11551155
// Should trigger loading all versions
11561156
await vi.waitFor(() => {
11571157
expect(mockFetchAllPackageVersions).toHaveBeenCalledWith('test-package')
11581158
})
11591159

1160-
// After loading, 1.5.0 should appear in the results
1160+
// After loading, 3.4.0 should appear as an auto-expanded child of the latest tag
11611161
await vi.waitFor(() => {
11621162
const versionLinks = component
11631163
.findAll('a')
11641164
.filter(
11651165
a => !a.attributes('href')?.startsWith('#') && a.attributes('target') !== '_blank',
11661166
)
11671167
const versions = versionLinks.map(l => l.text())
1168-
expect(versions).toContain('1.5.0')
1168+
expect(versions).toContain('3.4.0')
11691169
})
11701170
})
11711171

0 commit comments

Comments
 (0)