fix: page tree search results do not automatically expanded#1476
fix: page tree search results do not automatically expanded#1476hexqi merged 2 commits intoopentiny:release/v2.6.xfrom
Conversation
WalkthroughThis update enhances the Tree.vue component by introducing TypeScript typings for improved type safety, especially for tree nodes and drag-and-drop handlers. It adds reactive filtering that auto-expands ancestor nodes of filtered results. The collapse map API is extended, and several function signatures are updated for clarity and consistency. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant TreeComponent
participant CollapseMap
User->>TreeComponent: Update filterValue
TreeComponent->>TreeComponent: Watch filterValue
TreeComponent->>TreeComponent: Compute filteredNodes
TreeComponent->>TreeComponent: Identify ancestors of filtered nodes
TreeComponent->>CollapseMap: setCollapse(ancestorId, false) for each ancestor
TreeComponent->>TreeComponent: Update collapse state to expand ancestors
User->>TreeComponent: Interact with drag-and-drop or collapse
TreeComponent->>CollapseMap: switchCollapse or setCollapse as needed
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 2
🔭 Outside diff range comments (1)
packages/plugins/page/src/Tree.vue (1)
242-256: Guard againstdraggedNodebeingnull– avoid hard crash
draggedNode.value!.iduses a non-null assertion butdragstartmay originate outside the component (or be prevented), leavingdraggedNodenull and throwing on every hover.-const isDescendant = getAncestorIds(node.id).includes(draggedNode.value!.id) +if (!draggedNode.value) return +const isDescendant = getAncestorIds(node.id).includes(draggedNode.value.id)A defensive check costs nothing and removes a critical runtime risk.
🧹 Nitpick comments (3)
packages/plugins/page/src/Tree.vue (3)
162-166: Duplicate filter logic – consolidate into one reactive source
filteredNodesis populated here and again in thefilterValuewatcher below, causing the samenodes.filter(...)to run twice and introducing divergence risk.
A single computed property (or a singlewatchEffect) driven by bothnodesandprops.filterValuewould be simpler and cheaper.
214-232: Minor: ensurelayerLineintermediate objects existInside the inner
forloop you assumeresult[i]was initialised in an earlier iteration.
If the algorithm changes (e.g., reverse traversal) this will explode.
Add a cheap safeguard:for (let i = parentIndex + 1; i < index; i++) { - result[i][node.level - 1] = (result[i][node.level - 1] || 0) | lines.layer + result[i] = result[i] || {} + result[i][node.level - 1] = (result[i][node.level - 1] || 0) | lines.layer }
148-160: IterativegetAncestorIdsscales better than recursionDeep trees (≫1 k levels) risk stack overflow.
Refactor to an iterative loop to remove the depth limit; the function is hot in drag-&-drop.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
packages/plugins/page/src/Tree.vue(11 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: push-check
English | 简体中文
PR
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
Background and solution
页面树搜索框,搜索结果更新后。匹配到的页面或者文件夹节点,如果被收起了,不会自动展开
What is the current behavior?
页面树搜索框,搜索结果更新后。匹配到的页面或者文件夹节点,如果被收起了,不会自动展开
Issue Number: N/A
What is the new behavior?
页面树搜索框,搜索结果更新后。匹配到的页面或者文件夹节点,如果被收起了,会自动展开并显示

Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit
Summary by CodeRabbit
New Features
Improvements