Skip to content

Commit 792cb82

Browse files
committed
fix(search-route): Improve handling of year filters
1 parent 7b8db1b commit 792cb82

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

src/app/routes/search/search-route.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,24 @@ export const SearchRoute = () => {
143143
})
144144
}}
145145
tagConfigs={{
146-
category: { validate: Boolean },
146+
category: {},
147147
until: {
148-
validate: dateHelpers.isValid,
149-
format: value => dateHelpers.stringify(dateHelpers.parse(value)),
148+
validate: value => value.length < 4 || dateHelpers.isValid(value),
149+
format: value => {
150+
if (value.length < 4) return ""
151+
const isYear = /^\d{4}$/.test(value)
152+
const date = dateHelpers.parse(isYear ? `${value}-12-31` : value)
153+
return dateHelpers.stringify(date)
154+
},
150155
},
151156
from: {
152-
validate: dateHelpers.isValid,
153-
format: value => dateHelpers.stringify(dateHelpers.parse(value)),
157+
validate: value => value.length < 4 || dateHelpers.isValid(value),
158+
format: value => {
159+
if (value.length < 4) return ""
160+
const isYear = /^\d{4}$/.test(value)
161+
const date = dateHelpers.parse(isYear ? `${value}-01-01` : value)
162+
return dateHelpers.stringify(date)
163+
},
154164
},
155165
}}
156166
/>

src/components/ui/filter-input/parse-filter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export interface TagConfig {
2-
validate: (value: string) => boolean
2+
validate?: (value: string) => boolean
33
format?: (value: string) => string
44
}
55

@@ -136,7 +136,7 @@ const enrichItems = (
136136
value,
137137
text,
138138
isTagValid: !!config || tag == null,
139-
isValueValid: config?.validate(value) ?? (!!value || tag == null),
139+
isValueValid: config?.validate?.(value) ?? true,
140140
}
141141
})
142142

0 commit comments

Comments
 (0)