Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug: #2572 Signed-off-by: Michaël Charfadi <michael.charfadi@obeosoft.com>
- Loading branch information
Showing
27 changed files
with
680 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...es/diagrams/frontend/sirius-components-diagrams-reactflow/src/converter/convertHandles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/******************************************************************************* | ||
* 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 { GQLEdge } from '../graphql/subscription/edgeFragment.types'; | ||
import { GQLNode, GQLNodeStyle } from '../graphql/subscription/nodeFragment.types'; | ||
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: GQLNode<GQLNodeStyle>, gqlEdges: GQLEdge[]): ConnectionHandle[] => { | ||
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.