feat: AI flow builder, visibility model, dashboard tabs, fork UI (#88)

- AI flow builder: scaffold → branch detail → assemble → review flow
- Generate All one-click branch generation with stop/cancel
- Regenerate scaffold suggestions button
- 3-action review screen: Start Flow, Open in Editor, Build Another
- Fix Publish button gated behind !isDirty
- Fix visibility column enforcement in tree access filter
- Add ?visibility filter and author_name to GET /trees
- Dashboard tabbed flows: My Flows / My Team / Public / All
- Create button in My Flows tab, window focus reload (stale data fix)
- Fork UI with optional reason modal
- Fix account_id nullability in User type and schema
- Keep is_public and visibility in sync on updates

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit was merged in pull request #88.
This commit is contained in:
chihlasm
2026-02-24 07:40:44 -05:00
committed by GitHub
parent 97cd297f46
commit ed4ab059bf
41 changed files with 1909 additions and 315 deletions

View File

@@ -1,9 +1,9 @@
import { useState, useEffect, useRef, useMemo } from 'react'
import { useState, useEffect, useRef, useMemo, useCallback } from 'react'
import { useNavigate } from 'react-router-dom'
import { Search, Loader2, Star, ChevronLeft, ChevronRight } from 'lucide-react'
import { Search, Loader2, Star, ChevronLeft, ChevronRight, GitBranch } from 'lucide-react'
import { treesApi } from '@/api/trees'
import { sessionsApi } from '@/api/sessions'
import type { TreeListItem } from '@/types'
import type { TreeListItem, TreeFilters } from '@/types'
import type { Session } from '@/types/session'
import { getTreeNavigatePath } from '@/lib/routing'
import { usePermissions } from '@/hooks/usePermissions'
@@ -21,6 +21,7 @@ import { ViewToggle } from '@/components/library/ViewToggle'
import { AIFlowBuilderModal } from '@/components/ai-builder/AIFlowBuilderModal'
import { CreateFlowDropdown } from '@/components/common/CreateFlowDropdown'
import { cn } from '@/lib/utils'
import { toast } from '@/lib/toast'
function timeAgo(dateStr: string): string {
const now = Date.now()
@@ -66,6 +67,16 @@ export function QuickStartPage() {
const [showAIBuilder, setShowAIBuilder] = useState(false)
const { aiEnabled } = useCachedQuota()
// Tab state
type Tab = 'mine' | 'team' | 'public' | 'all'
const hasTeam = Boolean(user?.account_id)
const [activeTab, setActiveTab] = useState<Tab>('mine')
// Fork modal state
const [forkTarget, setForkTarget] = useState<TreeListItem | null>(null)
const [forkReason, setForkReason] = useState('')
const [isForking, setIsForking] = useState(false)
// Pin store
const pinnedItems = usePinnedFlowsStore((s) => s.items)
const pinnedIsLoading = usePinnedFlowsStore((s) => s.isLoading)
@@ -102,34 +113,29 @@ export function QuickStartPage() {
})
}, [])
// Load my flows when page/size or user changes
useEffect(() => {
// Load flows — tab-aware
const loadFlows = useCallback(async () => {
if (!user?.id) return
setIsLoadingFlows(true)
setAllFlowsCeiling(false)
const loadFlows = async () => {
setIsLoadingFlows(true)
setAllFlowsCeiling(false)
try {
if (pageSize === 'all') {
// Fetch in chunks of 100, max 500
let allItems: TreeListItem[] = []
let skip = 0
const CHUNK = 100
const MAX = 500
while (true) {
const chunk = await treesApi.list({
author_id: user.id,
sort_by: 'updated_at',
limit: CHUNK,
skip,
})
const params: TreeFilters = { sort_by: 'updated_at', limit: CHUNK, skip }
if (activeTab === 'mine') params.author_id = user.id
if (activeTab === 'team') params.visibility = 'team'
if (activeTab === 'public') { params.visibility = 'public'; params.sort_by = 'usage_count' }
const chunk = await treesApi.list(params)
allItems = [...allItems, ...chunk]
if (chunk.length < CHUNK || allItems.length >= MAX) {
if (allItems.length >= MAX) {
allItems = allItems.slice(0, MAX)
setAllFlowsCeiling(true)
}
if (allItems.length >= MAX) { allItems = allItems.slice(0, MAX); setAllFlowsCeiling(true) }
break
}
skip += CHUNK
@@ -138,20 +144,34 @@ export function QuickStartPage() {
setHasNextPage(false)
} else {
const numSize = pageSize as number
const response = await treesApi.list({
author_id: user.id,
sort_by: 'updated_at',
const params: TreeFilters = {
sort_by: activeTab === 'public' ? 'usage_count' : 'updated_at',
limit: numSize + 1,
skip: (page - 1) * numSize,
})
}
if (activeTab === 'mine') params.author_id = user.id
if (activeTab === 'team') params.visibility = 'team'
if (activeTab === 'public') params.visibility = 'public'
const response = await treesApi.list(params)
setHasNextPage(response.length > numSize)
setMyFlows(response.slice(0, numSize))
}
} catch {
// silently fail
} finally {
setIsLoadingFlows(false)
}
}, [user?.id, page, pageSize, activeTab])
loadFlows().catch(() => setIsLoadingFlows(false))
}, [user?.id, page, pageSize])
useEffect(() => { loadFlows() }, [loadFlows])
// Reload on window focus (fixes stale data after returning from editor)
useEffect(() => {
const onFocus = () => loadFlows()
window.addEventListener('focus', onFocus)
return () => window.removeEventListener('focus', onFocus)
}, [loadFlows])
// Debounced search
useEffect(() => {
@@ -219,9 +239,35 @@ export function QuickStartPage() {
const handleTagClick = () => {} // Not used on dashboard
const handleFolderCreated = () => {} // Not used on dashboard
const handleFork = async () => {
if (!forkTarget) return
setIsForking(true)
try {
const forked = await treesApi.fork(forkTarget.id, {
fork_reason: forkReason.trim() || undefined,
})
toast.success(`"${forked.name}" added to your flows`)
setForkTarget(null)
setForkReason('')
setActiveTab('mine')
} catch {
toast.error('Failed to fork flow')
} finally {
setIsForking(false)
}
}
// Page size options
const pageSizeOptions: (number | 'all')[] = [10, 25, 50, 'all']
// Tabs
const tabs: { id: Tab; label: string }[] = [
{ id: 'mine', label: 'My Flows' },
...(hasTeam ? [{ id: 'team' as Tab, label: 'My Team' }] : []),
{ id: 'public', label: 'Public' },
{ id: 'all', label: 'All' },
]
return (
<div className="p-6 space-y-6">
{/* Page Header */}
@@ -234,14 +280,6 @@ export function QuickStartPage() {
Welcome back. Here&apos;s what&apos;s happening with your flows.
</p>
</div>
<div className="flex items-center gap-2">
{canCreateTrees && (
<CreateFlowDropdown
aiEnabled={aiEnabled}
onOpenAIBuilder={() => setShowAIBuilder(true)}
/>
)}
</div>
</div>
{/* Quick Stats */}
@@ -354,11 +392,31 @@ export function QuickStartPage() {
)}
</div>
{/* My Flows Section */}
{/* My Flows Section — tabbed */}
<div>
<div className="mb-3 flex items-center justify-between">
<h2 className="font-heading text-lg font-semibold text-foreground">My Flows</h2>
<div className="flex items-center gap-2">
<div className="mb-3 flex items-center gap-1 border-b border-border">
{tabs.map((tab) => (
<button
key={tab.id}
type="button"
onClick={() => { setActiveTab(tab.id); setPage(1) }}
className={cn(
'px-4 py-2.5 text-sm font-medium transition-colors border-b-2 -mb-px',
activeTab === tab.id
? 'border-primary text-foreground'
: 'border-transparent text-muted-foreground hover:text-foreground'
)}
>
{tab.label}
</button>
))}
<div className="ml-auto flex items-center gap-2 pb-1.5">
{activeTab === 'mine' && canCreateTrees && (
<CreateFlowDropdown
aiEnabled={aiEnabled}
onOpenAIBuilder={() => setShowAIBuilder(true)}
/>
)}
<ViewToggle view={dashboardMyFlowsView} onChange={setDashboardMyFlowsView} />
</div>
</div>
@@ -371,8 +429,16 @@ export function QuickStartPage() {
</div>
) : myFlows.length === 0 ? (
<div className="py-12 text-center">
<p className="text-muted-foreground mb-4">You haven&apos;t created any flows yet.</p>
{canCreateTrees && (
<p className="text-muted-foreground mb-4">
{activeTab === 'mine'
? "You haven't created any flows yet."
: activeTab === 'team'
? 'No team flows found.'
: activeTab === 'public'
? 'No public flows found.'
: 'No flows found.'}
</p>
{activeTab === 'mine' && canCreateTrees && (
<CreateFlowDropdown
aiEnabled={aiEnabled}
onOpenAIBuilder={() => setShowAIBuilder(true)}
@@ -497,6 +563,48 @@ export function QuickStartPage() {
)}
</div>
{/* Fork Modal */}
{forkTarget && (
<div className="fixed inset-0 z-50 flex items-center justify-center bg-background/80 backdrop-blur-sm">
<div className="w-full max-w-sm rounded-xl border border-border bg-card p-5 shadow-xl">
<h3 className="mb-1 text-sm font-semibold text-foreground">Fork this flow?</h3>
<p className="mb-4 text-xs text-muted-foreground">
Creates a copy of &ldquo;{forkTarget.name}&rdquo; under your account that you can edit freely.
</p>
<label className="mb-1 block text-xs text-muted-foreground">
Why are you forking? <span className="opacity-60">(optional)</span>
</label>
<input
type="text"
value={forkReason}
onChange={(e) => setForkReason(e.target.value)}
placeholder="e.g. Adding Cisco Meraki steps for our network"
maxLength={255}
className="mb-4 w-full rounded-lg border border-border bg-background px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary/20"
onKeyDown={(e) => e.key === 'Enter' && handleFork()}
/>
<div className="flex gap-2">
<button
type="button"
onClick={handleFork}
disabled={isForking}
className="flex flex-1 items-center justify-center gap-1.5 rounded-lg bg-gradient-brand py-2 text-sm font-medium text-white shadow-lg shadow-primary/20 hover:opacity-90 disabled:opacity-50"
>
<GitBranch className="h-3.5 w-3.5" />
{isForking ? 'Forking...' : 'Fork Flow'}
</button>
<button
type="button"
onClick={() => setForkTarget(null)}
className="rounded-lg border border-border px-4 py-2 text-sm text-muted-foreground hover:bg-accent"
>
Cancel
</button>
</div>
</div>
</div>
)}
{/* AI Builder Modal */}
{showAIBuilder && (
<AIFlowBuilderModal