Skip to content

Commit 1419fc7

Browse files
authored
fix: pass name/version separately in comparison grid (#1098)
1 parent 52cd1da commit 1419fc7

File tree

4 files changed

+18
-21
lines changed

4 files changed

+18
-21
lines changed

app/components/Compare/ComparisonGrid.vue

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import type { ModuleReplacement } from 'module-replacements'
33
44
export interface ComparisonGridColumn {
5-
/** Display text (e.g. "lodash@4.17.21") */
6-
header: string
5+
name: string
6+
version?: string
77
/** Module replacement data for this package (if available) */
88
replacement?: ModuleReplacement | null
99
}
@@ -38,18 +38,14 @@ function getReplacementTooltip(col: ComparisonGridColumn): string {
3838
<div class="comparison-label" />
3939

4040
<!-- Package columns -->
41-
<div
42-
v-for="col in columns"
43-
:key="col.header"
44-
class="comparison-cell comparison-cell-header"
45-
>
41+
<div v-for="col in columns" :key="col.name" class="comparison-cell comparison-cell-header">
4642
<span class="inline-flex items-center gap-1.5 truncate">
4743
<NuxtLink
48-
:to="packageRoute(col.header)"
44+
:to="packageRoute(col.name, col.version)"
4945
class="link-subtle font-mono text-sm font-medium text-fg truncate"
50-
:title="col.header"
46+
:title="col.version ? `${col.name}@${col.version}` : col.name"
5147
>
52-
{{ col.header }}
48+
{{ col.name }}<template v-if="col.version">@{{ col.version }}</template>
5349
</NuxtLink>
5450
<TooltipApp v-if="col.replacement" :text="getReplacementTooltip(col)" position="bottom">
5551
<span

app/pages/compare.vue

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,9 @@ const gridColumns = computed(() =>
4747
.filter(({ pkg }) => pkg !== NO_DEPENDENCY_ID)
4848
.map(({ pkg, originalIndex }) => {
4949
const data = packagesData.value?.[originalIndex]
50-
const header = data
51-
? data.package.version
52-
? `${data.package.name}@${data.package.version}`
53-
: data.package.name
54-
: pkg
5550
return {
56-
header,
51+
name: data?.package.name || pkg,
52+
version: data?.package.version,
5753
replacement: replacements.value.get(pkg) ?? null,
5854
}
5955
}),
@@ -78,7 +74,9 @@ const columnLoading = computed(() => packages.value.map((_, i) => isColumnLoadin
7874
const canCompare = computed(() => packages.value.length >= 2)
7975
8076
// Extract headers from columns for facet rows
81-
const gridHeaders = computed(() => gridColumns.value.map(col => col.header))
77+
const gridHeaders = computed(() =>
78+
gridColumns.value.map(col => (col.version ? `${col.name}@${col.version}` : col.name)),
79+
)
8280
8381
useSeoMeta({
8482
title: () =>

test/nuxt/a11y.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,7 +1613,7 @@ describe('component accessibility audits', () => {
16131613
it('should have no accessibility violations with 2 columns', async () => {
16141614
const component = await mountSuspended(CompareComparisonGrid, {
16151615
props: {
1616-
columns: [{ header: 'vue' }, { header: 'react' }],
1616+
columns: [{ name: 'vue' }, { name: 'react' }],
16171617
},
16181618
slots: {
16191619
default: '<div>Grid content</div>',
@@ -1626,7 +1626,7 @@ describe('component accessibility audits', () => {
16261626
it('should have no accessibility violations with 3 columns', async () => {
16271627
const component = await mountSuspended(CompareComparisonGrid, {
16281628
props: {
1629-
columns: [{ header: 'vue' }, { header: 'react' }, { header: 'angular' }],
1629+
columns: [{ name: 'vue' }, { name: 'react' }, { name: 'angular' }],
16301630
},
16311631
slots: {
16321632
default: '<div>Grid content</div>',
@@ -1639,7 +1639,7 @@ describe('component accessibility audits', () => {
16391639
it('should have no accessibility violations with no-dependency column', async () => {
16401640
const component = await mountSuspended(CompareComparisonGrid, {
16411641
props: {
1642-
columns: [{ header: 'vue' }, { header: 'react' }],
1642+
columns: [{ name: 'vue' }, { name: 'react' }],
16431643
showNoDependency: true,
16441644
},
16451645
slots: {

test/nuxt/components/compare/ComparisonGrid.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import { mountSuspended } from '@nuxt/test-utils/runtime'
33
import ComparisonGrid from '~/components/Compare/ComparisonGrid.vue'
44

55
function cols(...headers: string[]) {
6-
return headers.map(header => ({ header }))
6+
return headers.map(header => {
7+
const [name, version] = header.split('@')
8+
return { name: name!, version }
9+
})
710
}
811

912
describe('ComparisonGrid', () => {

0 commit comments

Comments
 (0)