Skip to content

Image Pipeline Playground

feat(frontend/canvas): add Projects dialog for save and load

Mohammad Rajaei4e8d812315d0
diff --git a/frontend/src/app/App.tsx b/frontend/src/app/App.tsx
index 0e77352..0969d2b 100644
--- a/frontend/src/app/App.tsx
+++ b/frontend/src/app/App.tsx
@@ -6,6 +6,7 @@ import { NodeInspector } from '../features/inspector/NodeInspector'
import { CodePanel } from '../features/code/CodePanel'
import { ExecutionLogPanel } from '../features/execution/ExecutionLogPanel'
import { PreviewGrid } from '../features/preview/PreviewGrid'
+import { ProjectsDialog } from '../features/projects/ProjectsDialog'
import { TemplateGallery } from '../features/templates/TemplateGallery'
import { useGraphStore } from '../store/graphStore'
import {
@@ -17,19 +18,23 @@ import { useWorkflowPersistence } from '../hooks/useWorkflowPersistence'
import { notifyError, notifyInfo, notifySuccess } from '../notify'
import { downloadWorkflowJson, parseWorkflowJson } from '../workflow/io'
import { materializeSampleImages } from '../workflow/materializeSampleImages'
+import {
+ confirmDiscardIfDirty,
+ loadExternalDocument,
+} from '../workflow/projectActions'
import type { WorkflowTemplate } from '../workflow/templates'
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 selectedNodeId = useGraphStore((s) => s.selectedNodeId)
const isExecuting = useGraphStore((s) => s.isExecuting)
const { run, cancel } = useExecutionSocket()
const fileInputRef = useRef<HTMLInputElement>(null)
const [templatesOpen, setTemplatesOpen] = useState(false)
+ const [projectsOpen, setProjectsOpen] = useState(false)
const [sideTab, setSideTab] = useState(0)
useEffect(() => bindExecutionRunner(run), [run])
@@ -54,9 +59,16 @@ export default function App() {
}
}
- const applyLoadedWorkflow = async (text: string, successMessage: string) => {
+ const applyLoadedWorkflow = async (
+ text: string,
+ successMessage: string,
+ nameOverride?: string,
+ ) => {
const doc = parseWorkflowJson(text)
- const { skippedTypes } = loadWorkflow(doc)
+ const { skippedTypes } = loadExternalDocument(
+ doc,
+ nameOverride ? { name: nameOverride } : undefined,
+ )
await materializeSampleImages()
if (skippedTypes.length > 0) {
notifyInfo(`${successMessage} (skipped unknown nodes: ${skippedTypes.join(', ')})`)
@@ -70,6 +82,7 @@ export default function App() {
notifyError('Node catalog is still loading — try again in a moment')
return
}
+ if (!confirmDiscardIfDirty()) return
fileInputRef.current?.click()
}
@@ -79,6 +92,7 @@ export default function App() {
try {
const text = await file.text()
await applyLoadedWorkflow(text, 'Workflow loaded')
+ setProjectsOpen(false)
} catch (error) {
notifyError(error instanceof Error ? error.message : 'Load failed')
} finally {
@@ -94,14 +108,19 @@ export default function App() {
setTemplatesOpen(true)
}
+ const onOpenProjects = () => {
+ setProjectsOpen(true)
+ }
+
const onSelectTemplate = async (template: WorkflowTemplate) => {
+ if (!confirmDiscardIfDirty()) return
try {
const response = await fetch(template.path)
if (!response.ok) {
throw new Error(`Could not fetch template (${response.status})`)
}
const text = await response.text()
- await applyLoadedWorkflow(text, `Loaded “${template.name}”`)
+ await applyLoadedWorkflow(text, `Loaded “${template.name}”`, template.name)
setTemplatesOpen(false)
} catch (error) {
notifyError(error instanceof Error ? error.message : 'Template load failed')
@@ -131,6 +150,13 @@ export default function App() {
onExportWorkflow={onExportWorkflow}
onLoadWorkflow={onLoadWorkflowClick}
onOpenTemplates={onOpenTemplates}
+ onOpenProjects={onOpenProjects}
+ />
+ <ProjectsDialog
+ open={projectsOpen}
+ onClose={() => setProjectsOpen(false)}
+ onImportFile={onLoadWorkflowClick}
+ disabled={isExecuting}
/>
<TemplateGallery
open={templatesOpen}
diff --git a/frontend/src/app/AppHeader.tsx b/frontend/src/app/AppHeader.tsx
index 89ff8d8..5b7a117 100644
--- a/frontend/src/app/AppHeader.tsx
+++ b/frontend/src/app/AppHeader.tsx
@@ -132,6 +132,7 @@ interface AppHeaderProps {
onExportWorkflow: () => void
onLoadWorkflow: () => void
onOpenTemplates: () => void
+ onOpenProjects: () => void
}
const outlineBtnSx = {
@@ -160,6 +161,7 @@ export function AppHeader({
onExportWorkflow,
onLoadWorkflow,
onOpenTemplates,
+ onOpenProjects,
}: AppHeaderProps) {
const seed = useGraphStore((s) => s.seed)
const sampleCount = useGraphStore((s) => s.sampleCount)
@@ -169,6 +171,8 @@ export function AppHeader({
const selectedNodeId = useGraphStore((s) => s.selectedNodeId)
const nodeCount = useGraphStore((s) => s.nodes.length)
const edgeCount = useGraphStore((s) => s.edges.length)
+ const projectName = useGraphStore((s) => s.projectName)
+ const projectDirty = useGraphStore((s) => s.projectDirty)
const [infoOpen, setInfoOpen] = useState(false)
const [exportAnchor, setExportAnchor] = useState<null | HTMLElement>(null)
const exportMenuOpen = Boolean(exportAnchor)
@@ -264,6 +268,49 @@ export function AppHeader({
>
i
</IconButton>
+ <Box
+ sx={{
+ display: { xs: 'none', sm: 'flex' },
+ flexDirection: 'column',
+ minWidth: 0,
+ maxWidth: 220,
+ ml: 0.5,
+ pl: 1.25,
+ borderLeft: '1px solid rgba(255,255,255,0.1)',
+ }}
+ >
+ <Typography
+ sx={{
+ fontSize: 10,
+ fontWeight: 700,
+ letterSpacing: '0.08em',
+ textTransform: 'uppercase',
+ color: 'rgba(244,241,234,0.4)',
+ lineHeight: 1.2,
+ }}
+ >
+ Project
+ </Typography>
+ <Typography
+ title={projectName}
+ sx={{
+ fontSize: 13,
+ fontWeight: 650,
+ color: '#f4f1ea',
+ lineHeight: 1.25,
+ overflow: 'hidden',
+ textOverflow: 'ellipsis',
+ whiteSpace: 'nowrap',
+ }}
+ >
+ {projectName}
+ {projectDirty ? (
+ <Box component="span" sx={{ color: '#e67e22', ml: 0.35 }}>
+ *
+ </Box>
+ ) : null}
+ </Typography>
+ </Box>
</Stack>
<ProjectInfoModal open={infoOpen} onClose={() => setInfoOpen(false)} />
@@ -412,6 +459,15 @@ export function AppHeader({
border: '1px solid rgba(255,255,255,0.06)',
}}
>
+ <Button
+ variant="outlined"
+ disabled={isExecuting}
+ onClick={onOpenProjects}
+ sx={outlineBtnSx}
+ >
+ Projects
+ </Button>
+
<Button
variant="outlined"
disabled={isExecuting}
diff --git a/frontend/src/features/inspector/NodeInspector.tsx b/frontend/src/features/inspector/NodeInspector.tsx
index 3261d43..55d924b 100644
--- a/frontend/src/features/inspector/NodeInspector.tsx
+++ b/frontend/src/features/inspector/NodeInspector.tsx
@@ -83,7 +83,7 @@ export function NodeInspector() {
>
<li>Connect matching port types (image, mask, bboxes, keypoints)</li>
<li>Press Run to execute with live previews</li>
- <li>Export saves workflow JSON; Export Python codegen</li>
+ <li>Projects saves named pipelines; Export downloads JSON / Python</li>
</Box>
</Box>
)
diff --git a/frontend/src/features/projects/ProjectsDialog.tsx b/frontend/src/features/projects/ProjectsDialog.tsx
new file mode 100644
index 0000000..68d1bee
--- /dev/null
+++ b/frontend/src/features/projects/ProjectsDialog.tsx
@@ -0,0 +1,535 @@
+import { useState } from 'react'
+import {
+ Box,
+ Button,
+ Dialog,
+ DialogContent,
+ IconButton,
+ Stack,
+ TextField,
+ Typography,
+} from '@mui/material'
+import { useGraphStore } from '../../store/graphStore'
+import { notifyError, notifyInfo, notifySuccess } from '../../notify'
+import { downloadWorkflowJson } from '../../workflow/io'
+import {
+ confirmDiscardIfDirty,
+ deleteProjectById,
+ listProjects,
+ newProject,
+ openProject,
+ type ProjectRecord,
+ renameActiveProject,
+ saveProject,
+ saveProjectAs,
+} from '../../workflow/projectActions'
+
+type ProjectsDialogProps = {
+ open: boolean
+ onClose: () => void
+ onImportFile: () => void
+ disabled?: boolean
+}
+
+type PromptMode = 'saveAs' | 'rename' | null
+
+const outlineBtnSx = {
+ height: 34,
+ px: 1.5,
+ 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
+
+function formatUpdatedAt(value: string): string {
+ try {
+ return new Intl.DateTimeFormat(undefined, {
+ dateStyle: 'medium',
+ timeStyle: 'short',
+ }).format(new Date(value))
+ } catch {
+ return value
+ }
+}
+
+function ProjectRow({
+ project,
+ active,
+ disabled,
+ onOpen,
+ onDelete,
+}: {
+ project: ProjectRecord
+ active: boolean
+ disabled?: boolean
+ onOpen: () => void
+ onDelete: () => void
+}) {
+ const nodeCount = project.graph.nodes.length
+ return (
+ <Box
+ sx={{
+ display: 'flex',
+ alignItems: 'stretch',
+ gap: 1,
+ p: 1.5,
+ borderRadius: 1.75,
+ border: '1px solid',
+ borderColor: active ? 'rgba(125,206,160,0.45)' : 'rgba(255,255,255,0.1)',
+ bgcolor: active ? 'rgba(125,206,160,0.08)' : 'rgba(255,255,255,0.02)',
+ }}
+ >
+ <Box sx={{ flex: 1, minWidth: 0 }}>
+ <Typography
+ sx={{
+ fontFamily: '"Fraunces", Georgia, serif',
+ fontWeight: 700,
+ fontSize: 16,
+ letterSpacing: '-0.02em',
+ color: '#f4f1ea',
+ lineHeight: 1.2,
+ }}
+ >
+ {project.name}
+ {active ? (
+ <Box
+ component="span"
+ sx={{
+ ml: 1,
+ fontFamily: 'inherit',
+ fontSize: 11,
+ fontWeight: 700,
+ letterSpacing: '0.06em',
+ textTransform: 'uppercase',
+ color: '#7dcea0',
+ }}
+ >
+ Open
+ </Box>
+ ) : null}
+ </Typography>
+ {project.description ? (
+ <Typography
+ sx={{
+ mt: 0.5,
+ fontSize: 12.5,
+ color: 'rgba(244,241,234,0.52)',
+ lineHeight: 1.4,
+ }}
+ >
+ {project.description}
+ </Typography>
+ ) : null}
+ <Typography
+ sx={{
+ mt: 0.75,
+ fontSize: 11,
+ color: 'rgba(244,241,234,0.38)',
+ fontVariantNumeric: 'tabular-nums',
+ }}
+ >
+ {nodeCount} node{nodeCount === 1 ? '' : 's'} · Updated {formatUpdatedAt(project.updatedAt)}
+ </Typography>
+ </Box>
+ <Stack spacing={0.75} sx={{ justifyContent: 'center' }}>
+ <Button
+ size="small"
+ variant="outlined"
+ disabled={disabled || active}
+ onClick={onOpen}
+ sx={{ ...outlineBtnSx, height: 30, px: 1.25, fontSize: 12 }}
+ >
+ Open
+ </Button>
+ <Button
+ size="small"
+ variant="outlined"
+ disabled={disabled}
+ onClick={onDelete}
+ sx={{
+ ...outlineBtnSx,
+ height: 30,
+ px: 1.25,
+ fontSize: 12,
+ color: '#ff8a80',
+ borderColor: 'rgba(255,138,128,0.28)',
+ '&:hover': {
+ borderColor: 'rgba(255,138,128,0.55)',
+ bgcolor: 'rgba(192,57,43,0.12)',
+ },
+ }}
+ >
+ Delete
+ </Button>
+ </Stack>
+ </Box>
+ )
+}
+
+export function ProjectsDialog({
+ open,
+ onClose,
+ onImportFile,
+ disabled,
+}: ProjectsDialogProps) {
+ const projectId = useGraphStore((s) => s.projectId)
+ const projectName = useGraphStore((s) => s.projectName)
+ const projectDescription = useGraphStore((s) => s.projectDescription)
+ const projectDirty = useGraphStore((s) => s.projectDirty)
+ const toWorkflowDocument = useGraphStore((s) => s.toWorkflowDocument)
+ const [projects, setProjects] = useState<ProjectRecord[]>([])
+ const [promptMode, setPromptMode] = useState<PromptMode>(null)
+ const [promptName, setPromptName] = useState('')
+ const [promptDescription, setPromptDescription] = useState('')
+
+ const refresh = () => setProjects(listProjects())
+
+ const closePrompt = () => {
+ setPromptMode(null)
+ setPromptName('')
+ setPromptDescription('')
+ }
+
+ const handleEnter = () => {
+ refresh()
+ closePrompt()
+ }
+
+ const handleClose = () => {
+ closePrompt()
+ onClose()
+ }
+
+ const onNew = () => {
+ if (!confirmDiscardIfDirty()) return
+ newProject()
+ refresh()
+ notifySuccess('New project')
+ }
+
+ const onOpen = (id: string) => {
+ if (id === projectId && !projectDirty) {
+ handleClose()
+ return
+ }
+ if (!confirmDiscardIfDirty()) return
+ try {
+ const { skippedTypes } = openProject(id)
+ refresh()
+ if (skippedTypes.length > 0) {
+ notifyInfo(`Opened project (skipped unknown nodes: ${skippedTypes.join(', ')})`)
+ } else {
+ notifySuccess('Project opened')
+ }
+ handleClose()
+ } catch (error) {
+ notifyError(error instanceof Error ? error.message : 'Could not open project')
+ }
+ }
+
+ const onSave = () => {
+ try {
+ if (!projectId) {
+ setPromptMode('saveAs')
+ setPromptName(projectName)
+ setPromptDescription(projectDescription)
+ return
+ }
+ saveProject()
+ refresh()
+ notifySuccess('Project saved')
+ } catch (error) {
+ notifyError(error instanceof Error ? error.message : 'Save failed')
+ }
+ }
+
+ const openSaveAs = () => {
+ setPromptMode('saveAs')
+ setPromptName(projectName)
+ setPromptDescription(projectDescription)
+ }
+
+ const openRename = () => {
+ setPromptMode('rename')
+ setPromptName(projectName)
+ setPromptDescription(projectDescription)
+ }
+
+ const submitPrompt = () => {
+ const name = promptName.trim()
+ if (!name) {
+ notifyError('Enter a project name')
+ return
+ }
+ try {
+ if (promptMode === 'saveAs') {
+ saveProjectAs({ name, description: promptDescription })
+ refresh()
+ notifySuccess(`Saved “${name}”`)
+ } else if (promptMode === 'rename') {
+ renameActiveProject({ name, description: promptDescription })
+ refresh()
+ notifySuccess('Project renamed')
+ }
+ closePrompt()
+ } catch (error) {
+ notifyError(error instanceof Error ? error.message : 'Could not update project')
+ }
+ }
+
+ const onDelete = (id: string, name: string) => {
+ if (!window.confirm(`Delete “${name}” from the library? This cannot be undone.`)) {
+ return
+ }
+ deleteProjectById(id)
+ refresh()
+ notifySuccess('Project deleted')
+ }
+
+ const onExport = () => {
+ try {
+ downloadWorkflowJson(toWorkflowDocument())
+ notifySuccess('Workflow exported')
+ } catch (error) {
+ notifyError(error instanceof Error ? error.message : 'Export failed')
+ }
+ }
+
+ return (
+ <Dialog
+ open={open}
+ onClose={handleClose}
+ maxWidth="sm"
+ fullWidth
+ slotProps={{
+ transition: {
+ onEnter: handleEnter,
+ },
+ paper: {
+ sx: {
+ bgcolor: '#121212',
+ color: '#f4f1ea',
+ border: '1px solid rgba(255,255,255,0.1)',
+ borderRadius: 2.5,
+ overflow: 'hidden',
+ backgroundImage: `
+ radial-gradient(ellipse 70% 55% at 0% 0%, rgba(125,206,160,0.14), transparent 55%),
+ radial-gradient(ellipse 55% 45% at 100% 0%, rgba(230,126,34,0.1), transparent 50%),
+ linear-gradient(180deg, #161616 0%, #101010 100%)
+ `,
+ },
+ },
+ }}
+ >
+ <Box
+ sx={{
+ display: 'flex',
+ alignItems: 'flex-start',
+ justifyContent: 'space-between',
+ gap: 2,
+ px: 3,
+ pt: 2.5,
+ pb: 1.5,
+ }}
+ >
+ <Box sx={{ minWidth: 0 }}>
+ <Typography
+ sx={{
+ fontFamily: '"Fraunces", Georgia, serif',
+ fontWeight: 700,
+ fontSize: 24,
+ letterSpacing: '-0.03em',
+ lineHeight: 1.15,
+ }}
+ >
+ Projects
+ </Typography>
+ <Typography sx={{ mt: 0.75, fontSize: 13, color: 'rgba(244,241,234,0.5)', maxWidth: 480 }}>
+ Save named pipelines in this browser, or import and export JSON files.
+ {projectDirty ? ' Current project has unsaved changes.' : ''}
+ </Typography>
+ </Box>
+ <IconButton
+ aria-label="Close projects"
+ onClick={handleClose}
+ size="small"
+ sx={{
+ color: 'rgba(244,241,234,0.55)',
+ border: '1px solid rgba(255,255,255,0.1)',
+ borderRadius: 1.25,
+ '&:hover': { bgcolor: 'rgba(255,255,255,0.06)', color: '#f4f1ea' },
+ }}
+ >
+ ×
+ </IconButton>
+ </Box>
+
+ <DialogContent sx={{ px: 3, pt: 0.5, pb: 3 }}>
+ <Stack
+ direction="row"
+ spacing={1}
+ useFlexGap
+ sx={{ mb: 2, flexWrap: 'wrap' }}
+ >
+ <Button variant="outlined" disabled={disabled} onClick={onNew} sx={outlineBtnSx}>
+ New
+ </Button>
+ <Button variant="outlined" disabled={disabled} onClick={onSave} sx={outlineBtnSx}>
+ Save
+ </Button>
+ <Button variant="outlined" disabled={disabled} onClick={openSaveAs} sx={outlineBtnSx}>
+ Save As…
+ </Button>
+ <Button variant="outlined" disabled={disabled} onClick={openRename} sx={outlineBtnSx}>
+ Rename…
+ </Button>
+ <Button
+ variant="outlined"
+ disabled={disabled}
+ onClick={onImportFile}
+ sx={outlineBtnSx}
+ >
+ Import file…
+ </Button>
+ <Button variant="outlined" disabled={disabled} onClick={onExport} sx={outlineBtnSx}>
+ Export JSON
+ </Button>
+ </Stack>
+
+ {promptMode ? (
+ <Box
+ sx={{
+ mb: 2,
+ p: 1.75,
+ borderRadius: 1.75,
+ border: '1px solid rgba(125,206,160,0.3)',
+ bgcolor: 'rgba(0,0,0,0.28)',
+ }}
+ >
+ <Typography
+ sx={{
+ mb: 1.25,
+ fontSize: 12,
+ fontWeight: 700,
+ letterSpacing: '0.06em',
+ textTransform: 'uppercase',
+ color: 'rgba(125,206,160,0.9)',
+ }}
+ >
+ {promptMode === 'saveAs' ? 'Save as' : 'Rename'}
+ </Typography>
+ <Stack spacing={1.25}>
+ <TextField
+ size="small"
+ label="Name"
+ value={promptName}
+ autoFocus
+ onChange={(event) => setPromptName(event.target.value)}
+ onKeyDown={(event) => {
+ if (event.key === 'Enter') submitPrompt()
+ }}
+ sx={{
+ '& .MuiInputBase-root': {
+ color: '#f0ebe3',
+ bgcolor: '#0f0f0f',
+ borderRadius: 1.25,
+ },
+ '& .MuiInputLabel-root': { color: 'rgba(244,241,234,0.45)' },
+ '& .MuiOutlinedInput-notchedOutline': {
+ borderColor: 'rgba(255,255,255,0.1)',
+ },
+ }}
+ />
+ <TextField
+ size="small"
+ label="Description (optional)"
+ value={promptDescription}
+ onChange={(event) => setPromptDescription(event.target.value)}
+ sx={{
+ '& .MuiInputBase-root': {
+ color: '#f0ebe3',
+ bgcolor: '#0f0f0f',
+ borderRadius: 1.25,
+ },
+ '& .MuiInputLabel-root': { color: 'rgba(244,241,234,0.45)' },
+ '& .MuiOutlinedInput-notchedOutline': {
+ borderColor: 'rgba(255,255,255,0.1)',
+ },
+ }}
+ />
+ <Stack direction="row" spacing={1}>
+ <Button
+ variant="contained"
+ onClick={submitPrompt}
+ sx={{
+ textTransform: 'none',
+ fontWeight: 700,
+ bgcolor: '#e67e22',
+ color: '#0f0f0f',
+ '&:hover': { bgcolor: '#f39c12' },
+ }}
+ >
+ {promptMode === 'saveAs' ? 'Save' : 'Rename'}
+ </Button>
+ <Button variant="outlined" onClick={closePrompt} sx={outlineBtnSx}>
+ Cancel
+ </Button>
+ </Stack>
+ </Stack>
+ </Box>
+ ) : null}
+
+ {projects.length === 0 ? (
+ <Box
+ sx={{
+ py: 5,
+ textAlign: 'center',
+ border: '1px dashed rgba(255,255,255,0.12)',
+ borderRadius: 2,
+ color: 'rgba(244,241,234,0.45)',
+ }}
+ >
+ <Typography sx={{ fontSize: 14 }}>No saved projects yet.</Typography>
+ <Typography sx={{ mt: 0.75, fontSize: 12.5, color: 'rgba(244,241,234,0.35)' }}>
+ Use Save As to keep the current canvas in this library.
+ </Typography>
+ </Box>
+ ) : (
+ <Stack spacing={1.25}>
+ {projects.map((project) => (
+ <ProjectRow
+ key={project.id}
+ project={project}
+ active={project.id === projectId}
+ disabled={disabled}
+ onOpen={() => onOpen(project.id)}
+ onDelete={() => onDelete(project.id, project.name)}
+ />
+ ))}
+ </Stack>
+ )}
+
+ <Typography
+ sx={{
+ mt: 2,
+ fontSize: 11,
+ color: 'rgba(244,241,234,0.35)',
+ letterSpacing: '0.02em',
+ }}
+ >
+ {projects.length} project{projects.length === 1 ? '' : 's'} in this browser
+ </Typography>
+ </DialogContent>
+ </Dialog>
+ )
+}