Skip to content

Commit

Permalink
fix(editor): Handle drag-n-dropping from other nodes in assignment co…
Browse files Browse the repository at this point in the history
…mponent (n8n-io#8661)
  • Loading branch information
elsmr authored Feb 20, 2024
1 parent 3279762 commit c943a51
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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',
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c943a51

Please sign in to comment.