Skip to content

Image Pipeline Playground

feat(frontend): replace Example with template gallery

Mohammad Rajaei0d863c56b68f
diff --git a/frontend/src/app/App.tsx b/frontend/src/app/App.tsx
index 97bc642..c3a5c70 100644
--- a/frontend/src/app/App.tsx
+++ b/frontend/src/app/App.tsx
@@ -1,10 +1,11 @@
import { Box } from '@mui/material'
-import { useEffect, useRef } from 'react'
+import { useEffect, useRef, useState } 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 { TemplateGallery } from '../features/templates/TemplateGallery'
import { useGraphStore } from '../store/graphStore'
import {
bindExecutionRunner,
@@ -13,6 +14,7 @@ import {
} from '../hooks/useExecutionSocket'
import { notifyError, notifyInfo, notifySuccess } from '../notify'
import { downloadWorkflowJson, parseWorkflowJson } from '../workflow/io'
+import type { WorkflowTemplate } from '../workflow/templates'
import { AppHeader } from './AppHeader'
export default function App() {
@@ -21,8 +23,10 @@ export default function App() {
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)
useEffect(() => bindExecutionRunner(run), [run])
@@ -76,20 +80,25 @@ export default function App() {
}
}
- const onLoadExample = async () => {
+ const onOpenTemplates = () => {
if (nodeCatalog.length === 0) {
notifyError('Node catalog is still loading — try again in a moment')
return
}
+ setTemplatesOpen(true)
+ }
+
+ const onSelectTemplate = async (template: WorkflowTemplate) => {
try {
- const response = await fetch('/examples/blur_canny.json')
+ const response = await fetch(template.path)
if (!response.ok) {
- throw new Error(`Could not fetch example (${response.status})`)
+ throw new Error(`Could not fetch template (${response.status})`)
}
const text = await response.text()
- applyLoadedWorkflow(text, 'Example workflow loaded')
+ applyLoadedWorkflow(text, `Loaded “${template.name}”`)
+ setTemplatesOpen(false)
} catch (error) {
- notifyError(error instanceof Error ? error.message : 'Example load failed')
+ notifyError(error instanceof Error ? error.message : 'Template load failed')
}
}
@@ -115,7 +124,13 @@ export default function App() {
onExportPython={() => void onExportPython()}
onExportWorkflow={onExportWorkflow}
onLoadWorkflow={onLoadWorkflowClick}
- onLoadExample={() => void onLoadExample()}
+ onOpenTemplates={onOpenTemplates}
+ />
+ <TemplateGallery
+ open={templatesOpen}
+ onClose={() => setTemplatesOpen(false)}
+ onSelect={(template) => void onSelectTemplate(template)}
+ disabled={isExecuting}
/>
<Box
diff --git a/frontend/src/app/AppHeader.tsx b/frontend/src/app/AppHeader.tsx
index 4309255..083db40 100644
--- a/frontend/src/app/AppHeader.tsx
+++ b/frontend/src/app/AppHeader.tsx
@@ -129,7 +129,7 @@ interface AppHeaderProps {
onExportPython: () => void
onExportWorkflow: () => void
onLoadWorkflow: () => void
- onLoadExample: () => void
+ onOpenTemplates: () => void
}
const outlineBtnSx = {
@@ -157,7 +157,7 @@ export function AppHeader({
onExportPython,
onExportWorkflow,
onLoadWorkflow,
- onLoadExample,
+ onOpenTemplates,
}: AppHeaderProps) {
const seed = useGraphStore((s) => s.seed)
const sampleCount = useGraphStore((s) => s.sampleCount)
@@ -383,10 +383,10 @@ export function AppHeader({
<Button
variant="outlined"
disabled={isExecuting}
- onClick={onLoadExample}
+ onClick={onOpenTemplates}
sx={outlineBtnSx}
>
- Example
+ Templates
</Button>
<Button
diff --git a/frontend/src/features/templates/TemplateGallery.tsx b/frontend/src/features/templates/TemplateGallery.tsx
new file mode 100644
index 0000000..bb4fc60
--- /dev/null
+++ b/frontend/src/features/templates/TemplateGallery.tsx
@@ -0,0 +1,90 @@
+import {
+ Box,
+ Dialog,
+ DialogContent,
+ DialogTitle,
+ List,
+ ListItemButton,
+ ListItemText,
+ Typography,
+} from '@mui/material'
+import { WORKFLOW_TEMPLATES, type WorkflowTemplate } from '../../workflow/templates'
+
+type TemplateGalleryProps = {
+ open: boolean
+ onClose: () => void
+ onSelect: (template: WorkflowTemplate) => void
+ disabled?: boolean
+}
+
+export function TemplateGallery({ open, onClose, onSelect, disabled }: TemplateGalleryProps) {
+ return (
+ <Dialog
+ open={open}
+ onClose={onClose}
+ maxWidth="sm"
+ fullWidth
+ slotProps={{
+ paper: {
+ sx: {
+ bgcolor: '#161616',
+ color: '#f4f1ea',
+ border: '1px solid rgba(255,255,255,0.1)',
+ borderRadius: 2,
+ backgroundImage: 'none',
+ },
+ },
+ }}
+ >
+ <DialogTitle
+ sx={{
+ fontFamily: '"Fraunces", Georgia, serif',
+ fontWeight: 700,
+ fontSize: 20,
+ pb: 0.5,
+ }}
+ >
+ Template gallery
+ </DialogTitle>
+ <DialogContent sx={{ pt: 1 }}>
+ <Typography sx={{ fontSize: 13, color: 'rgba(244,241,234,0.5)', mb: 1.5 }}>
+ Load a starter pipeline onto the canvas. Existing graph will be replaced.
+ </Typography>
+ <List disablePadding sx={{ mx: -1 }}>
+ {WORKFLOW_TEMPLATES.map((template) => (
+ <ListItemButton
+ key={template.id}
+ disabled={disabled}
+ onClick={() => onSelect(template)}
+ sx={{
+ borderRadius: 1.25,
+ mb: 0.5,
+ alignItems: 'flex-start',
+ border: '1px solid transparent',
+ '&:hover': {
+ bgcolor: 'rgba(125,206,160,0.08)',
+ borderColor: 'rgba(125,206,160,0.25)',
+ },
+ }}
+ >
+ <ListItemText
+ primary={
+ <Box sx={{ display: 'flex', alignItems: 'baseline', gap: 1 }}>
+ <Typography sx={{ fontSize: 14, fontWeight: 700, color: '#f4f1ea' }}>
+ {template.name}
+ </Typography>
+ </Box>
+ }
+ secondary={
+ <Typography sx={{ fontSize: 12, color: 'rgba(244,241,234,0.5)', mt: 0.35 }}>
+ {template.description}
+ </Typography>
+ }
+ />
+ </ListItemButton>
+ ))}
+ </List>
+ </DialogContent>
+ </Dialog>
+ )
+}
diff --git a/frontend/src/workflow/templates.ts b/frontend/src/workflow/templates.ts
new file mode 100644
index 0000000..7fd5975
--- /dev/null
+++ b/frontend/src/workflow/templates.ts
@@ -0,0 +1,34 @@
+export type WorkflowTemplate = {
+ id: string
+ name: string
+ description: string
+ /** Public URL path under /examples/ */
+ path: string
+}
+
+export const WORKFLOW_TEMPLATES: WorkflowTemplate[] = [
+ {
+ id: 'blur_canny',
+ name: 'Blur & Canny',
+ description: 'Load Lena, blur, then extract Canny edges.',
+ path: '/examples/blur_canny.json',
+ },
+ {
+ id: 'hist_equalize',
+ name: 'Hist Equalize',
+ description: 'Grayscale + histogram equalize for OCR / documents.',
+ path: '/examples/hist_equalize.json',
+ },
+ {
+ id: 'morphology_cleanup',
+ name: 'Morphology Cleanup',
+ description: 'Otsu threshold then morphological open to clean noise.',
+ path: '/examples/morphology_cleanup.json',
+ },
+ {
+ id: 'contour_detect',
+ name: 'Contour Detect',
+ description: 'Threshold then find contours for structure analysis.',
+ path: '/examples/contour_detect.json',
+ },
+]