Canvas: Update connection info on element rename (#62532)

This commit is contained in:
Adela Almasan 2023-01-30 22:36:57 -06:00 committed by GitHub
parent e7ace4ed62
commit 58c9618160
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import {
} from 'app/features/canvas';
import { notFoundItem } from 'app/features/canvas/elements/notFound';
import { DimensionContext } from 'app/features/dimensions';
import { getConnectionsByTarget, isConnectionTarget } from 'app/plugins/panel/canvas/utils';
import { Constraint, HorizontalConstraint, Placement, VerticalConstraint } from '../types';
@ -382,6 +383,12 @@ export class ElementState implements LayerElement {
const scene = this.getScene();
if (oldName !== newName && scene) {
if (isConnectionTarget(this, scene.byName)) {
getConnectionsByTarget(this, scene).forEach((connection) => {
connection.info.targetName = newName;
});
}
scene.byName.delete(oldName);
scene.byName.set(newName, this);
}

View File

@ -99,6 +99,7 @@ export class Connections {
return false;
}
this.connectionTarget = undefined;
this.connectionAnchorDiv!.style.display = 'none';
return true;
};

View File

@ -157,3 +157,7 @@ export function getConnections(sceneByName: Map<string, ElementState>) {
return connections;
}
export function getConnectionsByTarget(element: ElementState, scene: Scene) {
return getConnections(scene.byName).filter((connection) => connection.target === element);
}