Skip to content

Commit

Permalink
Merge pull request #5049 from systeminit/fix/BUG-693-frame-holds-refe…
Browse files Browse the repository at this point in the history
…rence-to-children-wrongly

Fix: children that leave a parent were not re-processing their former parents
  • Loading branch information
johnrwatson authored Dec 2, 2024
2 parents b2b4d5f + 45fa66a commit 468fba9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
12 changes: 6 additions & 6 deletions app/web/src/components/ModelingDiagram/ModelingDiagram.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1689,7 +1689,7 @@ function endDragElements() {
},
);

const setParents: ComponentId[] = [];
const setParents: Set<ComponentId> = new Set();
nonChildElements.forEach((component) => {
if (!("parentId" in component.def)) return;
// if their current parent is NOT in this view, do not re-parent!!!
Expand All @@ -1703,17 +1703,17 @@ function endDragElements() {
// same parent, no call needed
if (component.def.parentId === newParent?.def.id) return;

if (component.def.parentId && detach) setParents.push(component.def.id);
if (component.def.parentId && detach) setParents.add(component.def.id);

if (!component.def.parentId && newParent?.def.id)
setParents.push(component.def.id);
setParents.add(component.def.id);

if (component.def.parentId !== newParent?.def.id)
setParents.push(component.def.id);
setParents.add(component.def.id);
});

if (setParents.length > 0) {
viewStore.SET_PARENT(setParents, newParent?.def.id ?? null);
if (setParents.size > 0) {
viewStore.SET_PARENT([...setParents], newParent?.def.id ?? null);
}

if (_components.length > 0)
Expand Down
5 changes: 5 additions & 0 deletions app/web/src/store/components.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1227,8 +1227,13 @@ export const useComponentsStore = (forceChangeSetId?: ChangeSetId) => {
// If the component that updated wasn't in this change set,
// don't update
if (metadata.change_set_id !== changeSetId) return;
const oldParent =
this.rawComponentsById[data.component.id]?.parentId;

this.rawComponentsById[data.component.id] = data.component;
this.processRawComponent(data.component.id);
if (oldParent && !data.component.parentId)
this.processRawComponent(oldParent);
},
},
{
Expand Down
12 changes: 10 additions & 2 deletions app/web/src/store/views.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1230,16 +1230,24 @@ export const useViewsStore = (forceChangeSetId?: ChangeSetId) => {
else {
component.parentId = undefined;
}
componentsStore.processRawComponent(componentId, true);
componentsStore.processRawComponent(componentId);
});
// if we change to no parent, we have to follow up and re-process
Object.values(oldParentIds)
.filter(nonNullable)
.forEach((parentId) => {
componentsStore.processRawComponent(parentId);
});
},
onFail: () => {
componentIds.forEach((componentId) => {
const component =
componentsStore.rawComponentsById[componentId];
if (!component) return;
component.parentId = oldParentIds[componentId];
componentsStore.processRawComponent(componentId, true);
componentsStore.processRawComponent(componentId);
if (component.parentId)
componentsStore.processRawComponent(component.parentId);
});
},
});
Expand Down

0 comments on commit 468fba9

Please sign in to comment.