Skip to content
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

fix(tree-select): add emit modelValue #2461

Merged

Conversation

MomoPoppy
Copy link
Collaborator

@MomoPoppy MomoPoppy commented Oct 29, 2024

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Enhanced event handling for single and multiple selections in the tree select component.
    • Improved responsiveness of the component's state based on user interactions.
  • Bug Fixes

    • Adjusted the handling of selected values for better tracking in multi-select scenarios.
  • Documentation

    • Updated method signatures to reflect new parameters for improved clarity.

Copy link

coderabbitai bot commented Oct 29, 2024

Walkthrough

The changes involve updates to the nodeClick and check functions in the packages/renderless/src/tree-select/index.ts file, enhancing event emission for both single and multiple selections. The renderless function in packages/renderless/src/tree-select/vue.ts has also been modified to include an emit parameter, improving the reactivity of the component's state. These modifications collectively improve the event handling capabilities of the tree-select component.

Changes

File Path Change Summary
packages/renderless/src/tree-select/index.ts Modified nodeClick and check functions to include event emission for single and multiple selections. Updated method signature for check.
packages/renderless/src/tree-select/vue.ts Updated renderless function to include emit parameter and changed value initialization to a computed property.

Possibly related PRs

Suggested reviewers

  • zzcr

Poem

🐇 In the garden where we play,
Events now dance and sway,
With clicks and checks, oh what a thrill,
Our selections bloom, they surely will!
So hop along, let's celebrate,
For every choice we now create! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • 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 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.

@github-actions github-actions bot added the bug Something isn't working label Oct 29, 2024
Copy link

[e2e-test-warn]
The component to be tested is missing.

The title of the Pull request should look like "fix(vue-renderless): [action-menu, alert] fix xxx bug".

Please make sure you've read our contributing guide

@MomoPoppy
Copy link
Collaborator Author

image

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


image

@MomoPoppy
Copy link
Collaborator Author

image

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


image

Copy link

@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

🧹 Outside diff range and nitpick comments (2)
packages/renderless/src/tree-select/vue.ts (1)

5-20: Consider adding JSDoc documentation

Since this is a renderless component implementation, consider adding JSDoc documentation to describe:

  1. The component's purpose
  2. The expected props interface
  3. The emitted events (especially the new modelValue emit)
  4. The returned API shape

This would improve maintainability and make it easier for other developers to use the component correctly.

packages/renderless/src/tree-select/index.ts (1)

31-46: LGTM! Consider adding type safety

The implementation correctly collects and emits multiple selected values. The event emissions follow Vue's v-model convention and are properly placed after data processing.

Consider adding type safety to improve maintainability:

-      const currentValue = []
+      const currentValue: Array<string | number> = []
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f4ca536 and 07389fa.

📒 Files selected for processing (2)
  • packages/renderless/src/tree-select/index.ts (1 hunks)
  • packages/renderless/src/tree-select/vue.ts (1 hunks)
🔇 Additional comments (5)
packages/renderless/src/tree-select/vue.ts (3)

5-5: LGTM: Function signature properly updated for v-model support

The addition of computed and emit parameters aligns with Vue's v-model implementation pattern, enabling proper two-way binding support.


9-9: LGTM: Reactive value properly implemented

Converting value to a computed property based on modelValue ensures proper reactivity and follows Vue's best practices for v-model implementation.


17-17: Verify emit implementation in check function

The emit parameter is now correctly passed to the check function, but we should verify its implementation.

✅ Verification successful

check function implementation verified and working correctly

The check function correctly uses the emit parameter to update the model value:

  • It emits 'change' and 'update:modelValue' events with the current value
  • Properly handles multiple selection mode
  • Correctly maps the checked nodes using the configured value and text fields
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the check function implementation in index.ts
# Expected: check function should use emit parameter for modelValue updates

# Search for check function implementation
ast-grep --pattern 'export const check = ({ props, vm, emit }) => {
  $$$
}'

Length of output: 78


Script:

#!/bin/bash
# Let's try to find the check function implementation with a broader search
rg "check = " -A 10

Length of output: 2492


Script:

#!/bin/bash
# Also search for any file that might contain the check function
fd "check.ts"

Length of output: 13


Script:

#!/bin/bash
# Search in the specific directory
rg "check = " packages/renderless/src/tree-select/ -A 10

Length of output: 58


Script:

#!/bin/bash
# Look for the function with a different pattern
ast-grep --pattern 'function check({ $$ }) {
  $$$
}'

Length of output: 55


Script:

#!/bin/bash
# Let's try to find the check function in the tree-select directory with a different approach
rg "check\(" packages/renderless/src/tree-select/ -A 10

Length of output: 331


Script:

#!/bin/bash
# Also look for files in the tree-select directory
fd . packages/renderless/src/tree-select/

Length of output: 131


Script:

#!/bin/bash
# Try to find any exports from index.ts in tree-select
rg "export" packages/renderless/src/tree-select/

Length of output: 475


Script:

#!/bin/bash
# Let's look at the content of index.ts to see the check function implementation
cat packages/renderless/src/tree-select/index.ts

Length of output: 1146

packages/renderless/src/tree-select/index.ts (2)

28-28: LGTM! Proper function signature update

The addition of the emit parameter to the function signature is correct and follows Vue's composition API patterns.


20-46: Verify v-model integration in parent components

The implementation of modelValue emissions is correct and follows Vue's v-model convention. However, ensure that parent components using this tree-select component have been updated to use v-model properly.

Let's verify the usage:

✅ Verification successful

Let's verify the v-model usage in these components to ensure proper integration.


V-model integration is properly implemented and used

The verification shows that the v-model implementation is correctly used across the codebase:

  • Parent components properly use v-model directive with the tree-select component
  • Both single and multiple selection modes demonstrate correct v-model usage
  • The internal implementation in pc.vue correctly binds to the state value
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for tree-select usage in parent components
rg -l "tree-select" | rg "\.vue$" | xargs rg -l "v-model"

Length of output: 1355


Script:

#!/bin/bash
# Check v-model usage in tree-select components
rg -A 2 -B 2 "v-model" examples/sites/demos/pc/app/tree-select/basic-usage.vue examples/sites/demos/pc/app/tree-select/multiple.vue packages/vue/src/tree-select/src/pc.vue

Length of output: 1151

Comment on lines +20 to +22
emit('change', data[props.valueField])
emit('update:modelValue', data[props.valueField])

Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add missing emit parameter to nodeClick function signature

The event emissions are correct, but the emit parameter needs to be added to the function signature to match its usage.

Apply this diff to fix the function signature:

-export const nodeClick = ({ props, vm }) =>
+export const nodeClick = ({ props, vm, emit }) =>

Committable suggestion was skipped due to low confidence.

@zzcr zzcr merged commit 6922d1f into opentiny:release-3.19.0 Oct 29, 2024
10 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants