From 241670c9d0c63da99ab2229479d8c6f0b018adb6 Mon Sep 17 00:00:00 2001
From: Fabio Manganiello <fabio@manganiello.tech>
Date: Sat, 21 Jan 2023 16:58:28 +0100
Subject: [PATCH] Handle parent/child update events through broadcast bus
 events

---
 .../src/components/panels/Entities/Entity.vue     | 15 +++++++++++++--
 .../src/components/panels/Entities/Index.vue      |  6 ++++++
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/platypush/backend/http/webapp/src/components/panels/Entities/Entity.vue b/platypush/backend/http/webapp/src/components/panels/Entities/Entity.vue
index 0bc56626..1307ef49 100644
--- a/platypush/backend/http/webapp/src/components/panels/Entities/Entity.vue
+++ b/platypush/backend/http/webapp/src/components/panels/Entities/Entity.vue
@@ -28,7 +28,6 @@
          :value="entity"
          :loading="loading"
          :level="level + 1"
-         @update="setJustUpdated"
          @input="$emit('input', entity)" />
       </div>
     </div>
@@ -38,11 +37,12 @@
 <script>
 import { defineAsyncComponent, shallowRef } from 'vue'
 import EntityMixin from "./EntityMixin"
+import { bus } from "@/bus";
 
 export default {
   name: "Entity",
   mixins: [EntityMixin],
-  emits: ['input', 'loading'],
+  emits: ['input', 'loading', 'update'],
 
   data() {
     return {
@@ -91,6 +91,15 @@ export default {
       }
     },
 
+    onEntityUpdate(entity) {
+      // Check if any of the children have been updated
+      const entityId = entity?.id
+      if (entityId == null || !(entityId in this.children))
+        return
+
+      this.setJustUpdated()
+    },
+
     toggleCollapsed() {
       this.collapsed = !this.collapsed
       // Propagate the collapsed state to the wrapped component if applicable
@@ -128,6 +137,8 @@ export default {
         )
       )
     }
+
+    bus.onEntity(this.onEntityUpdate)
   },
 }
 </script>
diff --git a/platypush/backend/http/webapp/src/components/panels/Entities/Index.vue b/platypush/backend/http/webapp/src/components/panels/Entities/Index.vue
index c1fa989f..a4fef403 100644
--- a/platypush/backend/http/webapp/src/components/panels/Entities/Index.vue
+++ b/platypush/backend/http/webapp/src/components/panels/Entities/Index.vue
@@ -76,6 +76,7 @@ import NoItems from "@/components/elements/NoItems";
 import Entity from "./Entity.vue";
 import Selector from "./Selector.vue";
 import EntityModal from "./Modal"
+import { bus } from "@/bus";
 import icons from '@/assets/icons.json'
 import meta from './meta.json'
 
@@ -320,6 +321,7 @@ export default {
       }
 
       this.entities[entityId] = entity
+      bus.publishEntity(entity)
     },
 
     onEntityDelete(event) {
@@ -359,6 +361,10 @@ export default {
     await this.sync()
     await this.refresh()
   },
+
+  unmounted() {
+    this.unsubscribe('on-entity-update')
+  },
 }
 </script>