Skip to content

Commit

Permalink
Merge pull request #5118 from systeminit/fix/BUG-698-re-process-child…
Browse files Browse the repository at this point in the history
…ren-when-a-parent-changes

BUG-698: re-process children when a component updates, fixes when parentage changes
  • Loading branch information
jobelenus authored Dec 12, 2024
2 parents a2a1e18 + 130ce96 commit 44dc9cc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
42 changes: 29 additions & 13 deletions app/web/src/store/components.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -1072,7 +1088,7 @@ export const useComponentsStore = (forceChangeSetId?: ChangeSetId) => {
},
};

this.processAndStoreRawComponent(componentId);
this.processAndStoreRawComponent(componentId, {});
}
}

Expand All @@ -1090,7 +1106,7 @@ export const useComponentsStore = (forceChangeSetId?: ChangeSetId) => {
deletedInfo: undefined,
};

this.processAndStoreRawComponent(componentId);
this.processAndStoreRawComponent(componentId, {});
}
}
};
Expand Down Expand Up @@ -1122,7 +1138,7 @@ export const useComponentsStore = (forceChangeSetId?: ChangeSetId) => {
toDelete: false,
deletedInfo: undefined,
};
this.processAndStoreRawComponent(componentId);
this.processAndStoreRawComponent(componentId, {});
}
}
},
Expand Down Expand Up @@ -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, {});
},
},
{
Expand Down Expand Up @@ -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, {});
},
},
{
Expand Down Expand Up @@ -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, {});
},
},
{
Expand All @@ -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;
},
},
Expand Down
7 changes: 4 additions & 3 deletions app/web/src/store/views.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: () => {
Expand All @@ -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,
{},
);
});
},
Expand Down

0 comments on commit 44dc9cc

Please sign in to comment.