Skip to content

Commit 7539ab4

Browse files
author
Eric Wheeler
committed
feat: respect parent bulk expansion for new child tasks
When a parent task in the history view is bulk-expanded, newly added child tasks will now automatically inherit this expanded state. This ensures that the visibility of new sub-tasks aligns with the user's current view settings for the parent, providing a more consistent and intuitive user experience when navigating hierarchical task histories. Signed-off-by: Eric Wheeler <[email protected]>
1 parent cb745e1 commit 7539ab4

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

webview-ui/src/components/history/useTaskSearch.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,32 @@ export const useTaskSearch = () => {
143143
return sortTasksRecursive(rootTasks)
144144
}, [presentableTasks, searchQuery, fzf, sortOption])
145145

146+
useEffect(() => {
147+
// This effect ensures that newly added children of bulk-expanded parents are also expanded.
148+
setExpandedItems((prevExpanded) => {
149+
let newExpanded = { ...prevExpanded }
150+
let changed = false
151+
152+
const checkAndExpandChildrenRecursive = (currentTasks: HierarchicalHistoryItem[]) => {
153+
for (const item of currentTasks) {
154+
if (item.parent_task_id && bulkExpandedRootItems[item.parent_task_id]) {
155+
if (!newExpanded[item.id]) {
156+
newExpanded[item.id] = true
157+
changed = true
158+
}
159+
}
160+
if (item.children && item.children.length > 0) {
161+
checkAndExpandChildrenRecursive(item.children)
162+
}
163+
}
164+
}
165+
166+
checkAndExpandChildrenRecursive(tasks) // `tasks` is the hierarchical list
167+
168+
return changed ? newExpanded : prevExpanded
169+
})
170+
}, [tasks, bulkExpandedRootItems, setExpandedItems])
171+
146172
const toggleItemExpansion = useCallback(
147173
(taskId: string) => {
148174
setExpandedItems((prev) => ({

0 commit comments

Comments
 (0)