Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/main/frontend/app/routes/studio/canvas/flow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@
}, [])

const { nodes, edges, onNodesChange, onEdgesChange, onConnect, onReconnect } = useFlowStore(useShallow(selector))
const project = useProjectStore.getState().project

Check warning on line 260 in src/main/frontend/app/routes/studio/canvas/flow.tsx

View workflow job for this annotation

GitHub Actions / Build & Run All Tests

'project' is assigned a value but never used. Allowed unused vars must match /^_/u
Comment thread
stijnpotters1 marked this conversation as resolved.
Outdated

const saveFlow = useCallback(async () => {
const { nodes: flowNodes, edges: flowEdges, viewport: flowViewport } = useFlowStore.getState()
Expand Down Expand Up @@ -321,7 +321,7 @@
logApiError('Failed to save XML', error as Error)
setIdle()
}
}, [])

Check warning on line 324 in src/main/frontend/app/routes/studio/canvas/flow.tsx

View workflow job for this annotation

GitHub Actions / Build & Run All Tests

React Hook useCallback has missing dependencies: 'setIdle', 'setSaved', and 'setSaving'. Either include them or remove the dependency array

const autosaveEnabled = useSettingsStore((s) => s.general.autoSave.enabled)
const autosaveDelay = useSettingsStore((s) => s.general.autoSave.delayMs)
Expand Down Expand Up @@ -825,6 +825,17 @@

const deleteSelection = useCallback((): boolean => {
if (isEditing) return false

const { parentId: storeParentId, nodeId: storeNodeId } = useNodeContextStore.getState()
if (storeParentId !== null) {
useFlowStore.getState().deleteChild(storeParentId, storeNodeId.toString())
useNodeContextStore.getState().setParentId(null)
useNodeContextStore.getState().setChildParentId(null)
useNodeContextStore.getState().setNodeId(0)
showNodeContextMenu(false)
return true
}

const { nodes, edges, setNodes, setEdges } = useFlowStore.getState()
const selectedNodeIds = new Set(nodes.filter((n) => n.selected).map((n) => n.id))
const hasSelection = selectedNodeIds.size > 0 || edges.some((e) => e.selected)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
child: ChildNode
gradientEnabled: boolean
onEdit: (id: string) => void
onSelect: (id: string) => void
parentId: string
rootId: string
}
Expand All @@ -28,11 +29,23 @@
child,
gradientEnabled,
onEdit,
onSelect,
parentId,
rootId,
}: Readonly<ChildNodeProperties>) {
const { setParentId, setChildParentId, setIsEditing, setDraggedName, draggedName, setNodeId, setAttributes } =
useNodeContextStore()
const {
setParentId,
setChildParentId,
setIsEditing,
setDraggedName,
draggedName,
setNodeId,
setAttributes,
nodeId,
parentId: selectedParentId,
isDirty,
} = useNodeContextStore()
const isSelected = nodeId === +child.id && selectedParentId !== null
const showNodeContextMenu = useNodeContextMenu()
const addChildToChild = useFlowStore((state) => state.addChildToChild)
const [dragOver, setDragOver] = useState(false)
Expand Down Expand Up @@ -125,7 +138,7 @@
// Add child recursively
addChildToChild(rootId, child.id, newChild)
},
[

Check warning on line 141 in src/main/frontend/app/routes/studio/canvas/nodetypes/child-node.tsx

View workflow job for this annotation

GitHub Actions / Build & Run All Tests

React Hook useCallback has missing dependencies: 'setAttributes' and 'setNodeId'. Either include them or remove the dependency array
setDraggedName,
canAcceptChild,
showNodeContextMenu,
Expand Down Expand Up @@ -158,12 +171,19 @@
return (
<div
data-childnode-id={child.id}
className={`bg-background relative mr-0.5 mb-2 rounded-md border ${dragForbidden ? 'border-2 border-dashed' : 'border-border'}`}
className={`bg-background relative mr-0.5 mb-2 rounded-md border ${isSelected ? 'border-1' : dragForbidden ? 'border-2 border-dashed' : 'border-border'}`}

Check failure on line 174 in src/main/frontend/app/routes/studio/canvas/nodetypes/child-node.tsx

View workflow job for this annotation

GitHub Actions / Build & Run All Tests

Nested ternary expression should be parenthesized
Comment thread
stijnpotters1 marked this conversation as resolved.
Outdated
style={isSelected ? { borderColor: `var(--type-${child.type?.toLowerCase()})` } : undefined}
onDragOver={handleDragOver}
onDragLeave={handleDragLeave}
onDrop={handleDrop}
onClick={(mouseEvent) => {
mouseEvent.stopPropagation()
if (isDirty) return
onSelect(child.id)
}}
onDoubleClick={(event) => {
event.stopPropagation()
if (isDirty) return
onEdit(child.id)
}}
>
Expand Down Expand Up @@ -203,6 +223,7 @@
child={nested}
gradientEnabled={gradientEnabled}
onEdit={onEdit}
onSelect={onSelect}
parentId={child.id}
rootId={rootId}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
type NodeProps,
NodeResizeControl,
Position,
useReactFlow,
useStore,
useUpdateNodeInternals,
} from '@xyflow/react'
Expand Down Expand Up @@ -101,6 +102,7 @@
const [mandatoryChildrenFulfilled, setMandatoryChildrenFulfilled] = useState(false)
const [missingChildren, setMissingChildren] = useState<string[]>([])

const reactFlow = useReactFlow()
const updateNodeInternals = useUpdateNodeInternals()
const [isHandleMenuOpen, setIsHandleMenuOpen] = useState(false)
const [handleMenuPosition, setHandleMenuPosition] = useState({ x: 0, y: 0 })
Expand Down Expand Up @@ -243,6 +245,24 @@
setIsEditing(true)
}

const selectChild = (childId: string) => {
const child = findChildRecursive(properties.data.children, childId)
if (!child) return

const recordElements = elements as Record<string, ElementDetails>
const attributes = Object.values(recordElements).find((element) => element.name === child.subtype)?.attributes

const isFirstLevel = properties.data.children.some((childNode) => childNode.id === childId)
setParentId(properties.id)
setChildParentId(isFirstLevel ? null : properties.id)
setNodeId(+childId)
setAttributes(attributes)
setEditingSubtype(child.subtype)
showNodeContextMenu(true)

reactFlow.setNodes((nodes) => nodes.map((node) => ({ ...node, selected: false })))
}

const changeHandleType = (handleIndex: number, newType: string) => {
// Prevent changing to a duplicate handle type
const existing = properties.data.sourceHandles.some(
Expand Down Expand Up @@ -322,7 +342,7 @@

addChild(properties.id, child)
},
[

Check warning on line 345 in src/main/frontend/app/routes/studio/canvas/nodetypes/frank-node.tsx

View workflow job for this annotation

GitHub Actions / Build & Run All Tests

React Hook useCallback has missing dependencies: 'setAttributes' and 'setNodeId'. Either include them or remove the dependency array
properties.id,
addChild,
setIsNewNode,
Expand Down Expand Up @@ -514,6 +534,7 @@
child={child}
gradientEnabled={gradientEnabled}
onEdit={editChild}
onSelect={selectChild}
parentId={properties.id}
rootId={properties.id}
/>
Expand Down
Loading