Skip to content

Conversation

@mynetfan
Copy link
Collaborator

@mynetfan mynetfan commented Mar 31, 2025

Description

修复VbenTree的值未能正确同步的问题

fixed: #5822

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Checklist

ℹ️ Check all checkboxes - this will indicate that you have done everything in accordance with the rules in CONTRIBUTING.

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs:dev command.
  • Run the tests with pnpm test.
  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Summary by CodeRabbit

  • Refactor
    • Streamlined the tree component’s state management and selection behavior.
    • Updated interaction handling to consistently add selections and explicitly prevent default actions during user interactions.
    • Simplified the interface by removing the modelValue property, enhancing overall user experience with a more straightforward and predictable selection process.

@changeset-bot
Copy link

changeset-bot bot commented Mar 31, 2025

⚠️ No Changeset found

Latest commit: 331dca8

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 Mar 31, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request simplifies the model handling logic in the tree component. In tree.vue, the useVModel function is removed and replaced with defineModel for the modelValue, and the selection functions are streamlined. Additionally, the modelValue property is removed from the TreeProps interface in types.ts, aligning the component’s data management with a simpler approach.

Changes

File(s) Change Summary
packages/@core/ui-kit/shadcn-ui/src/ui/tree/tree.vue
packages/@core/ui-kit/shadcn-ui/src/ui/tree/types.ts
Replaced useVModel with `defineModel<Arrayable<number

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TreeComponent
    User->>TreeComponent: Initiates selection event
    TreeComponent->>TreeComponent: Calls event.preventDefault()
    TreeComponent->>TreeComponent: Executes onSelect()
    TreeComponent->>TreeComponent: Invokes updateTreeValue() (checks for undefined and maps values)
Loading

Assessment against linked issues

Objective (Issues) Addressed Explanation
Bug: Role editing page shows previous selections (#5822)

Possibly related PRs

  • fix: auto check parent after node selected #5794: The changes in the main PR are related to the modifications of the modelValue handling in the tree.vue file, while the retrieved PR alters the onSelect function to include logic for selecting parent nodes, which also involves modelValue, indicating a direct connection in their functionality.
  • fix: vbenTree modelValue synchronization #5825: The changes in the main PR and the retrieved PR are directly related as they both involve the same modifications to the modelValue handling in the tree.vue file and the removal of the modelValue property from the TreeProps interface in types.ts.

Suggested reviewers

  • anncwb
  • jinmao88
  • vince292007

Poem

I'm a little rabbit, hopping through the code,
Clearing tangled branches on our streamlined node,
No more old logic to pull down the tree,
Just crisp, clean hops with clarity,
Celebrating each change with a joyful, bouncy ode!
🥕🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0944aca and 331dca8.

📒 Files selected for processing (2)
  • packages/@core/ui-kit/shadcn-ui/src/ui/tree/tree.vue (3 hunks)
  • packages/@core/ui-kit/shadcn-ui/src/ui/tree/types.ts (0 hunks)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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 (2)
packages/@core/ui-kit/shadcn-ui/src/ui/tree/tree.vue (2)

269-270: Consider cleaning up commented code in template

There are several commented lines in the event handling section that appear to be leftover from previous implementations. Consider removing these comments to improve code readability and maintenance.

          @click="
            () => {
              handleSelect();
-              // onSelect(item, !isSelected);
            }
          "
        />
        <div
          class="flex items-center gap-1 pl-2"
          @click="
            (_event) => {
-              // $event.stopPropagation();
-              // $event.preventDefault();
              handleSelect();
-              // onSelect(item, !isSelected);
            }
          "

Also applies to: 277-281


155-176: Consider simplifying the onSelect function further

While the PR addresses the main synchronization issue, the onSelect function still contains complex logic for parent-child relationships. Since you've moved to the defineModel pattern, consider further simplifying this function and leveraging more of radix-vue's built-in functionality for propagation.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a0feeb1 and 0944aca.

📒 Files selected for processing (2)
  • packages/@core/ui-kit/shadcn-ui/src/ui/tree/tree.vue (3 hunks)
  • packages/@core/ui-kit/shadcn-ui/src/ui/tree/types.ts (0 hunks)
💤 Files with no reviewable changes (1)
  • packages/@core/ui-kit/shadcn-ui/src/ui/tree/types.ts
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Test (windows-latest)
  • GitHub Check: Check (windows-latest)
  • GitHub Check: Lint (windows-latest)
  • GitHub Check: post-update (windows-latest)
  • GitHub Check: post-update (ubuntu-latest)
🔇 Additional comments (3)
packages/@core/ui-kit/shadcn-ui/src/ui/tree/tree.vue (3)

76-76: Good use of defineModel for simplified two-way binding

Replacing useVModel with Vue 3's defineModel is a cleaner approach for handling two-way binding. This change eliminates the need for manual deep watching and default value assignment, which were likely sources of the synchronization issues.


101-107: Proper handling of undefined modelValue cases

The addition of an explicit check for undefined modelValue values ensures the component behaves correctly in edge cases, such as when no initial value is provided or when the value is cleared. This fix directly addresses potential synchronization issues when the value is reset or undefined.


233-233: Event propagation prevention is now active

Uncommenting the event.preventDefault() call ensures that native browser events don't interfere with the custom selection logic, preventing potential issues with event bubbling that could affect selection behavior.

@mynetfan mynetfan merged commit 06ccad9 into vbenjs:main Mar 31, 2025
10 checks passed
@mynetfan mynetfan deleted the fix/vben-tree branch March 31, 2025 02:18
@github-actions github-actions bot locked and limited conversation to collaborators May 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: 角色编辑页面当前已选中的菜单是上次选中的结果

1 participant