-
Notifications
You must be signed in to change notification settings - Fork 45
/
convertHandles.ts
62 lines (58 loc) · 2.06 KB
/
convertHandles.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*******************************************************************************
* Copyright (c) 2023 Obeo.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Obeo - initial API and implementation
*******************************************************************************/
import { Position } from 'reactflow';
import { ConnectionHandle } from '../renderer/handles/ConnectionHandles.types';
const numberSourceHandles = (handles: ConnectionHandle[]): string => {
return handles.filter((handle) => handle.type === 'source').length.toString();
};
const numberTargetHandles = (handles: ConnectionHandle[]): string => {
return handles.filter((handle) => handle.type === 'target').length.toString();
};
export const convertHandles = (gqlNode, gqlEdges) => {
const connectionHandles: ConnectionHandle[] = [];
gqlEdges.forEach((edge) => {
if (edge.sourceId === gqlNode.id) {
connectionHandles.push({
id: `handle--source--${gqlNode.id}--${numberSourceHandles(connectionHandles)}`,
edgeId: edge.id,
nodeId: gqlNode.id,
position: Position.Right,
type: 'source',
});
}
if (edge.targetId === gqlNode.id) {
connectionHandles.push({
id: `handle--target--${gqlNode.id}--${numberTargetHandles(connectionHandles)}`,
edgeId: edge.id,
nodeId: gqlNode.id,
position: Position.Left,
type: 'target',
});
}
});
connectionHandles.push({
id: `handle--source--${gqlNode.id}--${numberSourceHandles(connectionHandles)}`,
edgeId: '',
nodeId: gqlNode.id,
position: Position.Right,
type: 'source',
});
connectionHandles.push({
id: `handle--target--${gqlNode.id}--${numberTargetHandles(connectionHandles)}`,
edgeId: '',
nodeId: gqlNode.id,
position: Position.Left,
type: 'target',
});
return connectionHandles;
};