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(grid): [grid] Fix bug where dragging and dropping in the expanded state of the table cannot render correctly #2901

Merged
merged 5 commits into from
Feb 19, 2025

Conversation

chenxi-20
Copy link
Collaborator

@chenxi-20 chenxi-20 commented Feb 14, 2025

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: #1995

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • Refactor
    • Improved logic for generating unique keys during grid row rendering.
    • Enhanced drag-and-drop functionality for more reliable row reordering, including better error handling and user feedback.

@chenxi-20 chenxi-20 added the bug Something isn't working label Feb 14, 2025
Copy link

coderabbitai bot commented Feb 14, 2025

Walkthrough

This change updates key assignment logic in the grid body component and refines drag-and-drop row handling. In the body component, key generation in renderRow has been streamlined and adjusted for uniqueness during dragging. In the drag handler, the retrieval of the previous row element now accounts for the class of the elements, and error handling during drag end events is enhanced. These updates aim to improve rendering consistency and the robustness of drag-and-drop operations within the grid.

Changes

File(s) Change Summary
packages/vue/src/grid/src/body/src/body.tsx - In renderRow, updated key assignment logic to ensure uniqueness during dragging.
- Introduced renderRowFlag to manage row rendering state.
packages/vue/src/grid/src/dragger/src/rowDrop.ts - Modified createHandlerOnEnd to refine logic for identifying previous and next row elements, enhancing drag-and-drop functionality and error handling for invalid moves.

Sequence Diagram(s)

sequenceDiagram
    participant User as User
    participant DragHandler as createHandlerOnEnd
    participant Grid as Grid Component

    User->>DragHandler: Ends drag event on row
    DragHandler->>Grid: Retrieve target <tr> element's previous sibling
    Grid-->>DragHandler: Return previousElementSibling
    DragHandler->>DragHandler: Check if element has 'tiny-grid-body__row' class
    DragHandler->>Grid: If valid, move row to new position
    DragHandler->>DragHandler: Validate drag operation (prevent self-child insertion)
    DragHandler-->>User: Finalize drag-and-drop operation
Loading

Possibly related PRs

Suggested reviewers

  • Zcating
  • zzcr

Poem

I'm a bunny with a hop so light,
Updating keys with all my might.
Rows now dance in unique array,
Drag-and-drop now leads the way.
Carrots and code, a joyful sight!
🐇💻

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/vue/src/grid/src/dragger/src/rowDrop.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

packages/vue/src/grid/src/body/src/body.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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

Walkthrough

此PR修复了在表格展开状态下拖拽无法正确渲染的问题。主要修改包括调整表格行的key值以确保唯一性,并在拖拽操作中正确识别和处理展开行。

Changes

文件 概要
packages/vue/src/grid/src/body/src/body.tsx 修改了表格行的key值,确保在展开状态下的唯一性。
packages/vue/src/grid/src/dragger/src/rowDrop.ts 在拖拽逻辑中添加了对展开行的识别和处理。

@chenxi-20 chenxi-20 changed the title fix(grid): [grid] 修复表格展开状态下拖拽无法正确渲染bug fix(grid): [grid] Fix bug where dragging and dropping in the expanded state of the table cannot render correctly Feb 14, 2025
@Issues-translate-bot
Copy link

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


Walkthrough

This PR fixes the issue where dragging and dropping cannot render correctly when the table is expanded. The main modifications include adjusting the key value of the table row to ensure uniqueness and correctly identifying and processing the expanded rows in the drag and drop operation.

Changes

Documents Summary
packages/vue/src/grid/src/body/src/body.tsx Modify the key value of the table row to ensure uniqueness in the expanded state.
packages/vue/src/grid/src/dragger/src/rowDrop.ts Added recognition and processing of expanded rows in drag and drop logic.

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

🧹 Nitpick comments (1)
packages/vue/src/grid/src/dragger/src/rowDrop.ts (1)

64-66: Enhance null safety with optional chaining.

The current implementation could throw if prevEl is null. Consider using optional chaining for safer property access.

-    let prevTrElem =
-      prevEl && prevEl.classList.contains('tiny-grid-body__row') ? prevEl : prevEl && prevEl.previousElementSibling
+    let prevTrElem =
+      prevEl?.classList.contains('tiny-grid-body__row') ? prevEl : prevEl?.previousElementSibling
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3511adc and 77080a1.

📒 Files selected for processing (2)
  • packages/vue/src/grid/src/body/src/body.tsx (1 hunks)
  • packages/vue/src/grid/src/dragger/src/rowDrop.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/vue/src/grid/src/body/src/body.tsx
🧰 Additional context used
🪛 Biome (1.9.4)
packages/vue/src/grid/src/dragger/src/rowDrop.ts

[error] 66-67: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 67-68: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (4)
packages/vue/src/grid/src/dragger/src/rowDrop.ts (4)

29-29: LGTM! Import of row ID generator.

The addition of getRowUniqueId import supports the fix for rendering issues in expanded state by ensuring unique row identification.


63-63: LGTM! Improved element property access.

The destructuring assignment enhances code readability by clearly showing which properties are needed from the target element.


72-75: LGTM! Enhanced row identification during drag operations.

The addition of unique row IDs for both current and previous rows ensures correct rendering and state management during drag operations, particularly in expanded state.

Also applies to: 79-79


101-101: LGTM! Improved drag validation for expanded rows.

The addition of class validation ensures correct handling of drag operations when dealing with expanded rows.

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

🧹 Nitpick comments (3)
packages/vue/src/grid/src/dragger/src/rowDrop.ts (3)

62-65: Consider using optional chaining for safer element access.

The element access could be made more robust using optional chaining to handle cases where elements might be null.

-    const { parentNode: wrapperElem, previousElementSibling: prevEl, nextElementSibling: nextEl } = targetTrElem
-    let prevTrElem =
-      prevEl && prevEl.classList.contains('tiny-grid-body__row') ? prevEl : prevEl && prevEl.previousElementSibling
+    const { parentNode: wrapperElem, previousElementSibling: prevEl, nextElementSibling: nextEl } = targetTrElem
+    let prevTrElem =
+      prevEl?.classList.contains('tiny-grid-body__row') ? prevEl : prevEl?.previousElementSibling

70-70: Fix typo in property name.

The property _isDraging has a typo and should be _isDragging to follow correct spelling.

-    selfRow._isDraging = true
+    selfRow._isDragging = true

98-103: LGTM! Good handling of first-row drag-and-drop.

The implementation correctly handles dragging to the first position while maintaining data consistency. Consider extracting the class name to a constant for maintainability.

+const ROW_CLASS = 'tiny-grid-body__row'
+
-      } else if (nextEl && nextEl.classList.contains('tiny-grid-body__row')) {
+      } else if (nextEl?.classList.contains(ROW_CLASS)) {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 403c549 and 218d23e.

📒 Files selected for processing (2)
  • packages/vue/src/grid/src/body/src/body.tsx (4 hunks)
  • packages/vue/src/grid/src/dragger/src/rowDrop.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/vue/src/grid/src/body/src/body.tsx
🧰 Additional context used
🪛 Biome (1.9.4)
packages/vue/src/grid/src/dragger/src/rowDrop.ts

[error] 65-66: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 66-67: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: PR E2E Test (pnpm test:e2e3)
🔇 Additional comments (1)
packages/vue/src/grid/src/dragger/src/rowDrop.ts (1)

67-70: LGTM! Implementation respects data integrity.

The changes correctly handle row reordering without modifying user-specified properties like rowId, addressing previous review feedback.

@zzcr zzcr merged commit 2fb6814 into dev Feb 19, 2025
14 of 15 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.

4 participants