react-flow-chart icon indicating copy to clipboard operation
react-flow-chart copied to clipboard

Delete node on user action only

Open DrAmin opened this issue 5 years ago • 1 comments

We have integrated this library in our project, all the functionalities working fine. but we are facing issue while deleting node based on user action. Currently, user can delete node via Backspace and Delete button, but, it causes issue in our requirement so, we want to give button to delete node and for that, we referred your Selected-sidebar demo but, this demo has same issue.

Can you please help us to solve this problem?

Thank You.

DrAmin avatar Aug 08 '20 18:08 DrAmin

The culprit is line 183 here. It's missing a null-check.

https://github.com/MrBlenny/react-flow-chart/blob/master/src/container/actions.ts

if (config.readonly) {
    return chart
  }

Should be something like

if(config && config.readonly)

onDeleteKey takes an argument of the type IConfig. Which is not passed in the story you mentioned. Easiest workaround for you, while this is fixed, would be to just do this:

const config = { readonly: false }
...
<Button onClick={() => stateActions.onDeleteKey({config})}>Delete</Button>

davidanitoiu avatar Aug 08 '20 23:08 davidanitoiu