Frontend entities should have a reference to allEntities.

There are probably more optimal ways of achieving this other than
passing a reference to the full list of entities to each of the
entities, such as running a BFS to recursively expand all the entities
within the child hierarchy of an entity.

This is needed because the entity needs to know which entities aren't
direct children, but are two or more layers down in the hierarchy, so
they should be passed to their own child entities.
This commit is contained in:
Fabio Manganiello 2023-04-17 02:11:13 +02:00
parent 6e65783feb
commit 4842c1911b
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774
3 changed files with 21 additions and 1 deletions

View file

@ -24,11 +24,12 @@
</div> </div>
</div> </div>
<div class="children fade-in" v-if="!isCollapsed"> <div class="children fade-in" v-if="hasChildren && !isCollapsed">
<div class="child" v-for="entity in computedChildren" :key="entity.id"> <div class="child" v-for="entity in computedChildren" :key="entity.id">
<Entity <Entity
:value="entity" :value="entity"
:parent="value" :parent="value"
:children="childrenByParentId(entity.id)"
:loading="loading" :loading="loading"
:level="level + 1" :level="level + 1"
@show-modal="$emit('show-modal', $event)" @show-modal="$emit('show-modal', $event)"
@ -88,6 +89,19 @@ export default {
return this.objectsEqual(a, b) return this.objectsEqual(a, b)
}, },
childrenByParentId(parentId) {
return Object.values(this.allEntities || {}).
filter(
(entity) => entity
&& entity.parent_id === parentId
&& !entity.is_configuration
).
reduce((obj, entity) => {
obj[entity.id] = entity
return obj
}, {})
},
onClick(event) { onClick(event) {
event.stopPropagation() event.stopPropagation()

View file

@ -31,6 +31,11 @@ export default {
default: () => {}, default: () => {},
}, },
allEntities: {
type: Object,
default: () => {},
},
level: { level: {
type: Number, type: Number,
default: 0, default: 0,

View file

@ -57,6 +57,7 @@
<Entity <Entity
:value="entity" :value="entity"
:children="childrenByParentId(entity.id)" :children="childrenByParentId(entity.id)"
:all-entities="entities"
@show-modal="onEntityModal($event)" @show-modal="onEntityModal($event)"
@input="onEntityInput(entity)" @input="onEntityInput(entity)"
:error="!!errorEntities[entity.id]" :error="!!errorEntities[entity.id]"