Skip to content

Commit 5b877ba

Browse files
committed
chore: clean up hard-coded labels
1 parent 85b4edd commit 5b877ba

3 files changed

Lines changed: 96 additions & 145 deletions

File tree

app/components/Filter/Panel.vue

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import type {
88
} from '#shared/types/preferences'
99
import {
1010
DOWNLOAD_RANGES,
11-
SEARCH_SCOPE_OPTIONS,
12-
SECURITY_FILTER_OPTIONS,
11+
SEARCH_SCOPE_VALUES,
12+
SECURITY_FILTER_VALUES,
1313
UPDATED_WITHIN_OPTIONS,
1414
} from '#shared/types/preferences'
1515
@@ -205,20 +205,20 @@ const hasActiveFilters = computed(() => !!filterSummary.value)
205205
:aria-label="$t('filters.search_scope')"
206206
>
207207
<button
208-
v-for="option in SEARCH_SCOPE_OPTIONS"
209-
:key="option.value"
208+
v-for="scope in SEARCH_SCOPE_VALUES"
209+
:key="scope"
210210
type="button"
211211
class="px-2 py-0.5 text-xs font-mono rounded-sm transition-colors duration-200 focus-visible:ring-2 focus-visible:ring-fg focus-visible:ring-offset-1"
212212
:class="
213-
filters.searchScope === option.value
213+
filters.searchScope === scope
214214
? 'bg-bg-muted text-fg'
215215
: 'text-fg-muted hover:text-fg'
216216
"
217-
:aria-pressed="filters.searchScope === option.value"
218-
:title="$t(getScopeDescriptionKey(option.value))"
219-
@click="emit('update:searchScope', option.value)"
217+
:aria-pressed="filters.searchScope === scope"
218+
:title="$t(getScopeDescriptionKey(scope))"
219+
@click="emit('update:searchScope', scope)"
220220
>
221-
{{ $t(getScopeLabelKey(option.value)) }}
221+
{{ $t(getScopeLabelKey(scope)) }}
222222
</button>
223223
</div>
224224
</div>
@@ -301,18 +301,18 @@ const hasActiveFilters = computed(() => !!filterSummary.value)
301301
</legend>
302302
<div class="flex flex-wrap gap-2" role="radiogroup" :aria-label="$t('filters.security')">
303303
<button
304-
v-for="option in SECURITY_FILTER_OPTIONS"
305-
:key="option.value"
304+
v-for="security in SECURITY_FILTER_VALUES"
305+
:key="security"
306306
type="button"
307307
role="radio"
308308
disabled
309-
:aria-checked="filters.security === option.value"
309+
:aria-checked="filters.security === security"
310310
class="tag transition-colors duration-200 opacity-50 cursor-not-allowed focus-visible:ring-2 focus-visible:ring-fg focus-visible:ring-offset-1"
311311
:class="
312-
filters.security === option.value ? 'bg-fg text-bg border-fg hover:text-bg/70' : ''
312+
filters.security === security ? 'bg-fg text-bg border-fg hover:text-bg/70' : ''
313313
"
314314
>
315-
{{ $t(getSecurityLabelKey(option.value)) }}
315+
{{ $t(getSecurityLabelKey(security)) }}
316316
</button>
317317
</div>
318318
</fieldset>

shared/types/preferences.ts

Lines changed: 36 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ export type ColumnId =
2323

2424
export interface ColumnConfig {
2525
id: ColumnId
26-
label: string
2726
visible: boolean
2827
sortable: boolean
2928
width?: string
@@ -33,54 +32,48 @@ export interface ColumnConfig {
3332

3433
// Default column configuration
3534
export const DEFAULT_COLUMNS: ColumnConfig[] = [
36-
{ id: 'name', label: 'Name', visible: true, sortable: true, width: 'minmax(200px, 1fr)' },
37-
{ id: 'version', label: 'Version', visible: true, sortable: false, width: '100px' },
35+
{ id: 'name', visible: true, sortable: true, width: 'minmax(200px, 1fr)' },
36+
{ id: 'version', visible: true, sortable: false, width: '100px' },
3837
{
3938
id: 'description',
40-
label: 'Description',
4139
visible: true,
4240
sortable: false,
4341
width: 'minmax(200px, 2fr)',
4442
},
45-
{ id: 'downloads', label: 'Downloads/wk', visible: true, sortable: true, width: '120px' },
46-
{ id: 'updated', label: 'Updated', visible: true, sortable: true, width: '120px' },
47-
{ id: 'maintainers', label: 'Maintainers', visible: false, sortable: false, width: '150px' },
48-
{ id: 'keywords', label: 'Keywords', visible: false, sortable: false, width: '200px' },
43+
{ id: 'downloads', visible: true, sortable: true, width: '120px' },
44+
{ id: 'updated', visible: true, sortable: true, width: '120px' },
45+
{ id: 'maintainers', visible: false, sortable: false, width: '150px' },
46+
{ id: 'keywords', visible: false, sortable: false, width: '200px' },
4947
{
5048
id: 'qualityScore',
51-
label: 'Quality score',
5249
visible: false,
5350
sortable: true,
5451
width: '100px',
5552
disabled: true,
5653
},
5754
{
5855
id: 'popularityScore',
59-
label: 'Popularity score',
6056
visible: false,
6157
sortable: true,
6258
width: '100px',
6359
disabled: true,
6460
},
6561
{
6662
id: 'maintenanceScore',
67-
label: 'Maintenance score',
6863
visible: false,
6964
sortable: true,
7065
width: '100px',
7166
disabled: true,
7267
},
7368
{
7469
id: 'combinedScore',
75-
label: 'Combined score',
7670
visible: false,
7771
sortable: true,
7872
width: '100px',
7973
disabled: true,
8074
},
8175
{
8276
id: 'security',
83-
label: 'Security',
8477
visible: false,
8578
sortable: false,
8679
width: '80px',
@@ -131,7 +124,6 @@ export type SortOption =
131124

132125
export interface SortKeyConfig {
133126
key: SortKey
134-
label: string
135127
/** Default direction for this sort key */
136128
defaultDirection: SortDirection
137129
/** Whether the sort option is disabled (not yet available) */
@@ -141,52 +133,17 @@ export interface SortKeyConfig {
141133
}
142134

143135
export const SORT_KEYS: SortKeyConfig[] = [
144-
{ key: 'relevance', label: 'Relevance', defaultDirection: 'desc', searchOnly: true },
145-
{ key: 'downloads-week', label: 'Downloads/wk', defaultDirection: 'desc' },
146-
{
147-
key: 'downloads-day',
148-
label: 'Downloads/day',
149-
defaultDirection: 'desc',
150-
disabled: true,
151-
},
152-
{
153-
key: 'downloads-month',
154-
label: 'Downloads/mo',
155-
defaultDirection: 'desc',
156-
disabled: true,
157-
},
158-
{
159-
key: 'downloads-year',
160-
label: 'Downloads/yr',
161-
defaultDirection: 'desc',
162-
disabled: true,
163-
},
164-
{ key: 'updated', label: 'Updated', defaultDirection: 'desc' },
165-
{ key: 'name', label: 'Name', defaultDirection: 'asc' },
166-
{
167-
key: 'quality',
168-
label: 'Quality',
169-
defaultDirection: 'desc',
170-
disabled: true,
171-
},
172-
{
173-
key: 'popularity',
174-
label: 'Popularity',
175-
defaultDirection: 'desc',
176-
disabled: true,
177-
},
178-
{
179-
key: 'maintenance',
180-
label: 'Maintenance',
181-
defaultDirection: 'desc',
182-
disabled: true,
183-
},
184-
{
185-
key: 'score',
186-
label: 'Score',
187-
defaultDirection: 'desc',
188-
disabled: true,
189-
},
136+
{ key: 'relevance', defaultDirection: 'desc', searchOnly: true },
137+
{ key: 'downloads-week', defaultDirection: 'desc' },
138+
{ key: 'downloads-day', defaultDirection: 'desc', disabled: true },
139+
{ key: 'downloads-month', defaultDirection: 'desc', disabled: true },
140+
{ key: 'downloads-year', defaultDirection: 'desc', disabled: true },
141+
{ key: 'updated', defaultDirection: 'desc' },
142+
{ key: 'name', defaultDirection: 'asc' },
143+
{ key: 'quality', defaultDirection: 'desc', disabled: true },
144+
{ key: 'popularity', defaultDirection: 'desc', disabled: true },
145+
{ key: 'maintenance', defaultDirection: 'desc', disabled: true },
146+
{ key: 'score', defaultDirection: 'desc', disabled: true },
190147
]
191148

192149
/** All valid sort keys for validation */
@@ -205,7 +162,10 @@ const VALID_SORT_KEYS = new Set<SortKey>([
205162
])
206163

207164
/** Parse a SortOption into key and direction */
208-
export function parseSortOption(option: SortOption): { key: SortKey; direction: SortDirection } {
165+
export function parseSortOption(option: SortOption): {
166+
key: SortKey
167+
direction: SortDirection
168+
} {
209169
const match = option.match(/^(.+)-(asc|desc)$/)
210170
if (match) {
211171
const key = match[1]
@@ -234,66 +194,46 @@ export type DownloadRange = 'any' | 'lt100' | '100-1k' | '1k-10k' | '10k-100k' |
234194

235195
export interface DownloadRangeConfig {
236196
value: DownloadRange
237-
label: string
238197
min?: number
239198
max?: number
240199
}
241200

242201
export const DOWNLOAD_RANGES: DownloadRangeConfig[] = [
243-
{ value: 'any', label: 'Any' },
244-
{ value: 'lt100', label: '< 100', max: 100 },
245-
{ value: '100-1k', label: '100 - 1K', min: 100, max: 1000 },
246-
{ value: '1k-10k', label: '1K - 10K', min: 1000, max: 10000 },
247-
{ value: '10k-100k', label: '10K - 100K', min: 10000, max: 100000 },
248-
{ value: 'gt100k', label: '> 100K', min: 100000 },
202+
{ value: 'any' },
203+
{ value: 'lt100', max: 100 },
204+
{ value: '100-1k', min: 100, max: 1000 },
205+
{ value: '1k-10k', min: 1000, max: 10000 },
206+
{ value: '10k-100k', min: 10000, max: 100000 },
207+
{ value: 'gt100k', min: 100000 },
249208
]
250209

251210
// Updated within presets
252211
export type UpdatedWithin = 'any' | 'week' | 'month' | 'quarter' | 'year'
253212

254213
export interface UpdatedWithinConfig {
255214
value: UpdatedWithin
256-
label: string
257215
days?: number
258216
}
259217

260218
export const UPDATED_WITHIN_OPTIONS: UpdatedWithinConfig[] = [
261-
{ value: 'any', label: 'Any time' },
262-
{ value: 'week', label: 'Past week', days: 7 },
263-
{ value: 'month', label: 'Past month', days: 30 },
264-
{ value: 'quarter', label: 'Past 3 months', days: 90 },
265-
{ value: 'year', label: 'Past year', days: 365 },
219+
{ value: 'any' },
220+
{ value: 'week', days: 7 },
221+
{ value: 'month', days: 30 },
222+
{ value: 'quarter', days: 90 },
223+
{ value: 'year', days: 365 },
266224
]
267225

268226
// Security filter options
269227
export type SecurityFilter = 'all' | 'secure' | 'warnings'
270228

271-
export interface SecurityFilterConfig {
272-
value: SecurityFilter
273-
label: string
274-
}
275-
276-
export const SECURITY_FILTER_OPTIONS: SecurityFilterConfig[] = [
277-
{ value: 'all', label: 'All packages' },
278-
{ value: 'secure', label: 'Secure only' },
279-
{ value: 'warnings', label: 'Insecure only' },
280-
]
229+
/** Security filter values - labels are in i18n under filters.security_options */
230+
export const SECURITY_FILTER_VALUES: SecurityFilter[] = ['all', 'secure', 'warnings']
281231

282232
// Search scope options
283233
export type SearchScope = 'name' | 'description' | 'keywords' | 'all'
284234

285-
export interface SearchScopeConfig {
286-
value: SearchScope
287-
label: string
288-
description: string
289-
}
290-
291-
export const SEARCH_SCOPE_OPTIONS: SearchScopeConfig[] = [
292-
{ value: 'name', label: 'Name', description: 'Search package names only' },
293-
{ value: 'description', label: 'Description', description: 'Search descriptions only' },
294-
{ value: 'keywords', label: 'Keywords', description: 'Search keywords only' },
295-
{ value: 'all', label: 'All', description: 'Search name, description, and keywords' },
296-
]
235+
/** Search scope values - labels are in i18n under filters.scope_* */
236+
export const SEARCH_SCOPE_VALUES: SearchScope[] = ['name', 'description', 'keywords', 'all']
297237

298238
// Structured filters state
299239
export interface StructuredFilters {

0 commit comments

Comments
 (0)