Skip to content

feat: [vben-tree]增加数据disabled #6343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

gatspy
Copy link

@gatspy gatspy commented Jun 6, 2025

Description

目前 VbenTree 不支持树形数据中的disabled属性来控制节点是否可选,解决 #6342

const treeData = ref<any[]>([
  {
    id: 1,
    label: 'Level one 1',
    children: [
      {
        id: 3,
        label: 'Level two 2-1',
        children: [
          {
            id: 4,
            label: 'Level three 3-1-1',
          },
          {
            id: 5,
            label: 'Level three 3-1-2',
            disabled: true,
          },
        ],
      },
      {
        id: 2,
        label: 'Level two 2-2',
        disabled: true,
        children: [
          {
            id: 6,
            label: 'Level three 3-2-1',
          },
          {
            id: 7,
            label: 'Level three 3-2-2',
            disabled: true,
          },
        ],
      },
    ],
  },
]);

const formDisabled = ref(false);
    <VbenTree
      :tree-data="treeData"
      multiple
      bordered
      :default-expanded-level="2"
      :get-node-class="getNodeClass"
      value-field="id"
      label-field="label"
      :disabled="formDisabled"
      disabled-field="disabled"
    >

const formDisabled = ref(false);
image

const formDisabled = ref(true);
image

Summary by CodeRabbit

  • New Features

    • Tree nodes can now be marked as disabled using a configurable field, preventing selection, toggling, or interaction with those nodes.
    • Disabled nodes are visually indicated in the tree view.
  • Bug Fixes

    • Disabled nodes are excluded from selected values and model updates.

Copy link

changeset-bot bot commented Jun 6, 2025

⚠️ No Changeset found

Latest commit: 76da265

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

Copy link
Contributor

coderabbitai bot commented Jun 6, 2025

Walkthrough

A new disabledField prop was introduced to the tree component, allowing customization of the field that marks tree nodes as disabled. The logic and UI were updated to ensure disabled nodes cannot be selected, toggled, or interacted with, and are visually indicated as disabled throughout the component.

Changes

File(s) Change Summary
.../tree.vue Added disabledField prop, isNodeDisabled helper, and updated event handlers and UI logic to handle disabled nodes.
.../tree/types.ts Added optional disabledField property to TreeProps interface.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TreeComponent
    participant Node

    User->>TreeComponent: Attempt to interact with Node
    TreeComponent->>Node: Check isNodeDisabled
    alt Node is disabled
        TreeComponent-->>User: Ignore interaction, visually indicate disabled
    else Node is enabled
        TreeComponent->>Node: Proceed with selection/toggle
        Node-->>TreeComponent: Update model/value
    end
Loading

Poem

In the forest of code, a new rule was decreed,
Some nodes now rest, from selection they're freed.
With a hop and a skip, the rabbit ensures,
Disabled means peace, no clicks to endure.
The tree now stands strong, both nimble and wise,
With fields for the quiet, and fields for the prize!
🐇🌳


📜 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 b4d6fe9 and 76da265.

📒 Files selected for processing (1)
  • packages/@core/ui-kit/shadcn-ui/src/ui/tree/tree.vue (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/@core/ui-kit/shadcn-ui/src/ui/tree/tree.vue
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: post-update (ubuntu-latest)
  • GitHub Check: post-update (windows-latest)

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
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need 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)

  • @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 generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b9aef61 and b4d6fe9.

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

25-26: LGTM!

The addition of the optional disabledField property to the TreeProps interface is well-structured and follows the existing pattern for field customization properties.

packages/@core/ui-kit/shadcn-ui/src/ui/tree/tree.vue (5)

26-26: LGTM!

The prop definition with a sensible default value of 'disabled' follows Vue best practices.


105-124: Well-implemented disabled node filtering!

The logic correctly filters out disabled nodes from the selection and ensures the model value stays synchronized. The approach of updating modelValue when disabled nodes are detected prevents inconsistent state.


128-136: Consistent disabled node handling!

The function correctly filters out disabled nodes before updating the model value, maintaining consistency with updateTreeValue.


174-176: Good abstraction for disabled state checking!

The helper function properly checks both the global disabled state and individual node disabled state.


182-185: Comprehensive disabled state handling throughout the UI!

The event handlers and UI bindings correctly:

  • Prevent interactions with disabled nodes
  • Apply appropriate visual styling for disabled state
  • Stop event propagation to avoid unintended side effects
  • Blur focus from disabled nodes

Also applies to: 257-264, 267-277, 305-316, 322-331

jinmao88 and others added 2 commits June 8, 2025 17:57
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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.

2 participants