Skip to content

Conversation

@xueyitt
Copy link

@xueyitt xueyitt commented Dec 8, 2025

feat: 修正菜单排序在二级菜单不生效问题

Summary by CodeRabbit

  • New Features

    • Added enhanced sorting capabilities for hierarchical data structures, improving menu organization and display.
  • Improvements

    • Integrated new sorting utility into menu generation, ensuring consistent and customizable menu ordering.

✏️ Tip: You can customize this high-level summary in your review settings.

@changeset-bot
Copy link

changeset-bot bot commented Dec 8, 2025

⚠️ No Changeset found

Latest commit: 31a5145

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 8, 2025

Walkthrough

A new sortTree utility function is added to recursively sort tree-structured data with customizable child property names. The function is then integrated into the menu generation pipeline, replacing inline array sorting to standardize tree sorting behavior across the codebase.

Changes

Cohort / File(s) Summary
Tree utility expansion
packages/@core/base/shared/src/utils/tree.ts
Added sortTree function for recursive tree sorting with configurable child properties; updated public exports to include the new function alongside existing filterTree, mapTree, and traverseTreeValues.
Menu generation integration
packages/utils/src/helpers/generate-menus.ts
Updated imports to include sortTree from shared utilities; replaced inline menus.toSorted() call with sortTree utility to standardize tree sorting behavior.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Straightforward utility function addition with clear semantics
  • Single, uncomplicated usage integration point
  • No complex logic density or multi-pattern interactions

Possibly related PRs

Suggested reviewers

  • mynetfan
  • anncwb
  • vince292007
  • jinmao88

Poem

🐰 A tree grows tall, but jumbled and wild,
So we sort its branches, arranged and filed.
With sortTree magic, in order they stand,
The menus now flourish across all the land! 🌲✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is severely incomplete - it only contains a title repetition with no actual description, missing required sections like Type of change, detailed explanation, and checklist completion. Provide a comprehensive description including the bug/feature context, implementation details, type of change selection, and complete the pre-merge checklist with all required items marked.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and clearly relates to the changeset - it describes fixing menu sorting issues in secondary menus, which aligns with the introduction of the sortTree utility in the generateMenus file.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/@core/base/shared/src/utils/tree.ts (1)

113-122: Consider consistent immutability for all nodes.

The current implementation creates new objects for nodes with children but returns the original item for leaf nodes. For more predictable behavior and consistency, consider always creating new objects:

   return treeData.toSorted(sortFunction).map((item) => {
     const children = item[childProps];
     if (children && Array.isArray(children) && children.length > 0) {
       return {
         ...item,
         [childProps]: sortTree(children, sortFunction, options),
       };
     }
-    return item;
+    return { ...item };
   });

This ensures all returned nodes are new objects, maintaining consistent immutability throughout the tree structure.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1479f15 and 31a5145.

📒 Files selected for processing (2)
  • packages/@core/base/shared/src/utils/tree.ts (1 hunks)
  • packages/utils/src/helpers/generate-menus.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/utils/src/helpers/generate-menus.ts (1)
packages/@core/base/shared/src/utils/tree.ts (1)
  • sortTree (125-125)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Lint (ubuntu-latest)
  • GitHub Check: Check (windows-latest)
  • GitHub Check: Lint (windows-latest)
  • GitHub Check: Test (windows-latest)
  • GitHub Check: post-update (windows-latest)
  • GitHub Check: post-update (ubuntu-latest)
🔇 Additional comments (4)
packages/utils/src/helpers/generate-menus.ts (2)

9-9: LGTM: Proper import for the new utility.

The sortTree import is correctly added to support recursive menu sorting.


84-84: Good fix: Recursive sorting now works for all menu levels.

The replacement of toSorted() with sortTree() correctly addresses the issue where sorting was only applied to top-level menus. The new implementation will recursively sort all nested menu levels by the order property.

packages/@core/base/shared/src/utils/tree.ts (2)

125-125: LGTM: Export properly updated.

The sortTree function is correctly added to the public exports, making it available for use in other modules.


113-122: No action required—toSorted() is already established in this codebase.

The toSorted() method is already used in multiple files throughout the project (packages/utils/src/helpers/generate-menus.ts and packages/stores/src/modules/tabbar.ts), and the project's Node.js requirement (>=20.12.0) already supports ES2023 features since Node.js 20.0.0+. This change follows an existing pattern and does not introduce a new compatibility concern.

Likely an incorrect or invalid review comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant