uber / react-digraph

A library for creating directed graph editors
MIT License
2.62k stars 269 forks source link

onCopySelected is not call on copying the edge #257

Closed Malikx-Alee closed 4 years ago

Malikx-Alee commented 4 years ago

I am expecting this onCopySelected function to be called either the node or edge is selected, but currently its only being called for node only.

onCopySelected = () => {
    console.log("Node or edge is selected");
    if (this.state.selected.source) {
      console.warn("Cannot copy selected edges, try selecting a node instead.");

      return;
    }

    const x = this.state.selected.x + 10;
    const y = this.state.selected.y + 10;

    this.setState({
      copiedNode: { ...this.state.selected, x, y },
    });
  };
<GraphView
                ref={(el) => (this.GraphView = el)}
                nodeKey={NODE_KEY}
                nodes={this.state.graph.nodes}
                edges={this.state.graph.edges}
                selected={selected}
                nodeTypes={NodeTypes}
                nodeSubtypes={NodeSubtypes}
                edgeTypes={EdgeTypes}
                onSelectNode={this.onSelectNode}
                onCreateNode={this.onCreateNode}
                onUpdateNode={this.onUpdateNode}
                onDeleteNode={this.onDeleteNode}
                onSelectEdge={this.onSelectEdge}
                onCreateEdge={this.onCreateEdge}
                onSwapEdge={this.onSwapEdge}
                onDeleteEdge={this.onDeleteEdge}
                onUndo={this.onUndo}
                onCopySelected={this.onCopySelected}
                onPasteSelected={this.onPasteSelected}
                // onContextMenu={this.onContextMenu}
                layoutEngineType={this.state.layoutEngineType}
                renderNode={this.renderNode}
                renderNodeText={this.renderNodeText}
              />
ajbogh commented 4 years ago

onCopySelected only works on nodes because edges are a link between two nodes, so you can't really copy them anywhere. It would be the third party developer that would have to figure out what happens when an edge is copied. If you're willing you can help modify the graph-view.js file to include edge copying in the "c" and "v" locations. This would have to be a breaking change unless an additional graph-view attribute (allowEdgeCopying={boolean=false}) were included.

https://github.com/uber/react-digraph/blob/master/src/components/graph-view.js#L601