Skip to content

fix(Data Mapper): Deserialize source edge for custom function with dash in its name #4384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion libs/data-mapper/src/lib/utils/DataMap.Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ export const getDestinationNode = (targetKey: string, functions: FunctionData[],
return findFunctionForFunctionName(mapNodeParams.if, functions);
}

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

Expand Down
55 changes: 55 additions & 0 deletions libs/data-mapper/src/lib/utils/__test__/DataMapUtils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { FunctionCategory } from '../../models';
import type { FunctionData } from '../../models';
import type { ConnectionDictionary, ConnectionUnit } from '../../models/Connection';
import {
ReservedToken,
Separators,
addAncestorNodesToCanvas,
addParentConnectionForRepeatingElementsNested,
getDestinationNode,
getSourceValueFromLoop,
getTargetValueWithoutLoops,
lexThisThing as separateIntoTokens,
Expand Down Expand Up @@ -980,6 +982,59 @@ describe('utils/DataMap', () => {
]);
});
});

describe('getDestinationNode', () => {
const mockSchemaNodeExtended: SchemaNodeExtended = {
key: '/root',
name: 'root',
qName: 'root',
type: NormalizedDataType.String,
properties: SchemaNodeProperty.None,
nodeProperties: [SchemaNodeProperty.None],
children: [
{
key: '/root/Some-String-Property-With-A-Dash-And-Longer-Than-A-Guid',
name: 'Some-String-Property-With-A-Dash-And-Longer-Than-A-Guid',
qName: 'Some-String-Property-With-A-Dash-And-Longer-Than-A-Guid',
type: NormalizedDataType.String,
properties: SchemaNodeProperty.None,
nodeProperties: [SchemaNodeProperty.None],
children: [],
pathToRoot: [],
arrayItemIndex: undefined,
parentKey: '/root',
},
],
pathToRoot: [],
arrayItemIndex: undefined,
parentKey: undefined,
};

const mockFunctionData: FunctionData = {
key: 'some-function',
functionName: 'Some',
displayName: 'Some',
category: FunctionCategory.Custom,
description: 'Some',
inputs: [],
maxNumberOfInputs: 0,
outputValueType: NormalizedDataType.String,
};

it('returns function data for function target key', () => {
const result = getDestinationNode('some-function-4C117648-E570-4CDA-BA8E-DAFC66ECD402', [mockFunctionData], mockSchemaNodeExtended);
expect(result).toBe(mockFunctionData);
});

it('returns schema node for node target key', () => {
const result = getDestinationNode(
'/root/Some-String-Property-With-A-Dash-And-Longer-Than-A-Guid',
[mockFunctionData],
mockSchemaNodeExtended
);
expect(result).toBe(mockSchemaNodeExtended.children[0]);
});
});
});

const indexed: ConnectionDictionary = {
Expand Down