Skip to content

Commit

Permalink
refactor uuids
Browse files Browse the repository at this point in the history
  • Loading branch information
mutdmour committed Nov 11, 2021
1 parent 2b872eb commit 07f6848
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
7 changes: 2 additions & 5 deletions packages/editor-ui/src/components/mixins/nodeBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ const anchorPositions: {
},
};

const INPUT_UUID_KEY = '-input';
const OUTPUT_UUID_KEY = '-output';

const getInputEndpointStyle = (nodeTypeData: INodeTypeDescription, color: string) => ({
width: 8,
height: nodeTypeData && nodeTypeData.outputs.length > 2 ? 18 : 20,
Expand Down Expand Up @@ -148,7 +145,7 @@ export const nodeBase = mixins(
const anchorPosition = anchorPositions.input[nodeTypeData.inputs.length][index];

const newEndpointData: IEndpointOptions = {
uuid: `${this.nodeIndex}` + INPUT_UUID_KEY + index,
uuid: CanvasHelpers.getInputEndpointUUID(this.nodeIndex, index),
anchor: anchorPosition,
maxConnections: -1,
endpoint: 'Rectangle',
Expand Down Expand Up @@ -213,7 +210,7 @@ export const nodeBase = mixins(
const anchorPosition = anchorPositions.output[nodeTypeData.outputs.length][index];

const newEndpointData: IEndpointOptions = {
uuid: `${this.nodeIndex}` + OUTPUT_UUID_KEY + index,
uuid: CanvasHelpers.getInputEndpointUUID(this.nodeIndex, index),
anchor: anchorPosition,
maxConnections: -1,
endpoint: 'Dot',
Expand Down
17 changes: 7 additions & 10 deletions packages/editor-ui/src/views/NodeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1644,17 +1644,14 @@ export default mixins(
}
});
},
getOutputEndpointUUID(nodeName: string, index: number) {
return `${this.getNodeIndex(nodeName)}-output${index}`;
},
getInputEndpointUUID(nodeName: string, index: number) {
return `${this.getNodeIndex(nodeName)}-input${index}`;
},
__addConnection (connection: [IConnection, IConnection], addVisualConnection = false) {
if (addVisualConnection === true) {
const sourceIndex = this.getNodeIndex(connection[0].node);
const targetIndex = this.getNodeIndex(connection[1].node);
const uuid: [string, string] = [
this.getOutputEndpointUUID(connection[0].node, connection[0].index),
this.getInputEndpointUUID(connection[1].node, connection[1].index),
CanvasHelpers.getOutputEndpointUUID(sourceIndex, connection[0].index),
CanvasHelpers.getInputEndpointUUID(targetIndex, connection[1].index),
];
// Create connections in DOM
Expand Down Expand Up @@ -1762,8 +1759,8 @@ export default mixins(
const targetIndex = this.getNodeIndex(targetNodeName);
const targetId = `${NODE_NAME_PREFIX}${targetIndex}`;
const sourceEndpoint = `${sourceIndex}-output${sourceOutputIndex}`;
const targetEndpoint = `${targetIndex}-input${targetInputIndex}`;
const sourceEndpoint = CanvasHelpers.getOutputEndpointUUID(sourceIndex, sourceOutputIndex);
const targetEndpoint = CanvasHelpers.getInputEndpointUUID(targetIndex, targetInputIndex);
// @ts-ignore
const connections = this.instance.getConnections({
Expand Down
8 changes: 8 additions & 0 deletions packages/editor-ui/src/views/canvasHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -637,3 +637,11 @@ export const addConnectionActionsOverlay = (connection: Connection, onDelete: Fu
]);
};

export const getOutputEndpointUUID = (nodeIndex: string, outputIndex: number): string => {
return `${nodeIndex}-output${outputIndex}`;
};

export const getInputEndpointUUID = (nodeIndex: string, inputIndex: number): string => {
return `${nodeIndex}-input${inputIndex}`;
};

0 comments on commit 07f6848

Please sign in to comment.