From 8b05d89d434fd921b6b3be25ef2ecd2df029d4bd Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Sun, 18 Jun 2023 21:26:44 +0200 Subject: [PATCH] Fix connection serialisation + front end connection error --- .../elsa-workflows-designer/src/utils/graph.ts | 12 ++++++------ .../Serialization/FlowchartJsonConverter.cs | 9 ++++----- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/designer/designer_packages/elsa-workflows-designer/src/utils/graph.ts b/src/designer/designer_packages/elsa-workflows-designer/src/utils/graph.ts index 6fb3fe389..f60f5c0ca 100644 --- a/src/designer/designer_packages/elsa-workflows-designer/src/utils/graph.ts +++ b/src/designer/designer_packages/elsa-workflows-designer/src/utils/graph.ts @@ -243,9 +243,9 @@ export function createEdge(connection: Connection): Edge.Metadata { export function removeGuidsFromPortNames(root: Activity) { if (root.connections?.length > 0) { - root.connections.forEach((connection: { sourcePort: string; targetPort: string; }) => { - connection.sourcePort = getPortNameByPortId(connection.sourcePort); - connection.targetPort = getPortNameByPortId(connection.targetPort); + root.connections.forEach((connection: Connection) => { + connection.source.port = getPortNameByPortId(connection.source.port); + connection.target.port = getPortNameByPortId(connection.target.port); }); } let activitiesWithConnections = root.activities?.filter(act => act.body?.connections?.length > 0); @@ -256,9 +256,9 @@ export function removeGuidsFromPortNames(root: Activity) { export function addGuidsToPortNames(root: Activity) { if (root.connections.length > 0) { - root.connections.forEach((connection: { sourcePort: string; targetPort: string; }) => { - connection.sourcePort = uuid() + '_' + connection.sourcePort; - connection.targetPort = uuid() + '_' + connection.targetPort; + root.connections.forEach((connection: Connection) => { + connection.source.port = uuid() + '_' + connection.source.port; + connection.target.port = uuid() + '_' + connection.target.port; }); } let activitiesWithConnections = root.activities?.filter(act => act.body?.connections?.length > 0); diff --git a/src/modules/Elsa.Workflows.Core/Activities/Flowchart/Serialization/FlowchartJsonConverter.cs b/src/modules/Elsa.Workflows.Core/Activities/Flowchart/Serialization/FlowchartJsonConverter.cs index 73e795720..326a265dd 100644 --- a/src/modules/Elsa.Workflows.Core/Activities/Flowchart/Serialization/FlowchartJsonConverter.cs +++ b/src/modules/Elsa.Workflows.Core/Activities/Flowchart/Serialization/FlowchartJsonConverter.cs @@ -29,13 +29,12 @@ public class FlowchartJsonConverter : JsonConverter var connectionsElement = doc.RootElement.TryGetProperty("connections", out var connectionsEl) ? connectionsEl : default; var activitiesElement = doc.RootElement.TryGetProperty("activities", out var activitiesEl) ? activitiesEl : default; - var id = doc.RootElement.TryGetProperty("id", out var idAttribute) ? idAttribute.GetString() : _identityGenerator.GenerateId(); + var id = doc.RootElement.TryGetProperty("id", out var idAttribute) ? idAttribute.GetString()! : _identityGenerator.GenerateId(); var startId = doc.RootElement.TryGetProperty("start", out var startElement) ? startElement.GetString() : default; var activities = activitiesElement.ValueKind != JsonValueKind.Undefined ? activitiesElement.Deserialize>(options) ?? new List() : new List(); var metadataElement = doc.RootElement.TryGetProperty("metadata", out var metadataEl) ? metadataEl : default; var metadata = metadataElement.ValueKind != JsonValueKind.Undefined ? metadataElement.Deserialize>(options) ?? new Dictionary() : new Dictionary(); var start = activities.FirstOrDefault(x => x.Id == startId) ?? activities.FirstOrDefault(); - //var connectionSerializerOptions = new JsonSerializerOptions(options); var activityDictionary = activities.ToDictionary(x => x.Id); var connections = DeserializeConnections(connectionsElement, activityDictionary, options); var notFoundConnections = GetNotFoundConnections(doc.RootElement, activityDictionary, connections, options); @@ -93,9 +92,9 @@ public class FlowchartJsonConverter : JsonConverter private static ICollection GetNotFoundConnections(JsonElement rootElement, IDictionary activities, IEnumerable connections, JsonSerializerOptions connectionSerializerOptions) { - var applicationPropertiesElement = rootElement.TryGetProperty("applicationProperties", out var applicationPropertiesEl) ? applicationPropertiesEl : default; - var notFoundConnectionsElement = applicationPropertiesElement.ValueKind != JsonValueKind.Undefined ? applicationPropertiesElement.TryGetProperty(NotFoundConnectionsKey, out var notFoundConnectionsEl) ? notFoundConnectionsEl : default : default; - var notFoundConnections = DeserializeConnections(notFoundConnectionsElement, activities, connectionSerializerOptions); + var customPropertiesElement = rootElement.TryGetProperty("customProperties", out var customPropertiesEl) ? customPropertiesEl : default; + var notFoundConnectionsElement = customPropertiesElement.ValueKind != JsonValueKind.Undefined ? customPropertiesElement.TryGetProperty(NotFoundConnectionsKey, out var notFoundConnectionsEl) ? notFoundConnectionsEl : default : default; + var notFoundConnections = notFoundConnectionsElement.ValueKind != JsonValueKind.Undefined ? DeserializeConnections(notFoundConnectionsElement, activities, connectionSerializerOptions) : new List(); // Add connections of NotFoundActivity to the list if they aren't already in it. var notFoundActivities = activities.Values.Where(x => x is NotFoundActivity).Cast().ToList();