diff --git a/backend/src/Designer/EventHandlers/ComponentIdChanged/ComponentIdChangedLayoutsHandler.cs b/backend/src/Designer/EventHandlers/ComponentIdChanged/ComponentIdChangedLayoutsHandler.cs index 5ce5c4048a0..61577593b98 100644 --- a/backend/src/Designer/EventHandlers/ComponentIdChanged/ComponentIdChangedLayoutsHandler.cs +++ b/backend/src/Designer/EventHandlers/ComponentIdChanged/ComponentIdChangedLayoutsHandler.cs @@ -58,17 +58,22 @@ public bool TryChangeComponentId(JsonNode layout, string oldComponentId, string { JsonNode originalLayout = layout.DeepClone(); - FindIdOccurrencesRecursive(layout, oldComponentId, newComponentId); + FindIdOccurrencesRecursive(null, layout, oldComponentId, newComponentId); return !layout.ToJsonString().Equals(originalLayout.ToJsonString()); } - private void FindIdOccurrencesRecursive(JsonNode node, string oldComponentId, string newComponentId) + private void FindIdOccurrencesRecursive(string parentKey, JsonNode node, string oldComponentId, string newComponentId) { // Should we check if node is string to avoid unnecessary upcoming checks? if (node is JsonObject jsonObject) { - if (jsonObject["component"] is not null) + if (parentKey == "tableColumns" && jsonObject[oldComponentId] is not null) + { + // When componentId is the propertyName + UpdateComponentIdActingAsPropertyName(jsonObject, oldComponentId, newComponentId); + } + else if (jsonObject["component"] is not null) { // Objects that references components i.e. in `rowsAfter` in RepeatingGroup UpdateComponentIdActingAsCellMemberInRepeatingGroup(jsonObject, oldComponentId, newComponentId); @@ -85,7 +90,7 @@ private void FindIdOccurrencesRecursive(JsonNode node, string oldComponentId, st } foreach (var property in jsonObject) { - FindIdOccurrencesRecursive(property.Value, oldComponentId, newComponentId); + FindIdOccurrencesRecursive(property.Key, property.Value, oldComponentId, newComponentId); } } else if (node is JsonArray jsonArray) @@ -99,12 +104,23 @@ private void FindIdOccurrencesRecursive(JsonNode node, string oldComponentId, st } else { - FindIdOccurrencesRecursive(item, oldComponentId, newComponentId); + FindIdOccurrencesRecursive(parentKey, item, oldComponentId, newComponentId); } } } } + private void UpdateComponentIdActingAsPropertyName(JsonObject jsonObject, string oldComponentId, string newComponentId) + { + // Might need to make this stricter in case app-dev are calling components keys that already are used in the schema + JsonNode value = jsonObject[oldComponentId]; + jsonObject.Remove(oldComponentId); + if (!string.IsNullOrEmpty(newComponentId)) + { + jsonObject[newComponentId] = value; + } + } + private void UpdateComponentIdActingAsExpressionMember(JsonArray jsonArray, string newComponentId) { jsonArray[1] = newComponentId;