Skip to content

Image Pipeline Playground

feat(frontend/header): add export and load workflow buttons

Mohammad Rajaei18881d42e9c3
diff --git a/frontend/src/app/App.tsx b/frontend/src/app/App.tsx
index fa94041..24fc06a 100644
--- a/frontend/src/app/App.tsx
+++ b/frontend/src/app/App.tsx
@@ -1,18 +1,24 @@
import { Box } from '@mui/material'
+import { 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 { useGraphStore } from '../store/graphStore'
import { requestCodegen, useExecutionSocket } from '../hooks/useExecutionSocket'
-import { notifyError, notifySuccess } from '../notify'
+import { notifyError, notifyInfo, notifySuccess } from '../notify'
+import { downloadWorkflowJson, parseWorkflowJson } from '../workflow/io'
import { AppHeader } from './AppHeader'
export default function App() {
const setGeneratedCode = useGraphStore((s) => s.setGeneratedCode)
+ const toWorkflowDocument = useGraphStore((s) => s.toWorkflowDocument)
+ const loadWorkflow = useGraphStore((s) => s.loadWorkflow)
+ const nodeCatalog = useGraphStore((s) => s.nodeCatalog)
const { run, cancel } = useExecutionSocket()
+ const fileInputRef = useRef<HTMLInputElement>(null)
- const onExport = async () => {
+ const onExportPython = async () => {
try {
const code = await requestCodegen()
setGeneratedCode(code)
@@ -22,12 +28,57 @@ export default function App() {
}
}
+ const onExportWorkflow = () => {
+ try {
+ downloadWorkflowJson(toWorkflowDocument())
+ notifySuccess('Workflow exported')
+ } catch (error) {
+ notifyError(error instanceof Error ? error.message : 'Export failed')
+ }
+ }
+
+ const onLoadWorkflowClick = () => {
+ if (nodeCatalog.length === 0) {
+ notifyError('Node catalog is still loading — try again in a moment')
+ return
+ }
+ fileInputRef.current?.click()
+ }
+
+ const onLoadWorkflowFile = async (fileList: FileList | null) => {
+ const file = fileList?.[0]
+ if (!file) return
+ try {
+ const text = await file.text()
+ const doc = parseWorkflowJson(text)
+ const { skippedTypes } = loadWorkflow(doc)
+ if (skippedTypes.length > 0) {
+ notifyInfo(`Workflow loaded (skipped unknown nodes: ${skippedTypes.join(', ')})`)
+ } else {
+ notifySuccess('Workflow loaded')
+ }
+ } catch (error) {
+ notifyError(error instanceof Error ? error.message : 'Load failed')
+ } finally {
+ if (fileInputRef.current) fileInputRef.current.value = ''
+ }
+ }
+
return (
<Box sx={{ display: 'flex', flexDirection: 'column', height: '100vh', bgcolor: '#0f0f0f' }}>
+ <input
+ ref={fileInputRef}
+ type="file"
+ accept="application/json,.json"
+ hidden
+ onChange={(event) => void onLoadWorkflowFile(event.target.files)}
+ />
<AppHeader
onRun={run}
onCancel={cancel}
- onExport={() => void onExport()}
+ onExportPython={() => void onExportPython()}
+ onExportWorkflow={onExportWorkflow}
+ onLoadWorkflow={onLoadWorkflowClick}
/>
<Box
diff --git a/frontend/src/app/AppHeader.tsx b/frontend/src/app/AppHeader.tsx
index 10d18c4..ecd6a66 100644
--- a/frontend/src/app/AppHeader.tsx
+++ b/frontend/src/app/AppHeader.tsx
@@ -122,10 +122,36 @@ function StatPill({ label, value }: { label: string; value: number }) {
interface AppHeaderProps {
onRun: () => void
onCancel: () => void
- onExport: () => void
+ onExportPython: () => void
+ onExportWorkflow: () => void
+ onLoadWorkflow: () => void
}
-export function AppHeader({ onRun, onCancel, onExport }: AppHeaderProps) {
+const outlineBtnSx = {
+ height: 36,
+ px: 1.75,
+ borderRadius: 1.25,
+ textTransform: 'none',
+ fontWeight: 650,
+ color: '#f0ebe3',
+ borderColor: 'rgba(255,255,255,0.16)',
+ '&:hover': {
+ borderColor: 'rgba(125,206,160,0.45)',
+ bgcolor: 'rgba(125,206,160,0.08)',
+ },
+ '&.Mui-disabled': {
+ color: 'rgba(255,255,255,0.3)',
+ borderColor: 'rgba(255,255,255,0.08)',
+ },
+} as const
+
+export function AppHeader({
+ onRun,
+ onCancel,
+ onExportPython,
+ onExportWorkflow,
+ onLoadWorkflow,
+}: AppHeaderProps) {
const seed = useGraphStore((s) => s.seed)
const sampleCount = useGraphStore((s) => s.sampleCount)
const setSeed = useGraphStore((s) => s.setSeed)
@@ -291,24 +317,26 @@ export function AppHeader({ onRun, onCancel, onExport }: AppHeaderProps) {
<Button
variant="outlined"
disabled={isExecuting}
- onClick={onExport}
- sx={{
- height: 36,
- px: 1.75,
- borderRadius: 1.25,
- textTransform: 'none',
- fontWeight: 650,
- color: '#f0ebe3',
- borderColor: 'rgba(255,255,255,0.16)',
- '&:hover': {
- borderColor: 'rgba(125,206,160,0.45)',
- bgcolor: 'rgba(125,206,160,0.08)',
- },
- '&.Mui-disabled': {
- color: 'rgba(255,255,255,0.3)',
- borderColor: 'rgba(255,255,255,0.08)',
- },
- }}
+ onClick={onLoadWorkflow}
+ sx={outlineBtnSx}
+ >
+ Load
+ </Button>
+
+ <Button
+ variant="outlined"
+ disabled={isExecuting}
+ onClick={onExportWorkflow}
+ sx={outlineBtnSx}
+ >
+ Export
+ </Button>
+
+ <Button
+ variant="outlined"
+ disabled={isExecuting}
+ onClick={onExportPython}
+ sx={outlineBtnSx}
>
Export Python
</Button>