Automations: move from Settings to a sidebar workspace with a task dropdown
The Automations caret in the main sidebar lists the user's tasks (status dot, persisted expand state, live refresh via AUTOMATIONS_CHANGED) and deep-links /automations?task=<id>, which scrolls to the card and highlights it. The management surface (compiler, task list, run history) moves to the standalone /automations route; the settings tab is removed and legacy ?tab=automations deep links redirect. Assistant proposal creation notifies the sidebar too. README/RUNNING/help wording follows; browser regression covers the dropdown, deep link, redirect and mobile overflow.
This commit is contained in:
@@ -13,7 +13,7 @@ import { cn } from '@/lib/utils'
|
||||
import { BrandIcon } from '@/components/brand-icon'
|
||||
import {
|
||||
Calendar, Tags, Users, Kanban, Link2, Settings, ChevronLeft, ChevronRight, ChevronDown,
|
||||
FileText, Pin, PinOff, Plus, Shield, Search, MoreHorizontal, Trash2, Pencil, Layers, GripVertical, X,
|
||||
FileText, Pin, PinOff, Plus, Shield, Search, MoreHorizontal, Trash2, Pencil, Layers, GripVertical, X, Sparkles,
|
||||
} from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
} from '@/components/ui/dropdown-menu'
|
||||
import { toast } from 'sonner'
|
||||
import { PAGES_CHANGED, nextUntitledTitle, notifyPagesChanged, type PageSummary } from '@/lib/pages'
|
||||
import { AUTOMATIONS_CHANGED } from '@/lib/automations'
|
||||
import { reorderPages } from '@/lib/page-order'
|
||||
|
||||
// Dragging a page from "Untagged Pages" onto a tag assigns that tag. A custom
|
||||
@@ -32,6 +33,19 @@ type TagRow = { id: string; name: string; color: string }
|
||||
type ColumnRow = { id: string; label: string; color?: string }
|
||||
type CollectionRow = { id: string; name: string; icon?: string | null }
|
||||
type ContactRow = { id: string; displayName: string }
|
||||
type AutomationRow = { id: string; name: string; status: string; enabled: boolean }
|
||||
|
||||
// Status dot for the Automations dropdown: enabled tasks show their engine
|
||||
// status; a disabled task is muted regardless (it will not run).
|
||||
function automationDot(t: AutomationRow): string {
|
||||
if (!t.enabled) return '#9ca3af'
|
||||
switch (t.status) {
|
||||
case 'active': return '#10b981'
|
||||
case 'done': return '#9ca3af'
|
||||
case 'paused': return '#f59e0b'
|
||||
default: return '#ef4444'
|
||||
}
|
||||
}
|
||||
|
||||
// Section collapse state persists per browser. useSyncExternalStore keeps it
|
||||
// hydration-safe (server snapshot uses the default; the client snapshot reads
|
||||
@@ -255,6 +269,7 @@ function SidebarNav({ open, pathname, isAdmin = false }: { open: boolean; pathna
|
||||
const [columns, setColumns] = useState<ColumnRow[]>([])
|
||||
const [collections, setCollections] = useState<CollectionRow[]>([])
|
||||
const [contacts, setContacts] = useState<ContactRow[]>([])
|
||||
const [automations, setAutomations] = useState<AutomationRow[]>([])
|
||||
const [pagesExpanded, setPagesExpanded] = usePersistentState('superbrain:sidebar:pages', true)
|
||||
const [bookmarksExpanded, setBookmarksExpanded] = usePersistentState('superbrain:sidebar:bookmarks', true)
|
||||
const [allPagesExpanded, setAllPagesExpanded] = usePersistentState('superbrain:sidebar:allpages', true)
|
||||
@@ -264,6 +279,7 @@ function SidebarNav({ open, pathname, isAdmin = false }: { open: boolean; pathna
|
||||
const [kanbanExpanded, setKanbanExpanded] = usePersistentState('superbrain:sidebar:kanban', false)
|
||||
const [collectionsExpanded, setCollectionsExpanded] = usePersistentState('superbrain:sidebar:collections', false)
|
||||
const [contactsExpanded, setContactsExpanded] = usePersistentState('superbrain:sidebar:contacts', false)
|
||||
const [automationsExpanded, setAutomationsExpanded] = usePersistentState('superbrain:sidebar:automations', false)
|
||||
const [renamingId, setRenamingId] = useState<string | null>(null)
|
||||
const [renameValue, setRenameValue] = useState('')
|
||||
const [pageDrop, setPageDrop] = useState<{ id: string; after: boolean } | null>(null)
|
||||
@@ -293,6 +309,20 @@ function SidebarNav({ open, pathname, isAdmin = false }: { open: boolean; pathna
|
||||
get('/api/kanban/columns').then((d) => setColumns(Array.isArray(d) ? d : []))
|
||||
get('/api/collections').then((d) => setCollections(Array.isArray(d) ? d : []))
|
||||
get('/api/contacts').then((d) => setContacts(Array.isArray(d) ? d : []))
|
||||
get('/api/agent/tasks').then((d) => setAutomations(Array.isArray(d) ? d : []))
|
||||
}, [])
|
||||
|
||||
// The automations workspace announces creates/toggles/deletes so the
|
||||
// dropdown stays live without a navigation (the pages-changed pattern).
|
||||
useEffect(() => {
|
||||
const reloadAutomations = () => {
|
||||
fetch('/api/agent/tasks')
|
||||
.then((r) => (r.ok ? r.json() : []))
|
||||
.then((d) => setAutomations(Array.isArray(d) ? d : []))
|
||||
.catch(() => { /* non-fatal */ })
|
||||
}
|
||||
window.addEventListener(AUTOMATIONS_CHANGED, reloadAutomations)
|
||||
return () => window.removeEventListener(AUTOMATIONS_CHANGED, reloadAutomations)
|
||||
}, [])
|
||||
|
||||
const createPage = async (parentId?: string | null) => {
|
||||
@@ -434,6 +464,7 @@ function SidebarNav({ open, pathname, isAdmin = false }: { open: boolean; pathna
|
||||
{ href: '/kanban', icon: Kanban, label: 'Kanban' },
|
||||
{ href: '/collections', icon: Layers, label: 'Collections' },
|
||||
{ href: '/contacts', icon: Users, label: 'Contacts' },
|
||||
{ href: '/automations', icon: Sparkles, label: 'Automations' },
|
||||
{ href: '/trash', icon: Trash2, label: 'Trash' },
|
||||
...(isAdmin ? [{ href: '/admin', icon: Shield, label: 'Admin' }] : []),
|
||||
]
|
||||
@@ -672,6 +703,21 @@ function SidebarNav({ open, pathname, isAdmin = false }: { open: boolean; pathna
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="pt-2">
|
||||
<NavSection icon={Sparkles} label="Automations" href="/automations" expanded={automationsExpanded} onToggle={() => setAutomationsExpanded(!automationsExpanded)} count={automations.length}>
|
||||
{automations.map((t) => (
|
||||
<ChildLink
|
||||
key={t.id}
|
||||
href={`/automations?task=${t.id}`}
|
||||
label={t.name}
|
||||
dot={automationDot(t)}
|
||||
active={pathname === '/automations' && searchParams.get('task') === t.id}
|
||||
/>
|
||||
))}
|
||||
{automations.length === 0 && <p className="px-2 py-1 text-xs text-muted-foreground/70">No automations yet</p>}
|
||||
</NavSection>
|
||||
</div>
|
||||
|
||||
<div className="pt-2">
|
||||
<NavLink href="/trash" icon={Trash2} label="Trash" active={pathname === '/trash'} />
|
||||
{isAdmin && <NavLink href="/admin" icon={Shield} label="Admin" active={pathname === '/admin'} />}
|
||||
|
||||
Reference in New Issue
Block a user