feat: add procedural flows with intake forms, navigation, and seed templates

Adds a new "procedural" tree type for linear step-by-step project workflows
(domain controller setup, M365 onboarding, VPN config, etc). Includes intake
form builder, two-panel step navigation, variable resolution, procedural
exports, 3 seed templates, and UI rename from "Trees" to "Flows".

Also archives 19 implemented plan docs and creates deferred features backlog.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
chihlasm
2026-02-14 04:13:52 -05:00
parent 303570ca2c
commit 350c977eda
58 changed files with 11686 additions and 167 deletions

View File

@@ -1,5 +1,5 @@
import { useEffect, useState, useCallback } from 'react'
import { useNavigate, Link } from 'react-router-dom'
import { useNavigate, Link, useSearchParams } from 'react-router-dom'
import { Plus, X, FolderOpen, RotateCcw, Play } from 'lucide-react'
import { treesApi } from '@/api/trees'
import { categoriesApi } from '@/api/categories'
@@ -22,6 +22,7 @@ import { toast } from '@/lib/toast'
export function TreeLibraryPage() {
const { canCreateTrees } = usePermissions()
const navigate = useNavigate()
const [searchParams] = useSearchParams()
const [trees, setTrees] = useState<TreeListItem[]>([])
const [categories, setCategories] = useState<CategoryListItem[]>([])
const [folders, setFolders] = useState<FolderListItem[]>([])
@@ -32,6 +33,22 @@ export function TreeLibraryPage() {
const [isLoading, setIsLoading] = useState(true)
const [showDrafts, setShowDrafts] = useState(false)
// Read type filter from URL query params (e.g. /trees?type=procedural)
const urlType = searchParams.get('type')
const [typeFilter, setTypeFilter] = useState<'all' | 'troubleshooting' | 'procedural'>(
urlType === 'troubleshooting' || urlType === 'procedural' ? urlType : 'all'
)
// Sync type filter when URL changes (e.g. clicking nav sub-items)
useEffect(() => {
const t = searchParams.get('type')
if (t === 'troubleshooting' || t === 'procedural') {
setTypeFilter(t)
} else {
setTypeFilter('all')
}
}, [searchParams])
// View preferences from store
const { treeLibraryView, setTreeLibraryView, treeLibrarySortBy, setTreeLibrarySortBy } =
useUserPreferencesStore()
@@ -112,7 +129,7 @@ export function TreeLibraryPage() {
// Load trees when filters change
useEffect(() => {
loadTrees()
}, [selectedCategoryId, selectedTags, selectedFolderId, treeLibrarySortBy, showDrafts])
}, [selectedCategoryId, selectedTags, selectedFolderId, treeLibrarySortBy, showDrafts, typeFilter])
// Load folders on mount and listen for changes
useEffect(() => {
@@ -126,6 +143,7 @@ export function TreeLibraryPage() {
setIsLoading(true)
try {
const treesData = await treesApi.list({
tree_type: typeFilter !== 'all' ? typeFilter : undefined,
category_id: selectedCategoryId || undefined,
tags: selectedTags.length > 0 ? selectedTags.join(',') : undefined,
folder_id: selectedFolderId || undefined,
@@ -134,7 +152,7 @@ export function TreeLibraryPage() {
})
setTrees(treesData)
} catch (err) {
toast.error('Failed to load trees')
toast.error('Failed to load flows')
console.error(err)
} finally {
setIsLoading(false)
@@ -151,7 +169,7 @@ export function TreeLibraryPage() {
const results = await treesApi.search(searchQuery)
setTrees(results)
} catch (err) {
toast.error('Failed to search trees')
toast.error('Failed to search flows')
console.error(err)
} finally {
setIsLoading(false)
@@ -175,8 +193,12 @@ export function TreeLibraryPage() {
setSearchQuery('')
}
const handleStartSession = (treeId: string) => {
navigate(`/trees/${treeId}/navigate`)
const handleStartSession = (treeId: string, treeType?: string) => {
if (treeType === 'procedural') {
navigate(`/flows/${treeId}/navigate`)
} else {
navigate(`/trees/${treeId}/navigate`)
}
}
const handleCreateFolder = (parentId?: string | null) => {
@@ -198,10 +220,10 @@ export function TreeLibraryPage() {
await treesApi.delete(treeToDelete.id)
setTrees(trees.filter((t) => t.id !== treeToDelete.id))
window.dispatchEvent(new Event('folder-changed'))
toast.success(`Tree "${treeToDelete.name}" deleted successfully`)
toast.success(`"${treeToDelete.name}" deleted successfully`)
} catch (err) {
console.error('Failed to delete tree:', err)
toast.error('Failed to delete tree')
console.error('Failed to delete flow:', err)
toast.error('Failed to delete flow')
} finally {
setIsDeleting(false)
setShowDeleteConfirm(false)
@@ -214,11 +236,11 @@ export function TreeLibraryPage() {
setIsForkingTree(true)
try {
await treesApi.fork(treeId)
toast.success('Tree forked successfully')
toast.success('Flow forked successfully')
navigate('/my-trees')
} catch (err) {
console.error('Failed to fork tree:', err)
toast.error('Failed to fork tree')
console.error('Failed to fork flow:', err)
toast.error('Failed to fork flow')
} finally {
setIsForkingTree(false)
}
@@ -247,21 +269,27 @@ export function TreeLibraryPage() {
<div className="container mx-auto px-4 py-6 sm:px-6 sm:py-8">
<div className="mb-6 flex flex-col gap-4 sm:mb-8 sm:flex-row sm:items-start sm:justify-between">
<div>
<h1 className="text-2xl font-bold text-white sm:text-3xl">Decision Trees</h1>
<h1 className="text-2xl font-bold text-white sm:text-3xl">
{typeFilter === 'procedural' ? 'Procedures' : typeFilter === 'troubleshooting' ? 'Troubleshooting Flows' : 'Flow Library'}
</h1>
<p className="mt-2 text-white/40">
Select a troubleshooting tree to start a new session
{typeFilter === 'procedural'
? 'Step-by-step procedures for project work'
: typeFilter === 'troubleshooting'
? 'Branching decision flows for troubleshooting'
: 'Browse and start troubleshooting flows and procedures'}
</p>
</div>
{canCreateTrees && (
<Link
to="/trees/new"
to={typeFilter === 'procedural' ? '/flows/new' : '/trees/new'}
className={cn(
'flex items-center gap-2 rounded-md bg-white px-4 py-2 text-sm font-medium text-black',
'hover:bg-white/90'
)}
>
<Plus className="h-4 w-4" />
Create Tree
{typeFilter === 'procedural' ? 'Create Procedure' : 'Create Flow'}
</Link>
)}
</div>
@@ -284,7 +312,7 @@ export function TreeLibraryPage() {
<div className="flex flex-1 gap-2">
<input
type="text"
placeholder="Search trees..."
placeholder="Search flows..."
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
onKeyDown={(e) => e.key === 'Enter' && handleSearch()}
@@ -326,6 +354,22 @@ export function TreeLibraryPage() {
{/* View Controls */}
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
<div className="flex items-center gap-4">
<div className="flex rounded-lg border border-white/10 p-0.5">
{(['all', 'troubleshooting', 'procedural'] as const).map((t) => (
<button
key={t}
onClick={() => setTypeFilter(t)}
className={cn(
'rounded-md px-3 py-1 text-xs font-medium transition-colors',
typeFilter === t
? 'bg-white/10 text-white'
: 'text-white/40 hover:text-white/60'
)}
>
{t === 'all' ? 'All' : t === 'troubleshooting' ? 'Troubleshooting' : 'Procedures'}
</button>
))}
</div>
<SortDropdown value={treeLibrarySortBy} onChange={setTreeLibrarySortBy} />
<label className="flex items-center gap-2 cursor-pointer">
<input
@@ -450,7 +494,7 @@ export function TreeLibraryPage() {
</div>
) : trees.length === 0 ? (
<div className="py-12 text-center text-white/40">
No trees found.{' '}
No flows found.{' '}
{(searchQuery || hasActiveFilters) && 'Try adjusting your filters.'}
</div>
) : (
@@ -525,7 +569,7 @@ export function TreeLibraryPage() {
setTreeToDelete(null)
}}
onConfirm={handleDeleteTree}
title="Delete Tree"
title="Delete Flow"
message={`Are you sure you want to delete "${treeToDelete?.name}"? This action can be undone by an administrator.`}
confirmLabel="Delete"
confirmVariant="destructive"