Skip to content

feat: implement infinite scroll hook#40050

Merged
jacquesikot merged 3 commits intoreleasefrom
feat/fetch-page-on-infinite-scroll
Apr 3, 2025
Merged

feat: implement infinite scroll hook#40050
jacquesikot merged 3 commits intoreleasefrom
feat/fetch-page-on-infinite-scroll

Conversation

@jacquesikot
Copy link
Contributor

@jacquesikot jacquesikot commented Apr 3, 2025

✨ Optimized Infinite Scrolling for TableWidgetV2

📌 Problem

The infinite scrolling feature in TableWidgetV2 did not load the correct number of pages (2) on init, and the table rows length was more than the data fetched

✅ Solution

This PR optimizes infinite scrolling by:

  • 📥 Automatically loading the next page of data when the initial rows are ≤ 1 page
  • 📊 Simplifying row count management by using the actual rows length instead of relying on totalRecordsCount which does not tell actual rows loaded into the table

🚀 How to Test

  1. Enable Infinite Scroll in TableWidgetV2.
  2. Ensure that additional pages (page 2) loads automatically when the initial rows are ≤ 1 page.
  3. Verify that pagination behavior remains consistent with expected results.

Fixes #Issue Number
or
Fixes Issue URL

Warning

If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.

Automation

/ok-to-test tags="@tag.Widget, @tag.Table, @tag.Binding, @tag.Sanity"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/14241762644
Commit: 8bf69c9
Cypress dashboard.
Tags: @tag.Widget, @tag.Table, @tag.Binding, @tag.Sanity
Spec:


Thu, 03 Apr 2025 12:53:32 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced a new useInfiniteScroll hook to enhance infinite scrolling functionality in the table widget.
  • Refactor

    • Simplified pagination logic by directly utilizing the length of the rows array, improving performance and clarity.
  • Bug Fixes

    • Adjusted test data and assertions in the Cypress test suite to better reflect the expected behavior of the table widget under varying content conditions.

@jacquesikot jacquesikot requested a review from a team as a code owner April 3, 2025 05:12
@jacquesikot jacquesikot requested review from vivek-appsmith and removed request for a team April 3, 2025 05:12
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 3, 2025

Walkthrough

The changes refactor the infinite scrolling logic in the table widget. The code replaces the previous computation of itemCount (using a memoized calculation of totalRecordsCount) by directly using rows.length. A new custom hook, useInfiniteScroll, is added to handle loading additional rows when the current row count is less than or equal to the specified page size.

Changes

File(s) Change Summary
app/client/src/widgets/TableWidgetV2/component/VirtualTable/InifiniteScrollBody/index.tsx Removed the totalRecordsCount variable and useMemo hook; now directly using rows.length for itemCount. Integrated the new useInfiniteScroll hook to manage pagination and load-more functionality.
app/client/src/widgets/TableWidgetV2/component/VirtualTable/InifiniteScrollBody/useInfiniteScroll.tsx Introduced a new custom hook useInfiniteScroll along with the UseInfiniteScrollProps interface; uses a useEffect to monitor row changes and triggers loadMore when the row count is less than or equal to pageSize.
app/client/cypress/e2e/Regression/ClientSide/Widgets/TableV2/InfiniteScrollVariableHeightRows_spec.ts Modified test data and assertions for dynamic row heights; adjusted ID values in testData and htmlTestData, and updated the assertion for maximum row height to reflect the new logic for height calculations.

Possibly related issues

Poem

In rows the data gracefully flows,
A hook awakens when the threshold shows,
No more count, just length in view,
Infinite scrolling now feels brand new.
Code spins a tale where logic aligns—
A flutter of keys and bug fixes shines!
🌟 Happy coding!


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 2e3cafe and 8bf69c9.

📒 Files selected for processing (1)
  • app/client/src/widgets/TableWidgetV2/component/VirtualTable/InifiniteScrollBody/useInfiniteScroll.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/client/src/widgets/TableWidgetV2/component/VirtualTable/InifiniteScrollBody/useInfiniteScroll.tsx
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: perform-test / server-build / server-unit-tests
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: client-check-cyclic-deps / check-cyclic-dependencies
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-build / client-build
  • GitHub Check: client-prettier / prettier-check

🪧 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 plan to trigger planning for file edits and PR creation.
  • @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.

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.

@jacquesikot jacquesikot requested review from a team, AmanAgarwal041 and rahulbarwal April 3, 2025 05:12
@github-actions github-actions bot added the Enhancement New feature or request label Apr 3, 2025
Copy link
Contributor

@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 (4)
app/client/src/widgets/TableWidgetV2/component/VirtualTable/InifiniteScrollBody/useInfiniteScroll.tsx (4)

15-20: Consider potential edge case in loading condition.

The current implementation triggers loadMore when rows.length equals pageSize, which may cause unnecessary loading operations in some cases.

-    if (rows.length > 0 && rows.length <= pageSize) {
+    if (rows.length > 0 && rows.length < pageSize) {
      loadMore();
    }

16-16: Update comment to match code variable.

The comment refers to "cachedRows" but the variable is named "rows" in the code.

-    // If cachedRows is just a single page, call loadMore to fetch the next page
+    // If rows is just a single page, call loadMore to fetch the next page

22-23: No need for explicit return statement.

The function doesn't return any value, so the explicit return; statement is unnecessary.

-  return;

15-20: Add error handling for loadMore function.

Consider adding error handling to manage cases where the loadMore function might fail.

  useEffect(() => {
    // If cachedRows is just a single page, call loadMore to fetch the next page
    if (rows.length > 0 && rows.length <= pageSize) {
-      loadMore();
+      try {
+        loadMore();
+      } catch (error) {
+        console.error("Failed to load more rows:", error);
+      }
    }
  }, [rows.length, pageSize, loadMore]);
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1c17f35 and 1ab2639.

📒 Files selected for processing (2)
  • app/client/src/widgets/TableWidgetV2/component/VirtualTable/InifiniteScrollBody/index.tsx (2 hunks)
  • app/client/src/widgets/TableWidgetV2/component/VirtualTable/InifiniteScrollBody/useInfiniteScroll.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: client-check-cyclic-deps / check-cyclic-dependencies
  • GitHub Check: client-build / client-build
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-prettier / prettier-check
🔇 Additional comments (4)
app/client/src/widgets/TableWidgetV2/component/VirtualTable/InifiniteScrollBody/index.tsx (3)

1-1: Import statements look good.

The new import for useInfiniteScroll is correctly referenced from the relative path.

Also applies to: 7-7


25-29: Good extraction of infinite scroll logic.

Extracting the infinite scrolling logic into a separate hook improves code organization and separation of concerns.


37-37: Simplified itemCount usage.

Directly using rows.length for itemCount is simpler than the previous approach using totalRecordsCount. This change makes the code more straightforward.

app/client/src/widgets/TableWidgetV2/component/VirtualTable/InifiniteScrollBody/useInfiniteScroll.tsx (1)

4-8: Interface is well-defined.

The UseInfiniteScrollProps interface properly defines the required properties with appropriate types.

@jacquesikot jacquesikot self-assigned this Apr 3, 2025
@jacquesikot jacquesikot added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Apr 3, 2025
@jacquesikot jacquesikot merged commit 4b66e0c into release Apr 3, 2025
43 checks passed
@jacquesikot jacquesikot deleted the feat/fetch-page-on-infinite-scroll branch April 3, 2025 13:58
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Apr 12, 2025
# ✨ Optimized Infinite Scrolling for TableWidgetV2  

## 📌 Problem  
The **infinite scrolling** feature in **TableWidgetV2** did not load the
correct number of pages (2) on init, and the table rows length was more
than the data fetched
 
## ✅ Solution  
This PR optimizes **infinite scrolling** by:    
- 📥 **Automatically loading the next page of data** when the initial
rows are **≤ 1 page**
- 📊 **Simplifying row count management** by using the actual **rows
length** instead of relying on `totalRecordsCount` which does not tell
actual rows loaded into the table

---  

### 🚀 How to Test  
1. Enable **Infinite Scroll** in **TableWidgetV2**.  
2. Ensure that additional pages (page 2) loads **automatically** when
the initial rows are ≤ 1 page.
3. Verify that **pagination behavior remains consistent** with expected
results.



Fixes #`Issue Number`  
_or_  
Fixes `Issue URL`
> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## Automation

/ok-to-test tags="@tag.Widget, @tag.Table, @tag.Binding, @tag.Sanity"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/14241762644>
> Commit: 8bf69c9
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=14241762644&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Widget, @tag.Table, @tag.Binding, @tag.Sanity`
> Spec:
> <hr>Thu, 03 Apr 2025 12:53:32 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Summary by CodeRabbit

- **New Features**
- Introduced a new `useInfiniteScroll` hook to enhance infinite
scrolling functionality in the table widget.
  
- **Refactor**
- Simplified pagination logic by directly utilizing the length of the
rows array, improving performance and clarity.
  
- **Bug Fixes**
- Adjusted test data and assertions in the Cypress test suite to better
reflect the expected behavior of the table widget under varying content
conditions.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Rahul Barwal <rahul.barwal@appsmith.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement New feature or request ok-to-test Required label for CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants