Skip to content

Image Pipeline Playground

feat(frontend/canvas): run pipeline up to selected node

Mohammad Rajaei09bdf6e51242
diff --git a/frontend/src/app/App.tsx b/frontend/src/app/App.tsx
index f102681..97bc642 100644
--- a/frontend/src/app/App.tsx
+++ b/frontend/src/app/App.tsx
@@ -1,12 +1,16 @@
import { Box } from '@mui/material'
-import { useRef } from 'react'
+import { useEffect, useRef } from 'react'
import { PipelineCanvas } from '../features/canvas/PipelineCanvas'
import { NodePalette } from '../features/palette/NodePalette'
import { NodeInspector } from '../features/inspector/NodeInspector'
import { CodePanel } from '../features/code/CodePanel'
import { ExecutionLogPanel } from '../features/execution/ExecutionLogPanel'
import { useGraphStore } from '../store/graphStore'
-import { requestCodegen, useExecutionSocket } from '../hooks/useExecutionSocket'
+import {
+ bindExecutionRunner,
+ requestCodegen,
+ useExecutionSocket,
+} from '../hooks/useExecutionSocket'
import { notifyError, notifyInfo, notifySuccess } from '../notify'
import { downloadWorkflowJson, parseWorkflowJson } from '../workflow/io'
import { AppHeader } from './AppHeader'
@@ -16,9 +20,12 @@ export default function App() {
const toWorkflowDocument = useGraphStore((s) => s.toWorkflowDocument)
const loadWorkflow = useGraphStore((s) => s.loadWorkflow)
const nodeCatalog = useGraphStore((s) => s.nodeCatalog)
+ const selectedNodeId = useGraphStore((s) => s.selectedNodeId)
const { run, cancel } = useExecutionSocket()
const fileInputRef = useRef<HTMLInputElement>(null)
+ useEffect(() => bindExecutionRunner(run), [run])
+
const onExportPython = async () => {
try {
const code = await requestCodegen()
@@ -96,7 +103,14 @@ export default function App() {
onChange={(event) => void onLoadWorkflowFile(event.target.files)}
/>
<AppHeader
- onRun={run}
+ onRun={() => run()}
+ onRunToSelected={() => {
+ if (!selectedNodeId) {
+ notifyError('Select a node first')
+ return
+ }
+ run({ targetNodeId: selectedNodeId })
+ }}
onCancel={cancel}
onExportPython={() => void onExportPython()}
onExportWorkflow={onExportWorkflow}
diff --git a/frontend/src/app/AppHeader.tsx b/frontend/src/app/AppHeader.tsx
index 7260006..4309255 100644
--- a/frontend/src/app/AppHeader.tsx
+++ b/frontend/src/app/AppHeader.tsx
@@ -124,6 +124,7 @@ function StatPill({ label, value }: { label: string; value: number }) {
interface AppHeaderProps {
onRun: () => void
+ onRunToSelected: () => void
onCancel: () => void
onExportPython: () => void
onExportWorkflow: () => void
@@ -151,6 +152,7 @@ const outlineBtnSx = {
export function AppHeader({
onRun,
+ onRunToSelected,
onCancel,
onExportPython,
onExportWorkflow,
@@ -162,6 +164,7 @@ export function AppHeader({
const setSeed = useGraphStore((s) => s.setSeed)
const setSampleCount = useGraphStore((s) => s.setSampleCount)
const isExecuting = useGraphStore((s) => s.isExecuting)
+ const selectedNodeId = useGraphStore((s) => s.selectedNodeId)
const nodeCount = useGraphStore((s) => s.nodes.length)
const edgeCount = useGraphStore((s) => s.edges.length)
const [infoOpen, setInfoOpen] = useState(false)
@@ -368,6 +371,15 @@ export function AppHeader({
</Box>
</Button>
+ <Button
+ variant="outlined"
+ disabled={isExecuting || !selectedNodeId}
+ onClick={onRunToSelected}
+ sx={outlineBtnSx}
+ >
+ Run to selected
+ </Button>
+
<Button
variant="outlined"
disabled={isExecuting}
diff --git a/frontend/src/features/canvas/NodeMenu.tsx b/frontend/src/features/canvas/NodeMenu.tsx
index b0d3941..8eafdba 100644
--- a/frontend/src/features/canvas/NodeMenu.tsx
+++ b/frontend/src/features/canvas/NodeMenu.tsx
@@ -11,6 +11,7 @@ import {
Typography,
} from '@mui/material'
import { useGraphStore } from '../../store/graphStore'
+import { runPipeline } from '../../hooks/useExecutionSocket'
type MenuAnchor =
| { kind: 'element'; el: HTMLElement }
@@ -69,6 +70,7 @@ export function useNodeMenu({
const removeNode = useGraphStore((state) => state.removeNode)
const duplicateNode = useGraphStore((state) => state.duplicateNode)
const selectNode = useGraphStore((state) => state.selectNode)
+ const isExecuting = useGraphStore((state) => state.isExecuting)
const open = Boolean(anchor)
const isMac =
typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform)
@@ -96,6 +98,12 @@ export function useNodeMenu({
[nodeId, selectNode],
)
+ const runToHere = useCallback(() => {
+ close()
+ if (isExecuting) return
+ runPipeline({ targetNodeId: nodeId })
+ }, [close, isExecuting, nodeId])
+
const runDuplicate = useCallback(() => {
duplicateNode(nodeId)
close()
@@ -226,6 +234,27 @@ export function useNodeMenu({
</Typography>
</Box>
+ <MenuItem
+ className="nodrag nopan"
+ disabled={isExecuting}
+ onClick={runToHere}
+ sx={{
+ mx: 0.5,
+ mt: 0.5,
+ borderRadius: 1,
+ py: 1,
+ '&:hover': { bgcolor: 'rgba(230,126,34,0.14)' },
+ }}
+ >
+ <ListItemIcon sx={{ minWidth: 40 }}>
+ <MenuGlyph>▶</MenuGlyph>
+ </ListItemIcon>
+ <ListItemText
+ primary="Run to here"
+ slotProps={{ primary: { sx: { fontSize: 13, fontWeight: 600 } } }}
+ />
+ </MenuItem>
+
<MenuItem
className="nodrag nopan"
onClick={runDuplicate}
diff --git a/frontend/src/hooks/useExecutionSocket.ts b/frontend/src/hooks/useExecutionSocket.ts
index 119570a..e534338 100644
--- a/frontend/src/hooks/useExecutionSocket.ts
+++ b/frontend/src/hooks/useExecutionSocket.ts
@@ -7,6 +7,25 @@ export type RunOptions = {
targetNodeId?: string
}
+type Runner = (options?: RunOptions) => void
+
+let sharedRunner: Runner | null = null
+
+/** Bind the App-level socket runner so menus can trigger targeted runs. */
+export function bindExecutionRunner(run: Runner) {
+ sharedRunner = run
+ return () => {
+ if (sharedRunner === run) sharedRunner = null
+ }
+}
+
+export function runPipeline(options?: RunOptions) {
+ if (!sharedRunner) {
+ throw new Error('Execution runner is not ready')
+ }
+ sharedRunner(options)
+}
+
export function useExecutionSocket() {
const socketRef = useRef<WebSocket | null>(null)
const clearExecution = useGraphStore((s) => s.clearExecution)
@@ -90,11 +109,15 @@ export function useExecutionSocket() {
if (event.type === 'done') {
appendLog(event.message ?? 'done')
const target = targetLabelRef.current
- notifySuccess(
- target
- ? `Ran to ${target}`
- : (event.message ?? 'Pipeline finished'),
- )
+ if (target) {
+ const node = useGraphStore
+ .getState()
+ .nodes.find((item) => item.id === target)
+ const label = node?.data.label ?? target
+ notifySuccess(`Ran to ${label}`)
+ } else {
+ notifySuccess(event.message ?? 'Pipeline finished')
+ }
targetLabelRef.current = null
setIsExecuting(false)
setActiveNodeId(null)