Skip to content
Snippets Groups Projects
Commit 6e26f626 authored by ali asaria's avatar ali asaria
Browse files

bubble up delete event

parent d27c74fe
No related branches found
No related tags found
No related merge requests found
import { Typography } from '@mui/joy'; import { Typography } from '@mui/joy';
import { BuiltInNode, Handle } from '@xyflow/react'; import { BuiltInNode, Handle, useReactFlow } from '@xyflow/react';
import { NodeProps, Position } from '@xyflow/system'; import { NodeProps, Position } from '@xyflow/system';
import { XIcon } from 'lucide-react'; import { XIcon } from 'lucide-react';
...@@ -15,11 +15,18 @@ function chipColorByType(jobType: string) { ...@@ -15,11 +15,18 @@ function chipColorByType(jobType: string) {
} }
export default function memo({ export default function memo({
id,
data, data,
isConnectable, isConnectable,
targetPosition = Position.Top, targetPosition = Position.Top,
sourcePosition = Position.Bottom, sourcePosition = Position.Bottom,
}: NodeProps<BuiltInNode>) { }: NodeProps<BuiltInNode>) {
const { deleteElements } = useReactFlow();
const handleDelete = () => {
deleteElements({ nodes: [{ id }] });
};
return ( return (
<div className="custom-node" style={{ width: '100%' }}> <div className="custom-node" style={{ width: '100%' }}>
<div <div
...@@ -40,7 +47,7 @@ export default function memo({ ...@@ -40,7 +47,7 @@ export default function memo({
borderRadius: '50%', borderRadius: '50%',
}} }}
onClick={() => { onClick={() => {
alert('delete node: ' + data?.id); handleDelete();
}} }}
> >
<XIcon size="12px" /> <XIcon size="12px" />
......
...@@ -118,6 +118,11 @@ const Flow = ({ selectedWorkflow, setNewNodeModalOpen = (x) => {} }) => { ...@@ -118,6 +118,11 @@ const Flow = ({ selectedWorkflow, setNewNodeModalOpen = (x) => {} }) => {
zoomOnPinch={false} zoomOnPinch={false}
zoomOnDoubleClick={false} zoomOnDoubleClick={false}
panOnScroll={false} panOnScroll={false}
onDelete={({ nodes, edges }) => {
for (const node of nodes) {
alert('delete node: ' + node?.id);
}
}}
style={{ style={{
backgroundColor: 'var(--joy-palette-background-level2)', backgroundColor: 'var(--joy-palette-background-level2)',
}} }}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment