From 130ce966616d5291c73f75fdd85cc4cf8ba31b25 Mon Sep 17 00:00:00 2001 From: John Obelenus Date: Thu, 12 Dec 2024 14:51:54 -0500 Subject: [PATCH] BUG-698: re-process children when a component updates, fixes when parentage changes --- app/web/src/store/components.store.ts | 42 ++++++++++++++++++--------- app/web/src/store/views.store.ts | 7 +++-- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/app/web/src/store/components.store.ts b/app/web/src/store/components.store.ts index c9544e3565..177494c125 100644 --- a/app/web/src/store/components.store.ts +++ b/app/web/src/store/components.store.ts @@ -626,7 +626,10 @@ export const useComponentsStore = (forceChangeSetId?: ChangeSetId) => { }, processAndStoreRawComponent( componentId: ComponentId, - processAncestors = true, + { + processAncestors = true, + processChildren = true, + }: { processAncestors?: boolean; processChildren?: boolean }, ): void { const component = this.rawComponentsById[componentId]; if (!component) return; @@ -649,12 +652,23 @@ export const useComponentsStore = (forceChangeSetId?: ChangeSetId) => { // is false when iterating over the whole data set... no need to duplicate work if (processAncestors) { if (component.parentId) { - this.processAndStoreRawComponent( - component.parentId, + this.processAndStoreRawComponent(component.parentId, { processAncestors, - ); + processChildren: false, + }); } } + if (processChildren) { + const children = Object.values(this.allComponentsById).filter( + (c) => c.def.parentId === component.id, + ); + children.forEach((child) => { + this.processAndStoreRawComponent(child.def.id, { + processAncestors: false, + processChildren: true, + }); + }); + } }, async SET_RESOURCE_ID(componentId: ComponentId, resourceId: string) { @@ -718,7 +732,9 @@ export const useComponentsStore = (forceChangeSetId?: ChangeSetId) => { // this.nodesById = {}; // this.groupsById = {}; response.components.forEach((component) => { - this.processAndStoreRawComponent(component.id, false); + this.processAndStoreRawComponent(component.id, { + processAncestors: false, + }); }); const edges = @@ -1072,7 +1088,7 @@ export const useComponentsStore = (forceChangeSetId?: ChangeSetId) => { }, }; - this.processAndStoreRawComponent(componentId); + this.processAndStoreRawComponent(componentId, {}); } } @@ -1090,7 +1106,7 @@ export const useComponentsStore = (forceChangeSetId?: ChangeSetId) => { deletedInfo: undefined, }; - this.processAndStoreRawComponent(componentId); + this.processAndStoreRawComponent(componentId, {}); } } }; @@ -1122,7 +1138,7 @@ export const useComponentsStore = (forceChangeSetId?: ChangeSetId) => { toDelete: false, deletedInfo: undefined, }; - this.processAndStoreRawComponent(componentId); + this.processAndStoreRawComponent(componentId, {}); } } }, @@ -1171,7 +1187,7 @@ export const useComponentsStore = (forceChangeSetId?: ChangeSetId) => { // don't update if (data.changeSetId !== changeSetId) return; this.rawComponentsById[data.component.id] = data.component; - this.processAndStoreRawComponent(data.component.id); + this.processAndStoreRawComponent(data.component.id, {}); }, }, { @@ -1250,9 +1266,9 @@ export const useComponentsStore = (forceChangeSetId?: ChangeSetId) => { this.rawComponentsById[componentId]?.parentId; this.rawComponentsById[componentId] = data.component; - this.processAndStoreRawComponent(componentId); + this.processAndStoreRawComponent(componentId, {}); if (oldParent && !data.component.parentId) - this.processAndStoreRawComponent(oldParent); + this.processAndStoreRawComponent(oldParent, {}); }, }, { @@ -1295,7 +1311,7 @@ export const useComponentsStore = (forceChangeSetId?: ChangeSetId) => { delete this.nodesById[data.originalComponentId]; delete this.groupsById[data.originalComponentId]; this.rawComponentsById[data.component.id] = data.component; - this.processAndStoreRawComponent(data.component.id); + this.processAndStoreRawComponent(data.component.id, {}); }, }, { @@ -1305,7 +1321,7 @@ export const useComponentsStore = (forceChangeSetId?: ChangeSetId) => { // don't update if (data.changeSetId !== changeSetId) return; this.rawComponentsById[data.component.id] = data.component; - this.processAndStoreRawComponent(data.component.id); + this.processAndStoreRawComponent(data.component.id, {}); this.refreshingStatus[data.component.id] = false; }, }, diff --git a/app/web/src/store/views.store.ts b/app/web/src/store/views.store.ts index c5e053cd86..7554cf7882 100644 --- a/app/web/src/store/views.store.ts +++ b/app/web/src/store/views.store.ts @@ -1226,13 +1226,13 @@ export const useViewsStore = (forceChangeSetId?: ChangeSetId) => { else { component.parentId = undefined; } - componentsStore.processAndStoreRawComponent(componentId); + componentsStore.processAndStoreRawComponent(componentId, {}); }); // if we change to no parent, we have to follow up and re-process Object.values(oldParentIds) .filter(nonNullable) .forEach((parentId) => { - componentsStore.processAndStoreRawComponent(parentId); + componentsStore.processAndStoreRawComponent(parentId, {}); }); }, onFail: () => { @@ -1241,10 +1241,11 @@ export const useViewsStore = (forceChangeSetId?: ChangeSetId) => { componentsStore.rawComponentsById[componentId]; if (!component) return; component.parentId = oldParentIds[componentId]; - componentsStore.processAndStoreRawComponent(componentId); + componentsStore.processAndStoreRawComponent(componentId, {}); if (component.parentId) componentsStore.processAndStoreRawComponent( component.parentId, + {}, ); }); },