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

Release319 fix(transfer): fix drag 2 item to right when set filterable=true #2517

Merged
merged 2 commits into from
Nov 12, 2024

Conversation

shenjunjian
Copy link
Collaborator

@shenjunjian shenjunjian commented Nov 12, 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

    • Updated the version of the @opentiny/vue-renderless package to 3.19.5.
    • Enhanced item movement logic between panels, improving data manipulation accuracy.
    • Introduced a new parameter to key functions for better access to Vue instance properties.
  • Bug Fixes

    • Adjusted logic for determining keys during item addition/removal to utilize filtered data correctly.

Copy link

coderabbitai bot commented Nov 12, 2024

Walkthrough

The pull request includes an update to the version number of the @opentiny/vue-renderless package from 3.19.4 to 3.19.5 in the package.json file. Additionally, modifications were made to the logicFun function in index.ts to include a new parameter vm, which enhances its capability to manage data between two panels. The renderless function in vue.ts was also updated to accommodate this new parameter, allowing for improved interaction with the Vue instance.

Changes

File Change Summary
packages/renderless/package.json Updated version from 3.19.4 to 3.19.5.
packages/renderless/src/transfer/index.ts Updated logicFun function signature to include new vm parameter; adjusted key determination logic.
packages/renderless/src/transfer/vue.ts Updated renderless function signature to include new vm parameter; modified logicFun call to pass vm.

Possibly related PRs

Suggested labels

bug

Suggested reviewers

  • zzcr

🐰 In the meadow where bunnies play,
A version update brightens the day.
With logic refined and panels in sync,
Our code hops forward, faster than you think!
So here's to the changes, both big and small,
In the world of renderless, we celebrate all! 🌼


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.

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

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: 3

🧹 Outside diff range and nitpick comments (1)
packages/renderless/src/transfer/index.ts (1)

220-233: Consider decoupling the renderless logic from Vue component structure

The current implementation creates tight coupling between the renderless logic and Vue component structure by directly accessing component refs. Consider refactoring to pass filtered data as parameters to maintain the renderless nature of the component.

Example approach:

interface LogicFunParams {
  leftFilteredData: any[];
  rightFilteredData: any[];
  // ... other params
}

const logicFun = ({ props, emit, state, leftFilteredData, rightFilteredData }: LogicFunParams) => {
  // Use passed filtered data instead of accessing through refs
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between c1496ee and a3a2442.

📒 Files selected for processing (3)
  • packages/renderless/package.json (1 hunks)
  • packages/renderless/src/transfer/index.ts (1 hunks)
  • packages/renderless/src/transfer/vue.ts (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/renderless/package.json
🔇 Additional comments (2)
packages/renderless/src/transfer/vue.ts (2)

83-83: LGTM: Consistent parameter passing

The update to include vm in the logicFun call aligns with the function signature changes and supports the PR's objective of fixing drag functionality with filterable enabled.


64-64: Verify the impact of adding the vm parameter

The addition of the vm parameter to the ITransferRenderlessParamUtils interface could potentially be a breaking change.

✅ Verification successful

Based on the results, I can now provide the final response:

The vm parameter addition is safe and follows existing patterns

The vm parameter is already part of the ISharedRenderlessParamUtils interface which is used by multiple renderless components (tree-menu, tooltip, popover, etc.). This change aligns with the existing codebase patterns and is not a breaking change since:

  • The type ITransferRenderlessParamUtils inherits from ISharedRenderlessParamUtils
  • Other renderless components already use the vm parameter in the same way
  • The implementation is consistent with the type definitions in transfer.type.ts
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for existing implementations that might be affected

# Search for any files importing and using the renderless function
rg -l "from.*transfer/vue.*renderless" 

# Search for implementations of ITransferRenderlessParamUtils
ast-grep --pattern 'interface ITransferRenderlessParamUtils {
  $$$
}'

Length of output: 113


Script:

#!/bin/bash
# Let's try different search patterns to find usages and type definitions

# Search for Transfer component imports and usages
rg -l "Transfer" 

# Search for ITransferRenderlessParamUtils in typescript files
rg -t ts "ITransferRenderlessParamUtils"

# Search for transfer renderless function usage
rg "transfer.*renderless"

# Look for vue transfer files
fd "transfer.*vue"

# Search for vm parameter usage in transfer related files
rg "vm.*transfer"

Length of output: 3780


Script:

#!/bin/bash
# Let's examine the type definition and its inheritance

# Check the content of the transfer type file
cat packages/renderless/types/transfer.type.ts

# Look for ISharedRenderlessParamUtils definition
rg -t ts "interface ISharedRenderlessParamUtils"

# Check if vm is used in other renderless components
rg -t ts "vm.*}: ISharedRenderlessParamUtils"

# Check the actual implementation in vue.ts
cat packages/renderless/src/transfer/vue.ts

Length of output: 6202

@@ -217,17 +217,20 @@ export const clearQuery = (refs: ITransferRenderlessParams['refs']) => (which: '

/** SortableJs 插件的回调逻辑, 添加,删除,更新事件后,触发本函数 */
export const logicFun =
({ props, emit, state }: Pick<ITransferRenderlessParams, 'emit' | 'props' | 'state'>) =>
({ props, emit, state, vm }: Pick<ITransferRenderlessParams, 'emit' | 'props' | 'state'>) =>
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Update type annotation to include vm parameter

The type annotation is missing the vm parameter in the Pick type utility.

Apply this fix:

-({ props, emit, state, vm }: Pick<ITransferRenderlessParams, 'emit' | 'props' | 'state'>) =>
+({ props, emit, state, vm }: Pick<ITransferRenderlessParams, 'emit' | 'props' | 'state' | 'vm'>) =>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
({ props, emit, state, vm }: Pick<ITransferRenderlessParams, 'emit' | 'props' | 'state'>) =>
({ props, emit, state, vm }: Pick<ITransferRenderlessParams, 'emit' | 'props' | 'state' | 'vm'>) =>

Comment on lines +228 to +230
const rightPanel = vm.$refs.rightPanel
const leftPanel = vm.$refs.leftPanel

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 null checks for panel refs

The panel refs should be checked for null to prevent runtime errors.

Apply this fix:

-      const rightPanel = vm.$refs.rightPanel
-      const leftPanel = vm.$refs.leftPanel
+      const rightPanel = vm.$refs.rightPanel
+      const leftPanel = vm.$refs.leftPanel
+      
+      if (!rightPanel?.state?.filteredData || !leftPanel?.state?.filteredData) {
+        return
+      }

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines +232 to +233
? rightPanel.state.filteredData[event.oldIndex][props.props.key]
: leftPanel.state.filteredData[event.oldIndex][props.props.key]
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 bounds check for array access

The array access using oldIndex should be bounds-checked to prevent undefined access.

Apply this fix:

-        ? rightPanel.state.filteredData[event.oldIndex][props.props.key]
-        : leftPanel.state.filteredData[event.oldIndex][props.props.key]
+        ? (rightPanel.state.filteredData[event.oldIndex] || {})[props.props.key]
+        : (leftPanel.state.filteredData[event.oldIndex] || {})[props.props.key]

Additionally, consider adding validation:

+      if (event.oldIndex < 0 || 
+          (isAdd && event.oldIndex >= rightPanel.state.filteredData.length) ||
+          (!isAdd && event.oldIndex >= leftPanel.state.filteredData.length)) {
+        return
+      }

Committable suggestion skipped: line range outside the PR's diff.

@zzcr zzcr merged commit cd67330 into opentiny:release-3.19.0 Nov 12, 2024
5 checks passed
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