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(transfer): [transfer] fix drag 2 item to right when set filterable=true #2492

Merged
merged 2 commits into from
Nov 12, 2024

Conversation

shenjunjian
Copy link
Collaborator

@shenjunjian shenjunjian commented Nov 7, 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 data handling during drag-and-drop operations in sortable panels, improving accuracy in data manipulation.
  • Bug Fixes

    • Updated logic for retrieving filtered data from left and right panels to ensure correct item addition and removal.
  • Chores

    • Updated package version from 3.18.6 to 3.18.7.

Copy link

coderabbitai bot commented Nov 7, 2024

Walkthrough

The pull request introduces modifications to the logicFun and renderless functions within the transfer component. The logicFun function now accepts an additional parameter vm, allowing direct access to the left and right panel references for improved data handling during drag-and-drop operations. The renderless function has also been updated to pass this new parameter when calling logicFun. These changes enhance the accuracy of data manipulation without altering the overall structure or other functionalities of the component.

Changes

File Path Change Summary
packages/renderless/src/transfer/index.ts Updated logicFun to include vm in the parameter list and modified data retrieval logic for panels.
packages/renderless/src/transfer/vue.ts Updated renderless function to include vm in the parameter list and adjusted the call to logicFun.
packages/renderless/package.json Updated version from 3.18.6 to 3.18.7.

Possibly related PRs

Suggested reviewers

  • zzcr

🐰 In the land of code where rabbits play,
A new vm joins the fun today!
With panels sorted, data flows,
Dragging and dropping, watch how it goes!
Logic refined, the state is bright,
Hopping along, everything feels right! 🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8f38804 and 227f45b.

📒 Files selected for processing (1)
  • packages/renderless/package.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/renderless/package.json

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

@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 (1)
packages/renderless/src/transfer/index.ts (1)

232-233: Add array bounds check and approve filtered data usage.

The change to use filteredData from panel refs correctly fixes the drag functionality when filterable=true. However, add bounds checking to prevent undefined access:

-        ? 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]
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1ed1721 and 8f38804.

📒 Files selected for processing (2)
  • packages/renderless/src/transfer/index.ts (1 hunks)
  • packages/renderless/src/transfer/vue.ts (2 hunks)
🔇 Additional comments (4)
packages/renderless/src/transfer/vue.ts (2)

64-64: LGTM: Clean parameter addition

The addition of the vm parameter to the function signature is well-structured and maintains proper TypeScript typing through the ITransferRenderlessParamUtils interface.


83-83: Verify panel references access

The update to include vm in the logicFun call looks correct. However, let's verify that the panel references are properly accessed in the implementation.

✅ Verification successful

Panel references are correctly accessed through vm parameter

The implementation shows proper usage of panel references through vm.$refs:

  • vm.$refs.rightPanel and vm.$refs.leftPanel are correctly accessed to get panel data
  • These refs are used to access the filtered data and handle item transfers between panels
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of logicFun and its usage of panel references
# Expected: Find the implementation showing proper usage of vm parameter to access panel refs

# Search for logicFun implementation
ast-grep --pattern 'export const logicFun = $_'

# Backup: Search using ripgrep if ast-grep doesn't find it
rg -A 10 'export const logicFun'

Length of output: 3965

packages/renderless/src/transfer/index.ts (2)

220-233: Verify edge cases with manual testing.

While the changes correctly fix the drag functionality when filterable=true, please ensure the following scenarios are tested:

  1. Dragging when filter returns no results
  2. Dragging when filter returns single item
  3. Dragging with filter applied to both panels

Let's check if there are any existing tests we should update:


220-220: Add type annotation for the vm parameter.

The vm parameter lacks proper TypeScript type annotation. This should be properly typed to maintain type safety.

Let's verify all callers of this function to ensure they're updated:

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 code assumes that panel refs will always be available. Add null checks to prevent runtime errors:

-      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) {
+        console.warn('Transfer panel refs or filtered data not available')
+        return
+      }
📝 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
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) {
console.warn('Transfer panel refs or filtered data not available')
return
}

@kagol kagol added the bug Something isn't working label Nov 12, 2024
@zzcr zzcr merged commit fb61081 into opentiny:release-3.18.0 Nov 12, 2024
3 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