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

Have the ability to cancel a delete #305

Closed
biscuit314 opened this issue Apr 10, 2023 · 2 comments · Fixed by #309
Closed

Have the ability to cancel a delete #305

biscuit314 opened this issue Apr 10, 2023 · 2 comments · Fixed by #309
Assignees
Labels
enhancement New feature or request

Comments

@biscuit314
Copy link

When the user clicks the "delete a node" button, sometimes we need to check first before completing the deletion. For example:

  • pop an "are you sure?" to give the user a chance to back out if she clicked delete in error
  • in the event deleting the backing item in a database or API fails

To allow for this, this feature request is for a new event treeNodeBeforeDelete which allows the application to perform the check then indicate whether the delete should be allowed to continue. For example:

<tree-view ... @treeNodeBeforeDelete="onBeforeDelete" ...>
...
function onBeforeDelete(target) {
    const answer = askAreYouSure()  // prompts user, returns boolean
    return answer
}

// OR
function onBeforeDelete(target) {
    const answer = askAreYouSure()
    if (answer === false) {
        target.cancelDeletion()  // or some other manipulation of the target node
    }
}
@biscuit314 biscuit314 added the enhancement New feature or request label Apr 10, 2023
@grapoza grapoza self-assigned this Apr 22, 2023
@grapoza
Copy link
Owner

grapoza commented Apr 22, 2023

@biscuit314 I'll probably merge this after the weekend, so if you get a chance to take a look and/or try out the solution let me know. I added a deleteNodeCallback property for the treeNodeSpec that gets called when the delete button is clicked and can return a boolean indicating whether to continue with deletion. If you checkout the source and run yarn storybook there's an Add Remove example with a very lazy Promise.resolve(window.confirm... implementation that should give you the gist of it.

@biscuit314
Copy link
Author

This is fantastic. I'll give it a try this week and let you know if I find anything!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants