question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature Request] Implement `onPortLink`

See original GitHub issue

My case is very simple - I need to link two ports between two nodes. How one should do it? This is what I tried to do:

<rf.Canvas
    nodes={nodes}
    edges={edges}
    onNodeLink={(event, from, to) => {
    // no `fromPort` and `toPort` here; does not run on port links
    console.log({ from, to })
    }}
    node={nodeProps => (
    <rf.Node
        dragType="port"
        port={
        <Port
            onEnter={(event, port) => 
            setTargetPortId(port.id)
            }}
            onLeave={(event, port) => {
            setTargetPortId(null)
            }}
            onDragStart={(event, pos, port) => {
            setSrcPortId(port.id)
            }}
            onDragEnd={(event, pos, port) => {
            setSrcPortId(null)
            setTargetPortId(null)
            }}
        />
        }
    />

First I thought I can do it with onDragEnd but there is no node there

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
emil14commented, Jan 31, 2022

@rishab-sharma here’s a piece from my project

function NetworkEditor(props: NetworkProps) {
  const [selections, setSelections] = useState<string[]>([])

  // dragging state
  const [srcNodeId, setSrcNodeId] = useState<string | null>(null)
  const [srcPortId, setSrcPortId] = useState<string | null>(null)
  const [dstNodeId, setDstNodeId] = useState<string | null>(null)
  const [dstPortId, setDstPortId] = useState<string | null>(null)

  const renderContextMenu = (e: MouseEvent) => {
    e.preventDefault()
    ContextMenu.show(
      <Menu>
        <MenuItem text="Add node" onClick={props.onAddNode} />
      </Menu>,
      { left: e.clientX, top: e.clientY },
      () => {}
    )
  }

  const { nodes, edges } = rfGraph(props.module)

  return (
    <div
      style={{
        position: "relative",
        width: "100%",
        height: "100%",
      }}
      onContextMenu={event => renderContextMenu(event.nativeEvent as any)}
    >
      <div
        style={{
          position: "absolute",
          left: 0,
          right: 0,
          top: 0,
          bottom: 0,
          background: "black",
        }}
      >
        <rf.Canvas
          nodes={nodes}
          edges={edges}
          selections={selections}
          onCanvasClick={() => setSelections([])}
          node={nodeProps => (
            <rf.Node
              dragType="port"
              onClick={(_event, node) => {
                if (selections.includes(node.id)) {
                  props.onNodeClick(node.id)
                  setSelections([])
                  return
                }
                setSelections([node.id])
              }}
              onRemove={(_event, node) => props.onRemoveNode(node.id)}
              port={
                <Port
                  onEnter={(_event, port) => {
                    setDstNodeId(nodeProps.id)
                    setDstPortId(port.id)
                  }}
                  onLeave={(_event, _port) => {}}
                  onDragStart={(_event, _pos, port) => {
                    setSrcNodeId(nodeProps.id)
                    setSrcPortId(port.id)
                  }}
                  onDragEnd={(_event, _pos, _port) => {
                    props.onAddConnection({
                      from: {
                        node: srcNodeId,
                        port: removePortPrefix(srcPortId),
                      },
                      to: {
                        node: dstNodeId,
                        port: removePortPrefix(dstPortId),
                      },
                    })
                    setSrcPortId(null)
                    setDstPortId(null)
                  }}
                />
              }
              onEnter={(_event, node) => {}}
            />
          )}
          edge={edge => (
            <Edge
              onClick={(_event, edge) => setSelections([edge.id])}
              onRemove={(_event, edge) => {
                props.onRemoveConnection({
                  from: {
                    node: edge.from,
                    port: removePortPrefix(edge.fromPort),
                  },
                  to: {
                    node: edge.to,
                    port: removePortPrefix(edge.toPort),
                  },
                })
              }}
              // onAdd={}
            />
          )}
        />
      </div>
    </div>
  )
}
1reaction
emil14commented, Oct 27, 2021
  1. I tested code and found a few bugs, now I have a working solution. Will add example to docs later
Read more comments on GitHub >

github_iconTop Results From Across the Web

Feature Request Template: How to Manage Suggestions at ...
Streamline and organize user feedback with this free feature request template. Available in Google Docs and Sheets (no email required).
Read more >
Issues · reaviz/reaflow · GitHub
[Feature Request] Implement onPortLink documentation Improvements or additions to documentation. #114 opened on Oct 25, 2021 by emil14.
Read more >
Feature Requests: What are they and how to manage them
Feature requests are a form of product feedback you may frequently encounter as a SaaS product manager. They typically come in the form...
Read more >
How to Make a Feature Request | Short.Io Help Center
You can add a request, track its implementation, vote for the request that other customers have left, receive notification when your request is...
Read more >
Feature Request Management Software | Hellonext
Feature request software to make data-informed decisions. Make data informed product decisions to ship features that your users need.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found