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

onbeforedelete should give back event #4116

Open
mcmxcdev opened this issue Apr 5, 2024 · 3 comments
Open

onbeforedelete should give back event #4116

mcmxcdev opened this issue Apr 5, 2024 · 3 comments
Labels
feature request New feature or request svelte svelte flow related

Comments

@mcmxcdev
Copy link

mcmxcdev commented Apr 5, 2024

Please describe the feature that you want to propose

Whenever the user hits deleteKey, we don't delete the nodes/edges right away but let the user confirm the action in a confirmation dialog which gets invoked through onbeforedelete . Once the deletion is confirmed, we trigger deleteElements programmatically to delete these elements.

Unfortunately, deleteElements triggers onbeforedelete yet again, where we have to work around it with a hack to not open the confirmation dialog twice.

onbeforedelete currently gives back values like this: onbeforedelete={({ nodes, edges }) => {. If it would additionally give us back the event so we know if it was called by the user hitting the configured deleteKey or not, that would make our code much simpler.

Actually, probably all the custom event handlers of Svelteflow should give back event.

@mcmxcdev mcmxcdev added the feature request New feature or request label Apr 5, 2024
@peterkogo peterkogo added the svelte svelte flow related label Apr 11, 2024
@peterkogo
Copy link
Member

@mcmxcdev You can just return true inside the onbeforedelete handler so the elements get deleted (false if deletion has not been confirmed). There is no need to actually programmatically delete the elements.

However, I still see you point. I assume there might be a reason to delete those elements programmatically, or to simply distinguish what has triggered the deletion (user input vs. program).

What do you think about an optional force parameter for deleteElements that skips onbeforedelete?

@mcmxcdev
Copy link
Author

It's not that we trigger an async request in onbeforedelete that needs to be awaited until it can be deleted. It's a modal window that might or might not confirm the deletion. So we are taken completely out of the flow of onbeforedelete, hence we need programatical deletion.

However, I still see you point. I assume there might be a reason to delete those elements programmatically, or to simply distinguish what has triggered the deletion (user input vs. program).

Yes, 100%

What do you think about an optional force parameter for deleteElements that skips onbeforedelete?

That would sound reasonable to fix the issue I am experiencing, but other users might run into situations where they would need event exposed for other use cases, so I would still consider that important.

@peterkogo
Copy link
Member

peterkogo commented May 7, 2024

@mcmxcdev I don't think I understand what it means to be "completely out of the flow". You can pass an async function to onbeforedelete from an element outside of the flow. You can also create a promise and resolve it elsewhere.
If you can help me out by creating a sandbox which illustrates your issue, I believe I can show you how to do it.

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

No branches or pull requests

2 participants