* feat: Add TreeCanvasNode inline editor card component Replaces modal-based node editing with inline expand/collapse cards. Each card shows node type, title, and options in compact mode, then renders the full edit form inline on expand — no modal required. Local draft state with save/cancel prevents premature store writes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: Add TreeCanvas layout with visual branching and orchestration Replaces NodeList + TreePreviewPanel with a single full-width canvas. Decision nodes branch horizontally; action/solution nodes flow vertically. Inline type picker adds nodes without modal interruption. Handles pending link resolution, inbound reference cleanup on delete, and selection sync. CSS dot-grid background + connector lines for structure clarity. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * refactor: Update forms for inline safety, add MetadataSidePanel, update layout - NodeFormDecision: option reorder via onUpdate (no premature store writes) - NodePicker: add allowCreate prop (default true) to hide Create New options during inline canvas editing, preventing side-effect node creation - MetadataSidePanel: 320px right slide-in overlay wrapping TreeMetadataForm, closes on backdrop click, close button, and Escape key - TreeEditorLayout: Flow mode now renders full-width TreeCanvas + MetadataSidePanel overlay; Code mode unchanged (Monaco + preview split) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: Wire toolbar metadata toggle and integrate canvas layout - Add isMetadataOpen state in TreeEditorPage - Add Metadata toolbar button (visible in Flow mode only) - Auto-close metadata panel when switching to Code mode - Pass isMetadataOpen/onCloseMetadata props through TreeEditorLayout - Update Flow mode toggle tooltip to reflect new canvas editing Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * docs: add canvas UX fixes design doc (scroll, tooltips, answer stubs) Captures approved design for three post-implementation UX improvements to the tree canvas editor: card scroll fix, info tooltip replacement for hint text, and the new 'answer' node type for sketching decision branches before assigning types. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * docs: add implementation plan for canvas UX fixes 12-task plan covering scroll fix, info tooltips, and answer stub node type. Each task has exact file paths, code, and build verification steps. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: make canvas card expanded area scrollable with sticky header Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: add fullscreen toggle to Modal, enable in NodeEditorModal Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: add reusable InfoTip component for field-level help Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: replace hint paragraphs with InfoTip tooltips in NodeFormDecision Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: replace hint paragraphs with InfoTip tooltips in NodeFormAction Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: replace hint paragraphs with InfoTip tooltips in NodeFormResolution Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: add 'answer' to NodeType union for branch placeholder stubs Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: add AnswerStubCard component for unresolved branch placeholders Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: guard NODE_TYPE_CONFIG lookup against 'answer' type Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: redesign NodeFormDecision to label-only options, remove NodePicker Users now type answer labels only. Stub nodes are created automatically by TreeCanvas when the decision node is saved. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: auto-create answer stubs on decision save, render AnswerStubCard Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: add answer type to all Record<NodeType> icon and color maps Fixes NodeList, ContinuationModal, NodePicker, and TreePreviewNode. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: allow 'answer' type in tree drafts, block on publish Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: block publish if unresolved answer stub nodes exist Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: serialize 'answer' stub nodes in markdown output Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: add defensive guard for answer nodes in session navigation Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: add delete button with confirmation to AnswerStubCard Adds an inline delete flow to answer stub placeholder cards: - Trash icon button (top-right, subtle) visible in idle state - Click reveals "Delete this stub?" confirmation with Delete/Cancel - Confirmed delete calls onDelete(nodeId) wired to handleDelete in TreeCanvas Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: prevent category Cancel overflow and add Tab/Enter to create options - TreeMetadataForm: add min-w-0 + shrink-0 to keep Cancel button in-panel - NodeFormDecision: Tab or Enter on the last non-empty option input adds a new option and auto-focuses it; empty last input lets Tab pass through normally Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: re-sync draft from store when canvas card is opened When a decision node is saved with new options, stub next_node_id values are written back to the store. But the local draft was initialized once at mount and never refreshed, so reopening the card gave a stale draft with empty next_node_ids — causing duplicate stubs on every subsequent save. Fix: reset draft from the live node whenever isExpanded transitions to true. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix+feat: blank options, stub card dismiss, collapsible subtrees - TreeCanvas: strip blank-label options on save so they don't generate stubs; also filter them from the unlinked-option add-button list - AnswerStubCard: collapse type-picker when clicking outside the card - TreeCanvasNode: add subtree collapse toggle button (ChevronsDownUp icon) visible in compact mode when the node has children - TreeCanvas: track collapsedNodeIds; hide subtree behind a clickable "N nodes hidden" pill when collapsed Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: stop connector fork line from overlapping child cards Replace the two-element approach (separate fork line + child lanes div with mismatched maxWidth values) with a single relative-positioned container. The fork line is absolutely positioned and its left/right are calculated from the number of children so it spans exactly from the center of the first lane to the center of the last lane. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: replace Show Drafts checkbox with Drafts tab in Flow Library - Remove the out-of-place checkbox; add 'Drafts' as a tab alongside All | Troubleshooting | Projects | Maintenance - Drafts tab sets showDrafts=true + typeFilter='all' so the API filter still works correctly via include_drafts - Move SortDropdown to the right side next to ViewToggle, so both secondary controls are grouped together Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
214 lines
7.0 KiB
TypeScript
214 lines
7.0 KiB
TypeScript
import { useEffect, useState } from 'react'
|
|
import { categoriesApi } from '@/api/categories'
|
|
import { useTreeEditorStore } from '@/store/treeEditorStore'
|
|
import { TagInput } from '@/components/common/TagInput'
|
|
import type { CategoryListItem } from '@/types'
|
|
import { cn } from '@/lib/utils'
|
|
import { Globe, Lock } from 'lucide-react'
|
|
|
|
export function TreeMetadataForm() {
|
|
const {
|
|
name,
|
|
description,
|
|
category,
|
|
categoryId,
|
|
tags,
|
|
isPublic,
|
|
setName,
|
|
setDescription,
|
|
setCategory,
|
|
setCategoryId,
|
|
setTags,
|
|
setIsPublic,
|
|
validationErrors,
|
|
} = useTreeEditorStore()
|
|
|
|
const [categories, setCategories] = useState<CategoryListItem[]>([])
|
|
const [customCategory, setCustomCategory] = useState(false)
|
|
|
|
// Load categories
|
|
useEffect(() => {
|
|
categoriesApi.list().then(setCategories).catch(console.error)
|
|
}, [])
|
|
|
|
const handleCategoryChange = (value: string) => {
|
|
if (value === '__custom__') {
|
|
setCustomCategory(true)
|
|
setCategory('')
|
|
setCategoryId(null)
|
|
} else if (value === '') {
|
|
setCustomCategory(false)
|
|
setCategory('')
|
|
setCategoryId(null)
|
|
} else {
|
|
setCustomCategory(false)
|
|
setCategoryId(value)
|
|
// Find category name for display
|
|
const cat = categories.find((c) => c.id === value)
|
|
if (cat) {
|
|
setCategory(cat.name)
|
|
}
|
|
}
|
|
}
|
|
|
|
const nameError = validationErrors.find(
|
|
(e) => !e.nodeId && e.message.toLowerCase().includes('name')
|
|
)
|
|
|
|
return (
|
|
<div className="space-y-4 bg-card border border-border rounded-2xl p-4">
|
|
<h2 className="text-sm font-semibold text-foreground">Tree Details</h2>
|
|
|
|
{/* Name */}
|
|
<div>
|
|
<label htmlFor="tree-name" className="block text-sm font-medium text-foreground">
|
|
Name <span className="text-red-400">*</span>
|
|
</label>
|
|
<input
|
|
id="tree-name"
|
|
type="text"
|
|
value={name}
|
|
onChange={(e) => setName(e.target.value)}
|
|
placeholder="e.g., VDA Registration Troubleshooting"
|
|
className={cn(
|
|
'mt-1 block w-full rounded-md border px-3 py-2 text-sm',
|
|
'bg-card text-foreground placeholder:text-muted-foreground',
|
|
'focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary/20',
|
|
nameError ? 'border-red-400' : 'border-border'
|
|
)}
|
|
/>
|
|
{nameError && <p className="mt-1 text-xs text-red-400">{nameError.message}</p>}
|
|
</div>
|
|
|
|
{/* Description */}
|
|
<div>
|
|
<label htmlFor="tree-description" className="block text-sm font-medium text-foreground">
|
|
Description
|
|
</label>
|
|
<textarea
|
|
id="tree-description"
|
|
value={description}
|
|
onChange={(e) => setDescription(e.target.value)}
|
|
placeholder="Brief description of what this tree troubleshoots..."
|
|
rows={2}
|
|
className={cn(
|
|
'mt-1 block w-full rounded-md border border-border px-3 py-2 text-sm',
|
|
'bg-card text-foreground placeholder:text-muted-foreground',
|
|
'focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary/20'
|
|
)}
|
|
/>
|
|
</div>
|
|
|
|
{/* Category */}
|
|
<div>
|
|
<label htmlFor="tree-category" className="block text-sm font-medium text-foreground">
|
|
Category
|
|
</label>
|
|
{!customCategory ? (
|
|
<select
|
|
id="tree-category"
|
|
value={categoryId || ''}
|
|
onChange={(e) => handleCategoryChange(e.target.value)}
|
|
className={cn(
|
|
'mt-1 block w-full rounded-md border border-border px-3 py-2 text-sm',
|
|
'bg-card text-foreground',
|
|
'focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary/20'
|
|
)}
|
|
>
|
|
<option value="">No category</option>
|
|
{categories.map((cat) => (
|
|
<option key={cat.id} value={cat.id}>
|
|
{cat.name}
|
|
{cat.account_id ? ' (Account)' : ''}
|
|
</option>
|
|
))}
|
|
<option value="__custom__">+ Add custom category</option>
|
|
</select>
|
|
) : (
|
|
<div className="mt-1 flex gap-2">
|
|
<input
|
|
type="text"
|
|
value={category}
|
|
onChange={(e) => setCategory(e.target.value)}
|
|
placeholder="Enter new category"
|
|
className={cn(
|
|
'block min-w-0 flex-1 rounded-md border border-border px-3 py-2 text-sm',
|
|
'bg-card text-foreground placeholder:text-muted-foreground',
|
|
'focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary/20'
|
|
)}
|
|
autoFocus
|
|
/>
|
|
<button
|
|
type="button"
|
|
onClick={() => {
|
|
setCustomCategory(false)
|
|
setCategory('')
|
|
setCategoryId(null)
|
|
}}
|
|
className="shrink-0 rounded-md border border-border px-2.5 py-2 text-xs text-muted-foreground hover:bg-accent hover:text-foreground"
|
|
>
|
|
Cancel
|
|
</button>
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
{/* Tags */}
|
|
<div>
|
|
<label className="block text-sm font-medium text-foreground">Tags</label>
|
|
<div className="mt-1">
|
|
<TagInput tags={tags} onChange={setTags} maxTags={10} placeholder="Add tags..." />
|
|
</div>
|
|
</div>
|
|
|
|
{/* Visibility */}
|
|
<div>
|
|
<label className="block text-sm font-medium text-foreground">Visibility</label>
|
|
<div className="mt-2 flex gap-4">
|
|
<label
|
|
className={cn(
|
|
'flex cursor-pointer items-center gap-2 rounded-md border px-4 py-2',
|
|
'transition-colors',
|
|
!isPublic ? 'border-primary/30 bg-accent text-foreground' : 'border-border text-muted-foreground hover:bg-accent/50'
|
|
)}
|
|
>
|
|
<input
|
|
type="radio"
|
|
name="visibility"
|
|
checked={!isPublic}
|
|
onChange={() => setIsPublic(false)}
|
|
className="sr-only"
|
|
/>
|
|
<Lock className="h-4 w-4" />
|
|
<span className="text-sm">Private</span>
|
|
</label>
|
|
<label
|
|
className={cn(
|
|
'flex cursor-pointer items-center gap-2 rounded-md border px-4 py-2',
|
|
'transition-colors',
|
|
isPublic ? 'border-primary/30 bg-accent text-foreground' : 'border-border text-muted-foreground hover:bg-accent/50'
|
|
)}
|
|
>
|
|
<input
|
|
type="radio"
|
|
name="visibility"
|
|
checked={isPublic}
|
|
onChange={() => setIsPublic(true)}
|
|
className="sr-only"
|
|
/>
|
|
<Globe className="h-4 w-4" />
|
|
<span className="text-sm">Public</span>
|
|
</label>
|
|
</div>
|
|
<p className="mt-1 text-xs text-muted-foreground">
|
|
{isPublic
|
|
? 'Anyone can view this tree'
|
|
: 'Only you and your team can view this tree'}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default TreeMetadataForm
|