Skip to content

Commit

Permalink
refactor: Update Canvas component to include event handling for showi…
Browse files Browse the repository at this point in the history
…ng panel on label click
  • Loading branch information
trheyi committed Jun 4, 2024
1 parent 7756c16 commit e6a437e
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const Index = (props: IProps) => {
value,
nodes,
setNodes,
setEdges,
openPanel,
setOpenPanel,
showMask,
Expand Down Expand Up @@ -63,6 +64,28 @@ const Index = (props: IProps) => {
const hidePanel = () => {
setOpenPanel(() => false)
setShowMask(() => true)

if (panelNode) {
setNodes((nodes) => {
return nodes.map((node) => {
if (node.id === panelNode.id) {
node.selected = false
}
return node
})
})
}

if (panelEdge) {
setEdges((edges) => {
return edges.map((edge) => {
if (edge.id === panelEdge.id) {
edge.selected = false
}
return edge
})
})
}
}

const afterOpenChange = (open: boolean) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
text-overflow: ellipsis;
white-space: nowrap;
}
cursor: pointer;
}
}

Expand Down Expand Up @@ -75,5 +76,12 @@
font-size: 12px;
border-radius: 24px;
background: var(--color_border_soft);
cursor: move;
}
}

._type:hover {
:global {
background: var(--color_bg_menu);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type IProps = {
}

const CustomNode: FC<NodeProps> = ({ id, data }: IProps) => {
const { onDelete, onAdd, onDuplicate, onSettingNode, running } = useBuilderContext()
const { onDelete, onAdd, onDuplicate, onSettingNode, running, setNodes } = useBuilderContext()

data.showSourceHandle = data.showSourceHandle === undefined ? true : data.showSourceHandle
data.showTargetHandle = data.showTargetHandle === undefined ? true : data.showTargetHandle
Expand All @@ -41,7 +41,20 @@ const CustomNode: FC<NodeProps> = ({ id, data }: IProps) => {
<a className='item' onClick={() => onDuplicate(id)}>
<Icon name='material-content_copy' size={16} />
</a>
<a className='item' onClick={() => onSettingNode(id)}>
<a
className='item'
onClick={() => {
setNodes((nodes) => {
return nodes.map((node) => {
if (node.id === id) {
node.selected = true
}
return node
})
})
onSettingNode(id)
}}
>
<Icon name='material-settings' size={16} />
</a>

Expand All @@ -63,7 +76,7 @@ const CustomNode: FC<NodeProps> = ({ id, data }: IProps) => {
<div className='message'>{data.error}</div>
</div>
)}
<div className={clsx([styles._type])}>
<div className={clsx([styles._type, 'item-drag-handle'])}>
{data.icon && (
<Icon
name={data.icon?.name ? data.icon?.name : data.icon}
Expand All @@ -75,7 +88,21 @@ const CustomNode: FC<NodeProps> = ({ id, data }: IProps) => {
<div style={{ color: color }}>{data.typeLabel || data.type}</div>
</div>

<div className={clsx([styles._label, 'flex align_center label'])}>
<div
className={clsx([styles._label, 'flex align_center label'])}
onMouseDown={(event) => {
event.stopPropagation()
setNodes((nodes) => {
return nodes.map((node) => {
if (node.id === id) {
node.selected = true
}
return node
})
})
onSettingNode(id)
}}
>
{data.icon && data.running !== true && (
<Icon
name={data.icon?.name ? data.icon?.name : data.icon}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ const Flow = (props: IProps) => {
return (
<div className='reactflow-wrapper' ref={reactFlowWrapper}>
<ReactFlow
nodes={nodes}
nodes={nodes?.map((node) => {
if (!node.data) return node
node.dragHandle = '.item-drag-handle'
return node
})}
edges={edges}
onInit={setReactFlowInstance}
onPaneClick={() => setHideContextMenu && setHideContextMenu(true)}
Expand Down

0 comments on commit e6a437e

Please sign in to comment.