From 58c96181605d1d1cc0876d5cfa1d55cbcaaf4a66 Mon Sep 17 00:00:00 2001 From: Adela Almasan <88068998+adela-almasan@users.noreply.github.com> Date: Mon, 30 Jan 2023 22:36:57 -0600 Subject: [PATCH] Canvas: Update connection info on element rename (#62532) --- public/app/features/canvas/runtime/element.tsx | 7 +++++++ public/app/plugins/panel/canvas/Connections.tsx | 1 + public/app/plugins/panel/canvas/utils.ts | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/public/app/features/canvas/runtime/element.tsx b/public/app/features/canvas/runtime/element.tsx index b954e96f18e..cb0cdea33ac 100644 --- a/public/app/features/canvas/runtime/element.tsx +++ b/public/app/features/canvas/runtime/element.tsx @@ -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); } diff --git a/public/app/plugins/panel/canvas/Connections.tsx b/public/app/plugins/panel/canvas/Connections.tsx index 3fe72811ff0..a7cb726b72c 100644 --- a/public/app/plugins/panel/canvas/Connections.tsx +++ b/public/app/plugins/panel/canvas/Connections.tsx @@ -99,6 +99,7 @@ export class Connections { return false; } + this.connectionTarget = undefined; this.connectionAnchorDiv!.style.display = 'none'; return true; }; diff --git a/public/app/plugins/panel/canvas/utils.ts b/public/app/plugins/panel/canvas/utils.ts index 878359cabdb..1da2f120515 100644 --- a/public/app/plugins/panel/canvas/utils.ts +++ b/public/app/plugins/panel/canvas/utils.ts @@ -157,3 +157,7 @@ export function getConnections(sceneByName: Map) { return connections; } + +export function getConnectionsByTarget(element: ElementState, scene: Scene) { + return getConnections(scene.byName).filter((connection) => connection.target === element); +}