({
section,
isExpanded,
workspaceCount,
hasAttention,
onToggleExpand,
onAddWorkspace,
onRename,
onChangeColor,
onDelete,
autoStartEditing = false,
onAutoCreateAbandon,
onAutoCreateRenameCancel,
})
| 37 | } |
| 38 | |
| 39 | export const SectionHeader: React.FC<SectionHeaderProps> = ({ |
| 40 | section, |
| 41 | isExpanded, |
| 42 | workspaceCount, |
| 43 | hasAttention, |
| 44 | onToggleExpand, |
| 45 | onAddWorkspace, |
| 46 | onRename, |
| 47 | onChangeColor, |
| 48 | onDelete, |
| 49 | autoStartEditing = false, |
| 50 | onAutoCreateAbandon, |
| 51 | onAutoCreateRenameCancel, |
| 52 | }) => { |
| 53 | const [isEditing, setIsEditing] = useState(false); |
| 54 | const [editValue, setEditValue] = useState(section.name); |
| 55 | const [hasEditedName, setHasEditedName] = useState(false); |
| 56 | const [showColorPicker, setShowColorPicker] = useState(false); |
| 57 | const [hexInputValue, setHexInputValue] = useState(section.color ?? ""); |
| 58 | const inputRef = useRef<HTMLInputElement>(null); |
| 59 | const autoStartHandledRef = useRef(false); |
| 60 | const wasMenuOpenOnPointerDownRef = useRef(false); |
| 61 | const sectionMenu = useContextMenuPosition(); |
| 62 | |
| 63 | const startEditing = () => { |
| 64 | setEditValue(section.name); |
| 65 | setHasEditedName(false); |
| 66 | setIsEditing(true); |
| 67 | }; |
| 68 | |
| 69 | useEffect(() => { |
| 70 | if (!autoStartEditing || autoStartHandledRef.current) { |
| 71 | return; |
| 72 | } |
| 73 | autoStartHandledRef.current = true; |
| 74 | setEditValue(section.name); |
| 75 | setHasEditedName(false); |
| 76 | setIsEditing(true); |
| 77 | }, [autoStartEditing, section.name]); |
| 78 | |
| 79 | useEffect(() => { |
| 80 | if (isEditing && inputRef.current) { |
| 81 | inputRef.current.focus(); |
| 82 | inputRef.current.select(); |
| 83 | } |
| 84 | }, [isEditing]); |
| 85 | |
| 86 | const handleSubmitRename = () => { |
| 87 | const trimmed = editValue.trim(); |
| 88 | if (trimmed && trimmed !== section.name) { |
| 89 | onRename(trimmed); |
| 90 | } else if (onAutoCreateRenameCancel) { |
| 91 | // Blur/submit with no committed rename should exit auto-create mode, |
| 92 | // otherwise a later Escape can still route through abandon/delete. |
| 93 | onAutoCreateRenameCancel(); |
| 94 | setEditValue(section.name); |
| 95 | } else { |
| 96 | setEditValue(section.name); |
nothing calls this directly
no test coverage detected