1
0

fix(filters): immediately emit filter query when editing saved filter

Resolves https://community.vikunja.io/t/filtering-unexpected-character-relative-dates/2544/12
This commit is contained in:
kolaente 2024-07-18 16:32:09 +02:00
parent 526bd1f170
commit a25834b089
No known key found for this signature in database
GPG Key ID: F40E70337AB24C9B
3 changed files with 33 additions and 13 deletions

View File

@ -19,8 +19,8 @@
v-model="value" v-model="value"
:has-title="true" :has-title="true"
class="filter-popup" class="filter-popup"
@update:modelValue="emitChanges" :change-immediately="false"
@showResults="() => modalOpen = false" @showResults="showResults"
/> />
</Modal> </Modal>
</template> </template>
@ -52,20 +52,21 @@ watch(
}, },
) )
function emitChanges(newValue: TaskFilterParams) {
emit('update:modelValue', {
...value.value,
filter: newValue.filter,
s: newValue.s,
})
}
const hasFilters = computed(() => { const hasFilters = computed(() => {
return value.value.filter !== '' || return value.value.filter !== '' ||
value.value.s !== '' value.value.s !== ''
}) })
const modalOpen = ref(false) const modalOpen = ref(false)
function showResults() {
emit('update:modelValue', {
...value.value,
filter: value.value.filter,
s: value.value.s,
})
modalOpen.value = false
}
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">

View File

@ -7,13 +7,14 @@
<FilterInput <FilterInput
v-model="filterQuery" v-model="filterQuery"
:project-id="projectId" :project-id="projectId"
@blur="change()" @update:modelValue="() => change('modelValue')"
@blur="() => change('blur')"
/> />
<div class="field is-flex is-flex-direction-column"> <div class="field is-flex is-flex-direction-column">
<FancyCheckbox <FancyCheckbox
v-model="params.filter_include_nulls" v-model="params.filter_include_nulls"
@blur="change()" @change="() => change('always')"
> >
{{ $t('filters.attributes.includeNulls') }} {{ $t('filters.attributes.includeNulls') }}
</FancyCheckbox> </FancyCheckbox>
@ -62,9 +63,11 @@ const props = withDefaults(defineProps<{
modelValue: TaskFilterParams, modelValue: TaskFilterParams,
hasTitle?: boolean, hasTitle?: boolean,
hasFooter?: boolean, hasFooter?: boolean,
changeImmediately?: boolean,
}>(), { }>(), {
hasTitle: false, hasTitle: false,
hasFooter: true, hasFooter: true,
changeImmediately: false,
}) })
const emit = defineEmits<{ const emit = defineEmits<{
@ -120,7 +123,22 @@ watch(
}, },
) )
function change() { function change(event: 'blur' | 'modelValue' | 'always') {
if (event !== 'always') {
// The filter edit setting needs to save immediately, but the filter query edit in project views should
// only change on blur, or it will show the filter replaced for api when the query is not yet complete.
// This is highly confusing UX, hence we want to avoid that.
// The approach taken here allows us to either toggle on blur or immediately, depending on the prop
// value provided. This probably is a hacky way to do this, but it is also the most effective.
if (props.changeImmediately && event === 'blur') {
return
}
if (!props.changeImmediately && event === 'modelValue') {
return
}
}
const filter = transformFilterStringForApi( const filter = transformFilterStringForApi(
filterQuery.value, filterQuery.value,
labelTitle => labelStore.getLabelByExactTitle(labelTitle)?.id || null, labelTitle => labelStore.getLabelByExactTitle(labelTitle)?.id || null,

View File

@ -60,6 +60,7 @@
:disabled="filterService.loading" :disabled="filterService.loading"
class="has-no-shadow has-no-border" class="has-no-shadow has-no-border"
:has-footer="false" :has-footer="false"
:change-immediately="true"
/> />
</div> </div>
</div> </div>