1
0
Fork 0

fix: use autocomplete for grid filter verb choices

This commit is contained in:
Lance Edgar 2024-08-23 14:38:02 -05:00
parent e332975ce9
commit bf2ca4b475
2 changed files with 88 additions and 12 deletions

View file

@ -164,12 +164,9 @@
gap: 0.5rem; gap: 0.5rem;
} }
.wutta-filter .button.filter-toggle {
justify-content: left;
}
.wutta-filter .button.filter-toggle, .wutta-filter .button.filter-toggle,
.wutta-filter .filter-verb { .wutta-filter .filter-verb {
justify-content: left;
min-width: 15rem; min-width: 15rem;
} }

View file

@ -88,16 +88,26 @@
<div v-show="filter.active" <div v-show="filter.active"
style="display: flex; gap: 0.5rem;"> style="display: flex; gap: 0.5rem;">
<b-select v-model="filter.verb" <b-button v-if="verbKnown"
class="filter-verb" class="filter-verb"
@input="focusValue()" @click="verbChoiceInit()"
:size="isSmall ? 'is-small' : null"> :size="isSmall ? 'is-small' : null">
<option v-for="verb in filter.verbs" {{ verbLabel }}
:key="verb" </b-button>
:value="verb">
{{ filter.verb_labels[verb] || verb }} <b-autocomplete v-if="!verbKnown"
</option> ref="verbAutocomplete"
</b-select> :data="verbOptions"
v-model="verbTerm"
field="verb"
:custom-formatter="formatVerb"
open-on-focus
keep-first
clearable
clear-on-select
@select="verbChoiceSelect"
icon-pack="fas"
:size="isSmall ? 'is-small' : null" />
<wutta-filter-value v-model="filter.value" <wutta-filter-value v-model="filter.value"
ref="filterValue" ref="filterValue"
@ -116,12 +126,81 @@
isSmall: Boolean, isSmall: Boolean,
}, },
data() {
return {
verbKnown: !!this.filter.verb,
verbLabel: this.filter.verb_labels[this.filter.verb],
verbTerm: '',
}
},
computed: {
verbOptions() {
// construct list of options
const options = []
for (let verb of this.filter.verbs) {
options.push({
verb,
label: this.filter.verb_labels[verb],
})
}
// parse list of search terms
const terms = []
for (let term of this.verbTerm.toLowerCase().split(' ')) {
term = term.trim()
if (term) {
terms.push(term)
}
}
// show all if no search terms
if (!terms.length) {
return options
}
// only show filters matching all search terms
return options.filter(option => {
let label = option.label.toLowerCase()
for (let term of terms) {
if (label.indexOf(term) < 0) {
return false
}
}
return true
})
return options
},
},
methods: { methods: {
focusValue() { focusValue() {
this.$refs.filterValue.focus() this.$refs.filterValue.focus()
}, },
formatVerb(option) {
return option.label || option.verb
},
verbChoiceInit(option) {
this.verbKnown = false
this.$nextTick(() => {
this.$refs.verbAutocomplete.focus()
})
},
verbChoiceSelect(option) {
this.filter.verb = option.verb
this.verbLabel = option.label
this.verbKnown = true
this.verbTerm = ''
this.focusValue()
},
valuedVerb() { valuedVerb() {
/* return true if the current verb should expose value input(s) */ /* return true if the current verb should expose value input(s) */