diff --git a/app/w/[id]/workflow.tsx b/app/w/[id]/workflow.tsx index b603a192e1..cb40fa0533 100644 --- a/app/w/[id]/workflow.tsx +++ b/app/w/[id]/workflow.tsx @@ -28,6 +28,8 @@ import { NotificationList } from '@/app/w/components/notifications/notifications import { useNotificationStore } from '@/stores/notifications/notifications-store' import { executeWorkflow } from '@/lib/workflow' import { useWorkflowExecution } from '../hooks/use-workflow-execution' +import { useWorkflowRegistry } from '@/stores/workflow/workflow-registry' +import { useParams } from 'next/navigation' /** * Represents the data structure for a workflow node @@ -304,6 +306,15 @@ function WorkflowCanvas() { * Root workflow component that provides the ReactFlow context to the canvas */ export default function Workflow() { + const params = useParams() + const { setActiveWorkflow } = useWorkflowRegistry() + + useEffect(() => { + if (params.id) { + setActiveWorkflow(params.id as string) + } + }, [params.id, setActiveWorkflow]) + return ( diff --git a/app/w/components/control-bar/control-bar.tsx b/app/w/components/control-bar/control-bar.tsx index d346835fe0..88ac787a30 100644 --- a/app/w/components/control-bar/control-bar.tsx +++ b/app/w/components/control-bar/control-bar.tsx @@ -7,7 +7,7 @@ import { DropdownMenuItem, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu' -import { History, Bell, Play } from 'lucide-react' +import { History, Bell, Play, Trash2 } from 'lucide-react' import { useNotificationStore } from '@/stores/notifications/notifications-store' import { NotificationDropdownItem } from './components/notification-dropdown-item' import { useWorkflowStore } from '@/stores/workflow/workflow-store' @@ -15,12 +15,31 @@ import { HistoryDropdownItem } from './components/history-dropdown-item' import { formatDistanceToNow } from 'date-fns' import { useEffect, useState } from 'react' import { useWorkflowExecution } from '../../hooks/use-workflow-execution' +import { useWorkflowRegistry } from '@/stores/workflow/workflow-registry' +import { useRouter } from 'next/navigation' export function ControlBar() { const { notifications } = useNotificationStore() const { history, undo, redo } = useWorkflowStore() const [, forceUpdate] = useState({}) const { isExecuting, handleRunWorkflow } = useWorkflowExecution() + const { workflows, removeWorkflow, activeWorkflowId } = useWorkflowRegistry() + const router = useRouter() + + const handleDeleteWorkflow = () => { + if (!activeWorkflowId) return + const newWorkflows = { ...workflows } + delete newWorkflows[activeWorkflowId] + const remainingIds = Object.keys(newWorkflows) + + removeWorkflow(activeWorkflowId) + + if (remainingIds.length > 0) { + router.push(`/w/${remainingIds[0]}`) + } else { + router.push('/') + } + } // Update the time display every minute useEffect(() => { @@ -44,6 +63,16 @@ export function ControlBar() { {/* Right Section - Actions */}
+ + + + Add Workflow + -