-
Notifications
You must be signed in to change notification settings - Fork 16
fix(table): prevent scrolling to top after selecting a row at the bottom #3726
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
base: main
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughRefactors the Table component's data update flow to compare row IDs instead of raw row data for determining replacement logic. Introduces ID-based decision-making alongside a new row-change detection mechanism. Adds unit tests validating the updated behavior with mocked tabulator methods. Changes
Sequence DiagramsequenceDiagram
participant Component as Table Component
participant Logic as Update Logic
participant Tabulator as Tabulator Instance
Component->>Logic: updateData(newData)
activate Logic
Logic->>Logic: newIds = getRowIds(newData)
Logic->>Logic: oldIds = getRowIds(currentData)
rect rgb(200, 230, 255)
Note over Logic: Check if replacement needed
Logic->>Logic: shouldReplaceData(newIds, oldIds)?
end
alt Replacement needed
Logic->>Tabulator: replaceData(newData)
else No replacement, check row updates
rect rgb(200, 230, 255)
Note over Logic: Check if rows changed
Logic->>Logic: hasRowUpdates(newData, currentData)?
end
alt Row updates exist
Logic->>Tabulator: updateData(changedRows)
Logic->>Tabulator: setSelection(preserved)
else No updates, add missing
Logic->>Tabulator: updateOrAddData(newData)
end
end
deactivate Logic
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Suggested labels
Suggested reviewers
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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: 2
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (2)
src/components/table/table.spec.ts(1 hunks)src/components/table/table.tsx(3 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.tsx
📄 CodeRabbit inference engine (.cursor/rules/wrap-multiple-jsx-elements-in-host-not-in-array.mdc)
When returning multiple JSX elements from the
rendermethod, never wrap them in an array literal. Instead, always wrap them in the special<Host>element. When there is already a single top-level element, it does not have to be wrapped in<Host>.
Files:
src/components/table/table.tsx
⚙️ CodeRabbit configuration file
**/*.tsx: Our.tsxfiles are typically using StencilJS, not React. When a developer wants to return multiple top-level JSX elements from therendermethod, they will sometimes wrap them in an array literal. In these cases, rather than recommending they addkeyproperties to the elements, recommend removing the hardcoded array literal. Recommend wrapping the elements in StencilJS's special<Host>element.
Files:
src/components/table/table.tsx
**/*.{ts,tsx}
⚙️ CodeRabbit configuration file
**/*.{ts,tsx}: Imports from other files in the same module (lime-elements) must use relative paths. Using absolute paths for imports will cause the production build to fail.
Files:
src/components/table/table.tsxsrc/components/table/table.spec.ts
**/*.{tsx,scss}
⚙️ CodeRabbit configuration file
**/*.{tsx,scss}: Almost all our components use shadow-DOM. Therefore, we have no need of BEM-style class names in our CSS.
Files:
src/components/table/table.tsx
src/components/**/*.tsx
⚙️ CodeRabbit configuration file
src/components/**/*.tsx: When contributors add new props to existing components in the lime-elements repository, they should always add documentation examples that demonstrate the new prop's usage and explain how it works. This helps with user adoption, feature discoverability, and maintains comprehensive documentation.
Files:
src/components/table/table.tsx
🧬 Code graph analysis (1)
src/components/table/table.tsx (2)
src/components/table/utils.ts (1)
areRowsEqual(4-12)src/components/table/table.types.ts (1)
RowData(217-219)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Docs / Publish Docs
- GitHub Check: Test
- GitHub Check: Build
🔇 Additional comments (2)
src/components/table/table.tsx (2)
284-312: LGTM! The ID-based update flow correctly prevents unnecessaryreplaceDatacalls.The refactored logic properly distinguishes between three scenarios:
- IDs/order changed →
replaceData(scroll resets)- IDs same, content changed →
updateData(scroll preserved) ✓ This is the key improvement- IDs same, content same →
updateOrAddData(idempotent fallback)Calling
setSelection()after bothreplaceDataandupdateDataensures selection state is maintained.
420-438: LGTM! Helper methods correctly implement ID comparison logic.
areEqualIds: Properly uses Set-based comparison to check if the same IDs exist (regardless of order)isSameOrder: Correctly verifies positional equalityBoth methods work as intended for primitive IDs (strings/numbers). The object reference issue noted in
getRowIdsis upstream of these helpers.
45740f9 to
11cb3cd
Compare
fix https://github.com/Lundalogik/crm-client/issues/398
When a user clicks a row in “table view”, we pass the same data back into
limel-table, but the component was always calling Tabulator’sreplaceData. That API wipes the whole table and rebuilds it, so the effect that the user sees is that the table suddenly scrolls to the top every time, even though nothing really changed.Because we expected a re-render after each click (in CRM web client, a sidepane opens, selection updates, etc.), this full rebuild happened on every interaction, which is why the scroll position kept jumping upward.
The fix stops using
replaceDatawhen we’re only updating the contents of existing rows. If the set or order of row IDs is unchanged, we now call Tabulator’s lighterupdateDatainstead. That API updates the rows in place, so the table keeps its scroll state and focus. We still fall back toreplaceDatawhen IDs or ordering truly change, so pagination and sorting continue to work as before.from
index.d.ts👇IN CRM web-client,
limec-table-viewfeedslimel-tablewith an array ofLimeObject. Those objects come straight from the CRM backend and always include the primary key inobject.id. Nothing in table-view strips or reshapes the data—when we render rows we spread the source object, and the only time we touch it is to passdata.iddown to header/row components. So the table keeps the original stableidon every render, which means our new scroll-preserving logic in this PR stays active for table view.Summary by CodeRabbit
Tests
Improvements
Review:
Browsers tested:
(Check any that applies, it's ok to leave boxes unchecked if testing something didn't seem relevant.)
Windows:
Linux:
macOS:
Mobile: