Skip to content

Commit 92198d8

Browse files
authored
Issue #837: fix: preserve user edits in transformation expressions when editing transformation connections (#838)
fixes #837 now when moving a wire the expression should not change. it does not try to figure out how to update it with the new connection, it just copies it over. this is because we don't know currently whether or not a more complicated edit has been made, and don't want to lose work on the expression.
2 parents 67efbb4 + 0d98f14 commit 92198d8

1 file changed

Lines changed: 5 additions & 24 deletions

File tree

frontends/mdr-frontend/src/pages/Explore/Mappings/MappingsView.tsx

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1814,15 +1814,7 @@ const MappingsView: React.FC = () => {
18141814
targetModel
18151815
),
18161816
} as any;
1817-
// Build source & target JSONata paths for naming and default expression on reassignment create
1818-
const srcAttrName =
1819-
(firstSrc as any)?.AttributeName ||
1820-
(firstSrc as any)?.Name ||
1821-
undefined;
1822-
const sourcePathExpr = buildDirectKeyExpression(
1823-
(firstSrc as any)?.EntityIdPath,
1824-
srcAttrName || null
1825-
);
1817+
// Derive target attribute name for the transformation name
18261818
const targetAttrName = (() => {
18271819
if (targetModel?.Entities) {
18281820
for (const ewa of targetModel.Entities) {
@@ -1841,28 +1833,17 @@ const MappingsView: React.FC = () => {
18411833
tgtPath,
18421834
targetAttrName
18431835
) || targetAttrName;
1844-
let srcSchema: any = null;
1845-
let tgtSchema: any = null;
1846-
try {
1847-
if (sourceModel?.EntityTree) srcSchema = generateJsonSchema(sourceModel, sourceModel.EntityTree);
1848-
} catch { /* ignore */ }
1849-
try {
1850-
if (targetModel?.EntityTree) tgtSchema = generateJsonSchema(targetModel, targetModel.EntityTree);
1851-
} catch { /* ignore */ }
1852-
const equalityExpr = buildDefaultAssignmentExpression(
1853-
srcSchema,
1854-
tgtSchema,
1855-
sourcePathExpr || '',
1856-
targetPathExpr || ''
1857-
) || (targetPathExpr && sourcePathExpr ? `${targetPathExpr} = ${sourcePathExpr}` : sourcePathExpr || targetPathExpr || '');
1836+
// Copy the expression from the old transformation instead of generating a new one.
1837+
// This preserves any manual edits the user may have made to the expression.
1838+
const preservedExpression = t.Expression;
18581839
// Use createOrUpdateTransformation to handle duplicate target attributes
18591840
const existingTransforms = group?.Transformations || transformations;
18601841
const result = await createOrUpdateTransformation({
18611842
TransformationGroupId:
18621843
t.TransformationGroupId,
18631844
ExpressionLanguage:
18641845
(t.ExpressionLanguage as any) || 'JSONata',
1865-
Expression: equalityExpr,
1846+
Expression: preservedExpression,
18661847
Name: targetPathExpr,
18671848
SourceAttributes: srcAttrPayload
18681849
? [srcAttrPayload]

0 commit comments

Comments
 (0)