Skip to content

Commit 266c8c1

Browse files
authored
feat: highlight selected version (#964)
1 parent 4fd6867 commit 266c8c1

File tree

2 files changed

+98
-7
lines changed

2 files changed

+98
-7
lines changed

app/components/Package/Versions.vue

Lines changed: 97 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const props = defineProps<{
1717
versions: Record<string, SlimVersion>
1818
distTags: Record<string, string>
1919
time: Record<string, string>
20+
selectedVersion?: string
2021
}>()
2122
2223
const chartModal = useModal('chart-modal')
@@ -78,6 +79,10 @@ function versionRoute(version: string): RouteLocationRaw {
7879
// Version to tags lookup (supports multiple tags per version)
7980
const versionToTags = computed(() => buildVersionToTagsMap(props.distTags))
8081
82+
const effectiveCurrentVersion = computed(
83+
() => props.selectedVersion ?? props.distTags.latest ?? undefined,
84+
)
85+
8186
// All tag rows derived from props (SSR-safe)
8287
// Deduplicates so each version appears only once, with all its tags
8388
const allTagRows = computed(() => {
@@ -334,6 +339,65 @@ function toggleMajorGroup(groupKey: string) {
334339
function getTagVersions(tag: string): VersionDisplay[] {
335340
return tagVersions.value.get(tag) ?? []
336341
}
342+
343+
function findClaimingTag(version: string): string | null {
344+
const versionChannel = getPrereleaseChannel(version)
345+
346+
// First matching tag claims the version
347+
for (const row of allTagRows.value) {
348+
const tagVersion = props.distTags[row.tag]
349+
if (!tagVersion) continue
350+
351+
const tagChannel = getPrereleaseChannel(tagVersion)
352+
353+
if (isSameVersionGroup(version, tagVersion) && versionChannel === tagChannel) {
354+
return row.tag
355+
}
356+
}
357+
358+
return null
359+
}
360+
361+
// Whether this row should be highlighted for the current version
362+
function rowContainsCurrentVersion(row: (typeof visibleTagRows.value)[0]): boolean {
363+
if (!effectiveCurrentVersion.value) return false
364+
365+
if (row.primaryVersion.version === effectiveCurrentVersion.value) return true
366+
367+
if (getTagVersions(row.tag).some(v => v.version === effectiveCurrentVersion.value)) return true
368+
369+
const claimingTag = findClaimingTag(effectiveCurrentVersion.value)
370+
return claimingTag === row.tag
371+
}
372+
373+
function otherVersionsContainsCurrent(): boolean {
374+
if (!effectiveCurrentVersion.value) return false
375+
376+
const claimingTag = findClaimingTag(effectiveCurrentVersion.value)
377+
378+
// If a tag claims it, check if that tag is in visibleTagRows
379+
if (claimingTag) {
380+
const isInVisibleTags = visibleTagRows.value.some(row => row.tag === claimingTag)
381+
if (!isInVisibleTags) return true
382+
return false
383+
}
384+
385+
// No tag claims it - it would be in otherMajorGroups
386+
return true
387+
}
388+
389+
function hiddenRowContainsCurrent(row: (typeof hiddenTagRows.value)[0]): boolean {
390+
if (!effectiveCurrentVersion.value) return false
391+
if (row.primaryVersion.version === effectiveCurrentVersion.value) return true
392+
393+
const claimingTag = findClaimingTag(effectiveCurrentVersion.value)
394+
return claimingTag === row.tag
395+
}
396+
397+
function majorGroupContainsCurrent(group: (typeof otherMajorGroups.value)[0]): boolean {
398+
if (!effectiveCurrentVersion.value) return false
399+
return group.versions.some(v => v.version === effectiveCurrentVersion.value)
400+
}
337401
</script>
338402

339403
<template>
@@ -358,7 +422,7 @@ function getTagVersions(tag: string): VersionDisplay[] {
358422
<div v-for="row in visibleTagRows" :key="row.id">
359423
<div
360424
class="flex items-center gap-2 pe-2 px-1"
361-
:class="row.tag === 'latest' ? 'bg-bg-subtle rounded-lg' : ''"
425+
:class="rowContainsCurrentVersion(row) ? 'bg-bg-subtle rounded-lg' : ''"
362426
>
363427
<!-- Expand button (only if there are more versions to show) -->
364428
<button
@@ -451,7 +515,12 @@ function getTagVersions(tag: string): VersionDisplay[] {
451515
v-if="expandedTags.has(row.tag) && getTagVersions(row.tag).length > 1"
452516
class="ms-4 ps-2 border-is border-border space-y-0.5 pe-2"
453517
>
454-
<div v-for="v in getTagVersions(row.tag).slice(1)" :key="v.version" class="py-1">
518+
<div
519+
v-for="v in getTagVersions(row.tag).slice(1)"
520+
:key="v.version"
521+
class="py-1"
522+
:class="v.version === effectiveCurrentVersion ? 'rounded bg-bg-subtle px-2 -mx-2' : ''"
523+
>
455524
<div class="flex items-center justify-between gap-2">
456525
<LinkBase
457526
:to="versionRoute(v.version)"
@@ -511,7 +580,8 @@ function getTagVersions(tag: string): VersionDisplay[] {
511580
<div class="p-1">
512581
<button
513582
type="button"
514-
class="flex items-center gap-2 text-start rounded-sm"
583+
class="flex items-center gap-2 text-start rounded-sm w-full"
584+
:class="otherVersionsContainsCurrent() ? 'bg-bg-subtle' : ''"
515585
:aria-expanded="otherVersionsExpanded"
516586
:aria-label="
517587
otherVersionsExpanded
@@ -553,7 +623,12 @@ function getTagVersions(tag: string): VersionDisplay[] {
553623
<!-- Expanded other versions -->
554624
<div v-if="otherVersionsExpanded" class="ms-4 ps-2 border-is border-border space-y-0.5">
555625
<!-- Hidden tag rows (overflow from visible tags) -->
556-
<div v-for="row in hiddenTagRows" :key="row.id" class="py-1">
626+
<div
627+
v-for="row in hiddenTagRows"
628+
:key="row.id"
629+
class="py-1"
630+
:class="hiddenRowContainsCurrent(row) ? 'rounded bg-bg-subtle px-2 -mx-2' : ''"
631+
>
557632
<div class="flex items-center justify-between gap-2">
558633
<LinkBase
559634
:to="versionRoute(row.primaryVersion.version)"
@@ -604,7 +679,11 @@ function getTagVersions(tag: string): VersionDisplay[] {
604679
<template v-if="otherMajorGroups.length > 0">
605680
<div v-for="group in otherMajorGroups" :key="group.groupKey">
606681
<!-- Version group header -->
607-
<div v-if="group.versions.length > 1" class="py-1">
682+
<div
683+
v-if="group.versions.length > 1"
684+
class="py-1"
685+
:class="majorGroupContainsCurrent(group) ? 'rounded bg-bg-subtle px-2 -mx-2' : ''"
686+
>
608687
<div class="flex items-center justify-between gap-2">
609688
<div class="flex items-center gap-2 min-w-0">
610689
<button
@@ -687,7 +766,11 @@ function getTagVersions(tag: string): VersionDisplay[] {
687766
</div>
688767
</div>
689768
<!-- Single version (no expand needed) -->
690-
<div v-else class="py-1">
769+
<div
770+
v-else
771+
class="py-1"
772+
:class="majorGroupContainsCurrent(group) ? 'rounded bg-bg-subtle px-2 -mx-2' : ''"
773+
>
691774
<div class="flex items-center justify-between gap-2">
692775
<div class="flex items-center gap-2 min-w-0">
693776
<LinkBase
@@ -749,7 +832,14 @@ function getTagVersions(tag: string): VersionDisplay[] {
749832
v-if="expandedMajorGroups.has(group.groupKey) && group.versions.length > 1"
750833
class="ms-6 space-y-0.5"
751834
>
752-
<div v-for="v in group.versions.slice(1)" :key="v.version" class="py-1">
835+
<div
836+
v-for="v in group.versions.slice(1)"
837+
:key="v.version"
838+
class="py-1"
839+
:class="
840+
v.version === effectiveCurrentVersion ? 'rounded bg-bg-subtle px-2 -mx-2' : ''
841+
"
842+
>
753843
<div class="flex items-center justify-between gap-2">
754844
<LinkBase
755845
:to="versionRoute(v.version)"

app/pages/package/[[org]]/[name].vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,6 +1289,7 @@ const showSkeleton = shallowRef(false)
12891289
:versions="pkg.versions"
12901290
:dist-tags="pkg['dist-tags'] ?? {}"
12911291
:time="pkg.time"
1292+
:selected-version="resolvedVersion ?? pkg['dist-tags']?.['latest']"
12921293
/>
12931294

12941295
<!-- Install Scripts Warning -->

0 commit comments

Comments
 (0)