Skip to content

Commit 9b44f43

Browse files
authored
fix(Data Mapper): Deserialize source edge for custom function with dash in its name (#4384)
Deserialize source edge for custom function with dash in its name
1 parent 1327f8d commit 9b44f43

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

libs/data-mapper/src/lib/utils/DataMap.Utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ export const getDestinationNode = (targetKey: string, functions: FunctionData[],
254254
return findFunctionForFunctionName(mapNodeParams.if, functions);
255255
}
256256

257-
const dashIndex = targetKey.indexOf('-');
257+
const guidLength = 36;
258+
const dashIndex = targetKey.lastIndexOf('-', targetKey.length - guidLength);
258259
const destinationFunctionKey = dashIndex === -1 ? targetKey : targetKey.slice(0, dashIndex);
259260
const destinationFunctionGuid = targetKey.slice(dashIndex + 1);
260261

libs/data-mapper/src/lib/utils/__test__/DataMapUtils.spec.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { FunctionCategory } from '../../models';
2+
import type { FunctionData } from '../../models';
23
import type { ConnectionDictionary, ConnectionUnit } from '../../models/Connection';
34
import {
45
ReservedToken,
56
Separators,
67
addAncestorNodesToCanvas,
78
addParentConnectionForRepeatingElementsNested,
9+
getDestinationNode,
810
getSourceValueFromLoop,
911
getTargetValueWithoutLoops,
1012
lexThisThing as separateIntoTokens,
@@ -980,6 +982,59 @@ describe('utils/DataMap', () => {
980982
]);
981983
});
982984
});
985+
986+
describe('getDestinationNode', () => {
987+
const mockSchemaNodeExtended: SchemaNodeExtended = {
988+
key: '/root',
989+
name: 'root',
990+
qName: 'root',
991+
type: NormalizedDataType.String,
992+
properties: SchemaNodeProperty.None,
993+
nodeProperties: [SchemaNodeProperty.None],
994+
children: [
995+
{
996+
key: '/root/Some-String-Property-With-A-Dash-And-Longer-Than-A-Guid',
997+
name: 'Some-String-Property-With-A-Dash-And-Longer-Than-A-Guid',
998+
qName: 'Some-String-Property-With-A-Dash-And-Longer-Than-A-Guid',
999+
type: NormalizedDataType.String,
1000+
properties: SchemaNodeProperty.None,
1001+
nodeProperties: [SchemaNodeProperty.None],
1002+
children: [],
1003+
pathToRoot: [],
1004+
arrayItemIndex: undefined,
1005+
parentKey: '/root',
1006+
},
1007+
],
1008+
pathToRoot: [],
1009+
arrayItemIndex: undefined,
1010+
parentKey: undefined,
1011+
};
1012+
1013+
const mockFunctionData: FunctionData = {
1014+
key: 'some-function',
1015+
functionName: 'Some',
1016+
displayName: 'Some',
1017+
category: FunctionCategory.Custom,
1018+
description: 'Some',
1019+
inputs: [],
1020+
maxNumberOfInputs: 0,
1021+
outputValueType: NormalizedDataType.String,
1022+
};
1023+
1024+
it('returns function data for function target key', () => {
1025+
const result = getDestinationNode('some-function-4C117648-E570-4CDA-BA8E-DAFC66ECD402', [mockFunctionData], mockSchemaNodeExtended);
1026+
expect(result).toBe(mockFunctionData);
1027+
});
1028+
1029+
it('returns schema node for node target key', () => {
1030+
const result = getDestinationNode(
1031+
'/root/Some-String-Property-With-A-Dash-And-Longer-Than-A-Guid',
1032+
[mockFunctionData],
1033+
mockSchemaNodeExtended
1034+
);
1035+
expect(result).toBe(mockSchemaNodeExtended.children[0]);
1036+
});
1037+
});
9831038
});
9841039

9851040
const indexed: ConnectionDictionary = {

0 commit comments

Comments
 (0)