-
Notifications
You must be signed in to change notification settings - Fork 284
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
Conversation
WalkthroughThis change updates key assignment logic in the grid body component and refines drag-and-drop row handling. In the body component, key generation in Changes
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
Possibly related PRs
Suggested reviewers
Poem
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
packages/vue/src/grid/src/dragger/src/rowDrop.tsOops! 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:
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.tsxOops! 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:
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
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Walkthrough此PR修复了在表格展开状态下拖拽无法正确渲染的问题。主要修改包括调整表格行的 Changes
|
WalkthroughThis PR fixes the issue where dragging and dropping cannot render correctly when the table is expanded. The main modifications include adjusting the Changes
|
There was a problem hiding this 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
📒 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.
There was a problem hiding this 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
📒 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.
PR
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #1995
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit