Skip to content

Commit

Permalink
refine unit autocomplete
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Herwege <mark.herwege@telenet.be>
  • Loading branch information
mherwege committed Feb 16, 2024
1 parent c9cd107 commit 795816c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
14 changes: 8 additions & 6 deletions bundles/org.openhab.ui/web/src/components/item/group-form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ export default {
data () {
return {
types,
unitAutocomplete: null,
unitInitialized: !this.createMode
unitAutocomplete: null
}
},
computed: {
Expand Down Expand Up @@ -189,13 +188,16 @@ export default {
openIn: 'dropdown',
typeahead: true,
source (query, render) {
if (!query || !query.length || !this.unitInitialized) {
if (!query || !query.length) {
// Render curated list by default
render(curatedUnits)
this.unitInitialized = true
} else {
// Always show currated units on top (don't filter them)
let units = [...new Set(curatedUnits.concat(allUnits.filter(u => u.indexOf(query) >= 0)))]
// First filter on curated list
let units = curatedUnits.filter(u => u.indexOf(query) >= 0)
if (!units.length) {
// If no match filter on full list
units = allUnits.filter(u => u.indexOf(query) >= 0)
}
render(units)
}
}
Expand Down
12 changes: 7 additions & 5 deletions bundles/org.openhab.ui/web/src/components/item/item-form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ export default {
return {
types,
unitAutocomplete: null,
unitInitialized: !this.createMode,
categoryInputId: '',
categoryAutocomplete: null,
nameErrorMessage: ''
Expand Down Expand Up @@ -178,13 +177,16 @@ export default {
typeahead: true,
dropdownPlaceHolderText: this.getUnitHint(dimension.name),
source (query, render) {
if (!query || !query.length || !this.unitInitialized) {
if (!query || !query.length) {
// Render curated list by default
render(curatedUnits)
this.unitInitialized = true
} else {
// Always show currated units on top (don't filter them)
let units = [...new Set(curatedUnits.concat(allUnits.filter(u => u.indexOf(query) >= 0)))]
// First filter on curated list
let units = curatedUnits.filter(u => u.indexOf(query) >= 0)
if (!units.length) {
// If no match filter on full list
units = allUnits.filter(u => u.indexOf(query) >= 0)
}
render(units)
}
}
Expand Down

0 comments on commit 795816c

Please sign in to comment.