|
1 | 1 | import type { Filter, SearchMatcher, UITaskTreeNode } from '~/composables/explorer/types' |
2 | | -import { findById } from '~/composables/client' |
3 | | -import { filterAll, filterNode } from '~/composables/explorer/filter' |
| 2 | +import { client, config } from '~/composables/client' |
| 3 | +import { filterNode, runFilter } from '~/composables/explorer/filter' |
4 | 4 | import { explorerTree } from '~/composables/explorer/index' |
5 | | -import { filteredFiles, openedTreeItems, treeFilter, uiEntries } from '~/composables/explorer/state' |
| 5 | +import { openedTreeItems, treeFilter, uiEntries } from '~/composables/explorer/state' |
6 | 6 | import { |
7 | 7 | createOrUpdateNode, |
8 | 8 | createOrUpdateSuiteTask, |
9 | 9 | isFileNode, |
10 | 10 | isParentNode, |
| 11 | + replaceSubtreeEntries, |
11 | 12 | } from '~/composables/explorer/utils' |
12 | 13 |
|
13 | 14 | /** |
@@ -46,11 +47,15 @@ export function runExpandNode(id: string, search: SearchMatcher, filter: Filter) |
46 | 47 |
|
47 | 48 | const treeItems = new Set(openedTreeItems.value) |
48 | 49 | treeItems.add(node.id) |
49 | | - // collect children |
50 | | - // the first node is itself only when it is a file |
51 | | - const children = new Set(filterNode(node, search, filter)) |
| 50 | + const subtree = filterNode(node, { |
| 51 | + nodes: explorerTree.nodes, |
| 52 | + taskIdMap: client.state.idMap, |
| 53 | + search, |
| 54 | + filter, |
| 55 | + slowTestThreshold: config.value.slowTestThreshold, |
| 56 | + }) |
52 | 57 |
|
53 | | - const entries = [...collectExpandedNode(node, children)] |
| 58 | + const entries = replaceSubtreeEntries(uiEntries.value, node, subtree) |
54 | 59 | openedTreeItems.value = Array.from(treeItems) |
55 | 60 | // Keep expandAll state as it is: expanding individual shouldn't prevent expanding all the nodes ("expand all" button) |
56 | 61 | // There is a watcher on composable search.ts to reset to undefined expandAll if there are no opened items |
@@ -81,11 +86,9 @@ export function runExpandNode(id: string, search: SearchMatcher, filter: Filter) |
81 | 86 | */ |
82 | 87 | export function runExpandAll(search: SearchMatcher, filter: Filter) { |
83 | 88 | expandAllNodes(explorerTree.root.tasks, false) |
84 | | - const entries = [...filterAll(search, filter)] |
85 | 89 | treeFilter.value.expandAll = false |
86 | 90 | openedTreeItems.value = [] |
87 | | - uiEntries.value = entries |
88 | | - filteredFiles.value = entries.filter(isFileNode).map((f) => findById(f.id)!) |
| 91 | + runFilter(search, filter) |
89 | 92 | } |
90 | 93 |
|
91 | 94 | export function expandNodesOnEndRun(ids: Set<string>, end: boolean) { |
@@ -113,32 +116,3 @@ function expandAllNodes(nodes: UITaskTreeNode[], updateState: boolean) { |
113 | 116 | openedTreeItems.value = [] |
114 | 117 | } |
115 | 118 | } |
116 | | - |
117 | | -/** |
118 | | - * Build the complete next explorer entry list by emitting an expanded node and its filtered |
119 | | - * subtree at the node's current position. |
120 | | - * |
121 | | - * `children` contains only entries produced by filtering the expanded subtree. This function |
122 | | - * walks the complete current `uiEntries`. When it reaches `node`, it emits the node unless |
123 | | - * `children` already contains it, followed by the children. Unrelated entries are copied |
124 | | - * unchanged, while existing entries with the same IDs are skipped to avoid duplicates. |
125 | | - * |
126 | | - * TODO: Make this a pure splice over explicit entries and keep expansion state changes in |
127 | | - * `runExpandNode`. |
128 | | - */ |
129 | | -function* collectExpandedNode(node: UITaskTreeNode, children: Set<UITaskTreeNode>) { |
130 | | - const id = node.id |
131 | | - const ids = new Set(Array.from(children).map((n) => n.id)) |
132 | | - |
133 | | - for (const child of uiEntries.value) { |
134 | | - if (child.id === id) { |
135 | | - child.expanded = true |
136 | | - if (!ids.has(child.id)) { |
137 | | - yield node |
138 | | - } |
139 | | - yield* children |
140 | | - } else if (!ids.has(child.id)) { |
141 | | - yield child |
142 | | - } |
143 | | - } |
144 | | -} |
0 commit comments