Skip to content

Commit 270cfbe

Browse files
committed
refactor: consistently use "facet" terminology
1 parent 5e9c8c5 commit 270cfbe

7 files changed

Lines changed: 54 additions & 111 deletions

File tree

app/components/compare/ComparisonGrid.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ defineProps<{
2828
</div>
2929
</div>
3030

31-
<!-- Metric rows -->
31+
<!-- Facet rows -->
3232
<slot />
3333
</div>
3434
</div>
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<script setup lang="ts">
2-
import type { MetricValue, DiffResult } from '#shared/types'
2+
import type { FacetValue, FacetDiffResult } from '#shared/types'
33
44
const props = defineProps<{
5-
/** Metric label */
5+
/** Facet label */
66
label: string
7-
/** Description/tooltip for the metric */
7+
/** Description/tooltip for the facet */
88
description?: string
99
/** Values for each column */
10-
values: (MetricValue | null | undefined)[]
10+
values: (FacetValue | null | undefined)[]
1111
/** Diff results between adjacent columns (for release comparison) */
12-
diffs?: (DiffResult | null | undefined)[]
12+
diffs?: (FacetDiffResult | null | undefined)[]
1313
/** Whether this row is loading */
1414
loading?: boolean
1515
/** Whether to show the proportional bar (defaults to true for numeric values) */
@@ -33,12 +33,12 @@ const maxValue = computed(() => {
3333
})
3434
3535
// Calculate bar width percentage for a value
36-
function getBarWidth(value: MetricValue | null | undefined): number {
36+
function getBarWidth(value: FacetValue | null | undefined): number {
3737
if (!isNumeric.value || !maxValue.value || !value || typeof value.raw !== 'number') return 0
3838
return (value.raw / maxValue.value) * 100
3939
}
4040
41-
function getStatusClass(status?: MetricValue['status']): string {
41+
function getStatusClass(status?: FacetValue['status']): string {
4242
switch (status) {
4343
case 'good':
4444
return 'text-emerald-400'
@@ -53,14 +53,14 @@ function getStatusClass(status?: MetricValue['status']): string {
5353
}
5454
}
5555
56-
function getDiffClass(diff?: DiffResult | null): string {
56+
function getDiffClass(diff?: FacetDiffResult | null): string {
5757
if (!diff) return ''
5858
if (diff.favorable === true) return 'text-emerald-400'
5959
if (diff.favorable === false) return 'text-red-400'
6060
return 'text-fg-muted'
6161
}
6262
63-
function getDiffIcon(diff?: DiffResult | null): string {
63+
function getDiffIcon(diff?: FacetDiffResult | null): string {
6464
if (!diff) return ''
6565
switch (diff.direction) {
6666
case 'increase':

app/composables/usePackageComparison.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { MetricValue, ComparisonFacet, ComparisonPackage } from '#shared/types'
1+
import type { FacetValue, ComparisonFacet, ComparisonPackage } from '#shared/types'
22
import type { PackageAnalysisResponse } from './usePackageAnalysis'
33

44
export interface PackageComparisonData {
@@ -176,13 +176,13 @@ export function usePackageComparison(packageNames: MaybeRefOrGetter<string[]>) {
176176
)
177177
}
178178

179-
// Compute metrics for each facet
180-
function getMetricValues(facet: ComparisonFacet): (MetricValue | null)[] {
179+
// Compute values for each facet
180+
function getFacetValues(facet: ComparisonFacet): (FacetValue | null)[] {
181181
if (!packagesData.value || packagesData.value.length === 0) return []
182182

183183
return packagesData.value.map(pkg => {
184184
if (!pkg) return null
185-
return computeMetricValue(facet, pkg)
185+
return computeFacetValue(facet, pkg)
186186
})
187187
}
188188

@@ -197,7 +197,7 @@ export function usePackageComparison(packageNames: MaybeRefOrGetter<string[]>) {
197197
packagesData: readonly(packagesData),
198198
status: readonly(status),
199199
error: readonly(error),
200-
getMetricValues,
200+
getFacetValues,
201201
isFacetLoading,
202202
}
203203
}
@@ -209,10 +209,7 @@ function encodePackageName(name: string): string {
209209
return encodeURIComponent(name)
210210
}
211211

212-
function computeMetricValue(
213-
facet: ComparisonFacet,
214-
data: PackageComparisonData,
215-
): MetricValue | null {
212+
function computeFacetValue(facet: ComparisonFacet, data: PackageComparisonData): FacetValue | null {
216213
switch (facet) {
217214
case 'downloads':
218215
if (data.downloads === undefined) return null

app/pages/compare.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const { selectedFacets, selectAll, deselectAll, isAllSelected, isNoneSelected }
2929
useFacetSelection()
3030
3131
// Fetch comparison data
32-
const { packagesData, status, getMetricValues, isFacetLoading } = usePackageComparison(packages)
32+
const { packagesData, status, getFacetValues, isFacetLoading } = usePackageComparison(packages)
3333
3434
// Check if we have enough packages to compare
3535
const canCompare = computed(() => packages.value.length >= 2)
@@ -116,12 +116,12 @@ useSeoMeta({
116116

117117
<div v-else-if="packagesData && packagesData.length > 0">
118118
<CompareComparisonGrid :columns="packages.length" :headers="gridHeaders">
119-
<CompareMetricRow
119+
<CompareFacetRow
120120
v-for="facet in selectedFacets"
121121
:key="facet"
122122
:label="FACET_INFO[facet].label"
123123
:description="FACET_INFO[facet].description"
124-
:values="getMetricValues(facet)"
124+
:values="getFacetValues(facet)"
125125
:loading="isFacetLoading(facet)"
126126
:bar="facet !== 'lastUpdated'"
127127
/>

shared/types/comparison.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Comparison feature types
33
*/
44

5-
/** Available comparison facets/metrics */
5+
/** Available comparison facets */
66
export type ComparisonFacet =
77
| 'downloads'
88
| 'packageSize'
@@ -117,8 +117,8 @@ export const FACETS_BY_CATEGORY: Record<FacetInfo['category'], ComparisonFacet[]
117117
/** Default facets - all non-comingSoon facets */
118118
export const DEFAULT_FACETS: ComparisonFacet[] = ALL_FACETS.filter(f => !FACET_INFO[f].comingSoon)
119119

120-
/** Metric value that can be compared */
121-
export interface MetricValue<T = unknown> {
120+
/** Facet value that can be compared */
121+
export interface FacetValue<T = unknown> {
122122
/** Raw value for comparison logic */
123123
raw: T
124124
/** Formatted display string (or ISO date string if type is 'date') */
@@ -129,8 +129,8 @@ export interface MetricValue<T = unknown> {
129129
type?: 'date'
130130
}
131131

132-
/** Result of comparing two metric values */
133-
export interface DiffResult<_T = unknown> {
132+
/** Result of comparing two facet values */
133+
export interface FacetDiffResult<_T = unknown> {
134134
/** Absolute difference (for numeric values) */
135135
absoluteDiff?: number
136136
/** Percentage difference (for numeric values) */
@@ -139,7 +139,7 @@ export interface DiffResult<_T = unknown> {
139139
display: string
140140
/** Direction of change */
141141
direction: 'increase' | 'decrease' | 'same' | 'changed'
142-
/** Whether the change is favorable (depends on metric semantics) */
142+
/** Whether the change is favorable (depends on facet semantics) */
143143
favorable?: boolean
144144
}
145145

test/nuxt/components.spec.ts

Lines changed: 5 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,8 @@ import PackageDeprecatedTree from '~/components/PackageDeprecatedTree.vue'
9797
import DependencyPathPopup from '~/components/DependencyPathPopup.vue'
9898
import CompareFacetSelector from '~/components/compare/FacetSelector.vue'
9999
import ComparePackageSelector from '~/components/compare/PackageSelector.vue'
100-
import CompareMetricRow from '~/components/compare/MetricRow.vue'
100+
import CompareFacetRow from '~/components/compare/FacetRow.vue'
101101
import CompareComparisonGrid from '~/components/compare/ComparisonGrid.vue'
102-
import CompareVersionPicker from '~/components/compare/VersionPicker.vue'
103-
import CompareComingSoonPlaceholder from '~/components/compare/ComingSoonPlaceholder.vue'
104102

105103
describe('component accessibility audits', () => {
106104
describe('DateTime', () => {
@@ -1335,9 +1333,9 @@ describe('component accessibility audits', () => {
13351333
})
13361334
})
13371335

1338-
describe('CompareMetricRow', () => {
1336+
describe('CompareFacetRow', () => {
13391337
it('should have no accessibility violations with basic values', async () => {
1340-
const component = await mountSuspended(CompareMetricRow, {
1338+
const component = await mountSuspended(CompareFacetRow, {
13411339
props: {
13421340
label: 'Downloads',
13431341
description: 'Weekly download count',
@@ -1352,7 +1350,7 @@ describe('component accessibility audits', () => {
13521350
})
13531351

13541352
it('should have no accessibility violations with diffs', async () => {
1355-
const component = await mountSuspended(CompareMetricRow, {
1353+
const component = await mountSuspended(CompareFacetRow, {
13561354
props: {
13571355
label: 'Package Size',
13581356
description: 'Size of the package',
@@ -1368,7 +1366,7 @@ describe('component accessibility audits', () => {
13681366
})
13691367

13701368
it('should have no accessibility violations when loading', async () => {
1371-
const component = await mountSuspended(CompareMetricRow, {
1369+
const component = await mountSuspended(CompareFacetRow, {
13721370
props: {
13731371
label: 'Install Size',
13741372
description: 'Total install size',
@@ -1410,56 +1408,4 @@ describe('component accessibility audits', () => {
14101408
expect(results.violations).toEqual([])
14111409
})
14121410
})
1413-
1414-
describe('CompareVersionPicker', () => {
1415-
it('should have no accessibility violations', async () => {
1416-
const component = await mountSuspended(CompareVersionPicker, {
1417-
props: {
1418-
packageName: 'vue',
1419-
modelValue: '3.5.0',
1420-
label: 'From version',
1421-
},
1422-
})
1423-
const results = await runAxe(component)
1424-
expect(results.violations).toEqual([])
1425-
})
1426-
1427-
it('should have no accessibility violations with other version context', async () => {
1428-
const component = await mountSuspended(CompareVersionPicker, {
1429-
props: {
1430-
packageName: 'vue',
1431-
modelValue: '3.5.0',
1432-
label: 'From version',
1433-
otherVersion: '3.4.0',
1434-
},
1435-
})
1436-
const results = await runAxe(component)
1437-
expect(results.violations).toEqual([])
1438-
})
1439-
})
1440-
1441-
describe('CompareComingSoonPlaceholder', () => {
1442-
it('should have no accessibility violations', async () => {
1443-
const component = await mountSuspended(CompareComingSoonPlaceholder, {
1444-
props: {
1445-
title: 'File Diff',
1446-
description: 'Compare file changes between versions',
1447-
},
1448-
})
1449-
const results = await runAxe(component)
1450-
expect(results.violations).toEqual([])
1451-
})
1452-
1453-
it('should have no accessibility violations with icon', async () => {
1454-
const component = await mountSuspended(CompareComingSoonPlaceholder, {
1455-
props: {
1456-
title: 'Dependency Diff',
1457-
description: 'Compare dependency changes',
1458-
icon: 'i-carbon:flow',
1459-
},
1460-
})
1461-
const results = await runAxe(component)
1462-
expect(results.violations).toEqual([])
1463-
})
1464-
})
14651411
})

0 commit comments

Comments
 (0)