Canvas: Remove deleted connections from source (#65321)

This commit is contained in:
Adela Almasan 2023-03-27 11:51:56 -05:00 committed by GitHub
parent 1387fec51d
commit 21ede347cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import { notFoundItem } from 'app/features/canvas/elements/notFound';
import { DimensionContext } from 'app/features/dimensions';
import { LayerActionID } from 'app/plugins/panel/canvas/types';
import { updateConnectionsForSource } from '../../../plugins/panel/canvas/utils';
import { CanvasElementItem } from '../element';
import { HorizontalConstraint, Placement, VerticalConstraint } from '../types';
@ -114,6 +115,7 @@ export class FrameState extends ElementState {
switch (action) {
case LayerActionID.Delete:
this.elements = this.elements.filter((e) => e !== element);
updateConnectionsForSource(element, this.scene);
this.scene.byName.delete(element.options.name);
this.scene.save();
this.reinitializeMoveable();

View File

@ -161,3 +161,12 @@ export function getConnections(sceneByName: Map<string, ElementState>) {
export function getConnectionsByTarget(element: ElementState, scene: Scene) {
return getConnections(scene.byName).filter((connection) => connection.target === element);
}
export function updateConnectionsForSource(element: ElementState, scene: Scene) {
const targetConnections = getConnectionsByTarget(element, scene);
targetConnections.forEach((connection) => {
const sourceConnections = connection.source.options.connections?.splice(0) ?? [];
const connections = sourceConnections.filter((con) => con.targetName !== element.getName());
connection.source.onChange({ ...connection.source.options, connections });
});
}