fix(filter): don't prevent entering date math strings
continuous-integration/drone/push Build is passing Details

Resolves https://community.vikunja.io/t/filter-setting-s/1791/2
This commit is contained in:
kolaente 2023-11-17 19:38:55 +01:00
parent 7f279c98e1
commit aa5e11915e
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 10 additions and 5 deletions

View File

@ -75,6 +75,7 @@ import {useI18n} from 'vue-i18n'
import flatPickr from 'vue-flatpickr-component'
import 'flatpickr/dist/flatpickr.css'
import {parseDateOrString} from '@/helpers/time/parseDateOrString'
import Popup from '@/components/misc/popup.vue'
import {DATE_RANGES} from '@/components/date/dateRanges'
@ -120,9 +121,9 @@ watch(
to.value = newValue.dateTo
// Only set the date back to flatpickr when it's an actual date.
// Otherwise flatpickr runs in an endless loop and slows down the browser.
const dateFrom = new Date(from.value)
const dateTo = new Date(to.value)
if (dateTo.getTime() === dateTo.getTime() && dateFrom.getTime() === dateFrom.getTime()) {
const dateFrom = parseDateOrString(from.value, false)
const dateTo = parseDateOrString(to.value, false)
if (dateFrom instanceof Date && dateTo instanceof Date) {
flatpickrRange.value = `${from.value} to ${to.value}`
}
},

View File

@ -1,8 +1,12 @@
export function parseDateOrString(rawValue: string | undefined, fallback: unknown) {
if (typeof rawValue === 'undefined') {
export function parseDateOrString(rawValue: string | undefined | null, fallback: unknown): (unknown | string | Date) {
if (rawValue === null || typeof rawValue === 'undefined') {
return fallback
}
if (rawValue.toLowerCase().includes('now') || rawValue.toLowerCase().includes('||')) {
return rawValue
}
const d = new Date(rawValue)
return !isNaN(+d)