A more efficient way of detecting the entity groups to display.

Instead of iterating over each of the entities in a grouping to find out
which groups should be displayed based on the selector's policy, the
selector can directly keep its `selectedGroups` attribute in sync with
the index.
This commit is contained in:
Fabio Manganiello 2023-05-05 02:33:34 +02:00
parent 373788377b
commit 8af3ae17b8
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774
2 changed files with 13 additions and 21 deletions

View file

@ -127,6 +127,7 @@ export default {
selector: {
grouping: 'plugin',
selectedEntities: {},
selectedGroups: {},
},
}
},
@ -148,14 +149,9 @@ export default {
},
displayGroups() {
return Object.entries(this.entityGroups[this.selector.grouping]).
filter(
(entry) => Object.values(entry[1]).filter(
(e) =>
!!this.selector.selectedEntities[e.id] && e.parent_id == null
).length > 0
).
map(
return Object.entries(this.entityGroups[this.selector.grouping])
.filter((entry) => this.selector.selectedGroups[entry[0]])
.map(
([grouping, entities]) => {
return {
name: grouping,
@ -164,8 +160,9 @@ export default {
),
}
}
).
sort((a, b) => a.name.localeCompare(b.name))
)
.filter((group) => group.entities?.length > 0)
.sort((a, b) => a.name.localeCompare(b.name))
},
},

View file

@ -143,16 +143,11 @@ export default {
return {}
},
synchronizeSelectedEntities() {
const value = {...this.value}
value.selectedEntities = this.selectedEntities
this.$emit('input', value)
},
updateSearchTerm() {
sync() {
const value = {...this.value}
value.searchTerm = this.searchTerm
value.selectedEntities = this.selectedEntities
value.selectedGroups = this.selectedGroups
this.$emit('input', value)
},
@ -166,17 +161,17 @@ export default {
}, {}
)
this.synchronizeSelectedEntities()
this.sync()
},
toggleGroup(group) {
this.selectedGroups[group] = !this.selectedGroups[group]
this.synchronizeSelectedEntities()
this.sync()
},
processEntityUpdate(entity) {
const group = entity[this.value?.grouping]
if (group && this.selectedGroups[entity[group]] == null) {
if (group && this.selectedGroups[group] == null) {
this.selectedGroups[group] = true
}
},
@ -194,7 +189,7 @@ export default {
mounted() {
this.refreshGroupFilter()
this.$watch(() => this.value?.grouping, () => { this.refreshGroupFilter() })
this.$watch(() => this.searchTerm, this.updateSearchTerm)
this.$watch(() => this.searchTerm, this.sync)
bus.onEntity(this.processEntityUpdate)
},
}