Skip to content

Commit fff3a6f

Browse files
authored
Ungrouping nodes by selecting group node itself (#427)
1 parent 6d005c3 commit fff3a6f

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

src/main/frontend/app/routes/studio/canvas/flow.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,11 +689,29 @@ function FlowCanvas() {
689689
}, [copySelection])
690690

691691
const handleUngroup = useCallback(() => {
692-
const selectedNodes = nodes.filter((n) => n.selected)
692+
const flowStore = useFlowStore.getState()
693+
const selectedNodes = flowStore.nodes.filter((n) => n.selected)
694+
693695
if (selectedNodes.length === 0) return
696+
const selectedGroupNodes = selectedNodes.filter((n) => n.type === 'groupNode')
697+
698+
if (selectedGroupNodes.length > 0) {
699+
let updatedNodes = [...flowStore.nodes]
700+
for (const groupNode of selectedGroupNodes) {
701+
const groupId = groupNode.id
702+
703+
const children = updatedNodes.filter((n) => n.parentId === groupId)
704+
705+
updatedNodes = degroupNodes(children, groupId, updatedNodes)
706+
}
707+
flowStore.setNodes(updatedNodes)
708+
return
709+
}
710+
694711
if (!allSelectedInSameGroup(selectedNodes)) return
712+
695713
handleDegroupSingleGroup(selectedNodes)
696-
}, [nodes, allSelectedInSameGroup, handleDegroupSingleGroup])
714+
}, [allSelectedInSameGroup, handleDegroupSingleGroup, degroupNodes])
697715

698716
const handleRightMouseButtonClick = useCallback(
699717
(event: React.MouseEvent) => {

src/main/frontend/app/routes/studio/canvas/nodetypes/group-node.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ export default function GroupNodeComponent({ id, data, selected }: NodeProps<Gro
6262
<div className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2">
6363
<HamburgerMenu />
6464
</div>
65+
6566
<div className="flex max-w-1/2 gap-1 px-2 py-1 text-sm font-bold">
6667
{isEditing ? (
6768
<input

0 commit comments

Comments
 (0)