From c943a51a28953c2ecd0f3ae4849fd8a0de187bfc Mon Sep 17 00:00:00 2001 From: Elias Meire Date: Tue, 20 Feb 2024 11:21:10 +0100 Subject: [PATCH] fix(editor): Handle drag-n-dropping from other nodes in assignment component (#8661) --- .../AssignmentCollection/__tests__/utils.test.ts | 15 +++++++++++++++ .../src/components/AssignmentCollection/utils.ts | 5 ++++- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 packages/editor-ui/src/components/AssignmentCollection/__tests__/utils.test.ts diff --git a/packages/editor-ui/src/components/AssignmentCollection/__tests__/utils.test.ts b/packages/editor-ui/src/components/AssignmentCollection/__tests__/utils.test.ts new file mode 100644 index 0000000000000..7767a2a4bad6b --- /dev/null +++ b/packages/editor-ui/src/components/AssignmentCollection/__tests__/utils.test.ts @@ -0,0 +1,15 @@ +import { nameFromExpression } from '../utils'; + +describe('AssignmentCollection > utils', () => { + describe('nameFromExpression', () => { + test('should extract assignment name from previous node', () => { + expect(nameFromExpression('{{ $json.foo.bar }}')).toBe('foo.bar'); + }); + + test('should extract assignment name from another node', () => { + expect(nameFromExpression("{{ $('Node's \"Name\" (copy)').item.json.foo.bar }}")).toBe( + 'foo.bar', + ); + }); + }); +}); diff --git a/packages/editor-ui/src/components/AssignmentCollection/utils.ts b/packages/editor-ui/src/components/AssignmentCollection/utils.ts index cb2ddd4b3c1ac..55c7556fb73e7 100644 --- a/packages/editor-ui/src/components/AssignmentCollection/utils.ts +++ b/packages/editor-ui/src/components/AssignmentCollection/utils.ts @@ -4,7 +4,10 @@ import { resolveParameter } from '@/composables/useWorkflowHelpers'; import { v4 as uuid } from 'uuid'; export function nameFromExpression(expression: string): string { - return expression.replace(/^{{\s*|\s*}}$/g, '').replace('$json.', ''); + return expression + .replace(/^{{\s*|\s*}}$/g, '') + .replace('$json.', '') + .replace(/^\$\(.*\)(\.item\.json)?\.(.*)/, '$2'); } export function inferAssignmentType(value: unknown): string {