Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added port type "any" #109

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions src/components/IoPorts/IoPorts.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { PortTypesContext } from "../../context";
import usePrevious from "../../hooks/usePrevious";
import { calculateCurve, getPortRect } from "../../connectionCalculator";
import { STAGE_ID, DRAG_CONNECTION_ID } from '../../constants'
import { getPort } from "../../utilities";

function useTransputs (transputsFn, transputType, nodeId, inputData, connections) {
const nodesDispatch = React.useContext(NodeDispatchContext);
Expand Down Expand Up @@ -54,7 +55,7 @@ const IoPorts = ({
const triggerRecalculation = React.useContext(ConnectionRecalculateContext);
const resolvedInputs = useTransputs(inputs, 'input', nodeId, inputData, connections);
const resolvedOutputs = useTransputs(outputs, 'output', nodeId, inputData, connections);

return (
<div className={styles.wrapper}>
{resolvedInputs.length ? (
Expand Down Expand Up @@ -265,29 +266,39 @@ const Port = ({
const droppedOnPort = !!e.target.dataset.portName;

if (isInput) {

const {
inputNodeId,
inputPortName,
outputNodeId,
outputPortName
outputPortName,
} = lineInToPort.current.dataset;

nodesDispatch({
type: "REMOVE_CONNECTION",
input: { nodeId: inputNodeId, portName: inputPortName },
output: { nodeId: outputNodeId, portName: outputPortName }
});
if (droppedOnPort) {

const {
portName: connectToPortName,
nodeId: connectToNodeId,
portType: connectToPortType,
portTransputType: connectToTransputType
} = e.target.dataset;
const isNotSameNode = outputNodeId !== connectToNodeId;

if (isNotSameNode && connectToTransputType !== "output") {
const inputWillAcceptConnection = inputTypes[
connectToPortType
].acceptTypes.includes(type);

const outputPortType = getPort(outputNodeId, outputPortName, "output").dataset.portType

const inputWillAcceptConnection = inputTypes[
connectToPortType
].acceptTypes.includes(outputPortType) || inputTypes[
connectToPortType
].acceptTypes.includes('any');

if (inputWillAcceptConnection) {
nodesDispatch({
type: "ADD_CONNECTION",
Expand All @@ -308,8 +319,12 @@ const Port = ({
const isNotSameNode = inputNodeId !== nodeId;
if (isNotSameNode && inputTransputType !== "output") {
const inputWillAcceptConnection = inputTypes[
inputNodeType
].acceptTypes.includes(type);
inputNodeType
].acceptTypes.includes(type) || inputTypes[
inputNodeType
].acceptTypes.includes('any')


if (inputWillAcceptConnection) {
nodesDispatch({
type: "ADD_CONNECTION",
Expand Down Expand Up @@ -340,6 +355,7 @@ const Port = ({
);
const portIsConnected = !!lineInToPort.current;
if (portIsConnected) {

lineInToPort.current.parentNode.style.zIndex = 9999;
const outputPort = getPortRect(
lineInToPort.current.dataset.outputNodeId,
Expand Down Expand Up @@ -381,6 +397,7 @@ const Port = ({
}
};


return (
<React.Fragment>
<div
Expand Down
6 changes: 1 addition & 5 deletions src/connectionCalculator.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import styles from "./components/Connection/Connection.css";
import { CONNECTIONS_ID } from './constants'
import { line, curveBasis } from 'd3-shape'

const getPort = (nodeId, portName, transputType = "input") => document
.querySelector(
`[data-node-id="${nodeId}"] [data-port-name="${portName}"][data-port-transput-type="${transputType}"]`
)
import { getPort } from "./utilities";

export const getPortRect = (nodeId, portName, transputType = "input", cache) => {
if(cache){
Expand Down
5 changes: 5 additions & 0 deletions src/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ export const checkForCircularNodes = (nodes, startNodeId) => {
walk(startNodeId)
return isCircular;
}

export const getPort = (nodeId, portName, transputType = "input") => document
.querySelector(
`[data-node-id="${nodeId}"] [data-port-name="${portName}"][data-port-transput-type="${transputType}"]`
)