Skip to content

feat: Enhance infinite scrolling to use action button for load more data#39792

Merged
jacquesikot merged 13 commits intoreleasefrom
feat/infinite-scroll-load-more-button
Mar 24, 2025
Merged

feat: Enhance infinite scrolling to use action button for load more data#39792
jacquesikot merged 13 commits intoreleasefrom
feat/infinite-scroll-load-more-button

Conversation

@jacquesikot
Copy link
Contributor

@jacquesikot jacquesikot commented Mar 19, 2025

Summary

This PR replaces the automatic infinite scrolling behavior in TableWidgetV2 with an explicit "Load More" button. This change improves user experience by:

  • Giving users more control over when additional data is loaded
  • Making the loading process more intentional

Changes

Removed Dependencies

  • Removed react-window-infinite-loader dependency as it's no longer needed with the new approach

Key Implementation Details

  • Added a "Load More" button that appears at the bottom of the table when more data is available
  • Simplified virtualization logic by removing automatic loading triggers
  • Improved the initial load experience by pre-loading two pages of data when possible
  • Made the loading state more explicit and user-controlled

Technical Implementation

  • Modified VirtualList.tsx to include a "Load More" button row when more data is available
  • Refactored useInfiniteVirtualization hook to track data availability without automatic loading
  • Updated InfiniteScrollBody component to pass the necessary props for the load more functionality
  • Maintained virtualization for performance while changing only the loading trigger mechanism

Fixes #39084

Automation

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

🔍 Cypress test results

Tip

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


Thu, 20 Mar 2025 15:41:02 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 dynamic “Load More” option within data views, allowing users to load additional results seamlessly.
    • Added a new LoadMoreButton component for enhanced user interaction when loading more records.
    • Added a constant for the "Load More" label to enhance user interface consistency.
  • Refactor

    • Streamlined infinite scrolling functionality for smoother data navigation and improved responsiveness during data loading.
    • Simplified data handling logic in the infinite scrolling component for enhanced performance.
    • Enhanced the row rendering logic to improve user experience with data loading.
    • Removed unnecessary imports and interfaces to clean up the codebase.
    • Adjusted component parameters for better integration of loading state and pagination.
  • Tests

    • Added a new test suite for validating the functionality of the updated virtual list component.
    • Removed outdated test cases to streamline testing efforts.

@jacquesikot jacquesikot requested a review from a team as a code owner March 19, 2025 01:14
@jacquesikot jacquesikot requested review from rahulbarwal and removed request for a team March 19, 2025 01:14
@jacquesikot jacquesikot marked this pull request as draft March 19, 2025 01:14
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 19, 2025

Walkthrough

This pull request refactors the virtual list rendering in Table Widget V2. In the VirtualList.tsx file, several import statements and the BaseVirtualListProps interface are removed. The infinite scrolling functionality in the InfiniteScrollBody component is streamlined by integrating its behavior directly into the VariableInfiniteVirtualList. The useInfiniteVirtualization hook is simplified by eliminating redundant properties and methods, introducing a hasMoreData flag. A new LoadMoreButton component is added to facilitate loading additional records.

Changes

File(s) Change Summary
app/client/.../TableBodyCoreComponents/VirtualList.tsx Removed several import statements and the BaseVirtualListProps interface; updated method signatures for VariableInfiniteVirtualList and FixedVirtualList.
app/client/.../VirtualTable/InifiniteScrollBody/index.tsx Refactored InfiniteScrollBodyComponent by removing InfiniteLoader and integrating its functionality into VariableInfiniteVirtualList; simplified props and removed onItemsRendered callback.
app/client/.../VirtualTable/InifiniteScrollBody/useInfiniteVirtualization.tsx Removed isLoading and isItemLoaded; simplified return type and logic to use a hasMoreData flag for data loading.
app/client/.../VirtualTable/InifiniteScrollBody/useInfiniteVirtualization.test.tsx Removed several test cases, renumbered remaining tests; focused on verifying core functionality related to loading data.
app/client/.../TableBodyCoreComponents/VirtualList.test.tsx Introduced new test suite for VariableInfiniteVirtualList; included tests for rendering rows, handling "Load More" button, and validating component behavior.
app/client/.../constants/messages.ts Added new constant TABLE_LOAD_MORE for user-friendly loading prompts.
app/client/.../LoadMoreButton.tsx Introduced new LoadMoreButton component with props for loading more data and custom styling.
app/client/.../VirtualTable/BaseVirtualList.tsx Added loadMore and hasMoreData properties to ExtendedListChildComponentProps and BaseVirtualListProps; updated MemoizedRow to render LoadMoreButton.

Possibly related issues

  • [Feature] Infinite scrolling on table #2896: The removal of the BaseVirtualListProps interface and modifications to the VariableInfiniteVirtualList are related to the implementation of infinite scrolling as described in this issue, as both involve handling data loading and pagination logic in table components.

Possibly related PRs

Suggested labels

Widgets Product, Task, Table Widget V2, Widgets & Accelerators Pod, Query & Widgets Pod

Suggested reviewers

  • AmanAgarwal041
  • rahulbarwal

Poem

In rows that scroll and data flow,
A "Load More" button starts the show.
Memoized rows with eager grace,
Pull in data at a faster pace.
Code refined with seamless art, 🚀
A smoother list now plays its part!
Cheers to progress, swift and smart!


📜 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 2106627 and 0c21654.

📒 Files selected for processing (2)
  • app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/VirtualList.test.tsx (1 hunks)
  • app/client/src/widgets/TableWidgetV2/component/VirtualTable/BaseVirtualList.tsx (6 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/VirtualList.test.tsx (1)
app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/VirtualList.tsx (1) (1)
  • VariableInfiniteVirtualList (9-13)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: perform-test / server-build / server-unit-tests
  • GitHub Check: perform-test / client-build / client-build
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-prettier / prettier-check
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-check-cyclic-deps / check-cyclic-dependencies
  • GitHub Check: client-build / client-build
🔇 Additional comments (19)
app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/VirtualList.test.tsx (10)

1-5: Well-structured imports for testing

The import statements are properly organized, including React, testing utilities, and the component under test. The explicit import of @testing-library/jest-dom ensures DOM-specific matchers are available.


7-66: Good implementation of react-window mocking

The mock implementation of VariableSizeList is thorough and handles the necessary props for testing virtualization without requiring actual DOM measurement. The mock renders all items directly and simulates the onItemsRendered callback appropriately.


68-72: Effective Row component mock

The Row component mock is minimal yet sufficient, rendering a simple div with the necessary test attributes.


74-103: Well-structured test setup with comprehensive mock data

The test suite has a clear structure and includes a helper function that generates complete mock row objects with all required properties.


105-115: Proper table sizing configuration

The mock table sizes object includes all necessary dimension properties for the virtualized list to render correctly.


117-132: Basic row rendering test is comprehensive

Test 1 verifies the fundamental functionality of row rendering, confirming that the correct number of rows are displayed.


134-157: Thorough "Load More" button presence test

Test 2 correctly verifies that the "Load More" button appears when the hasMoreData prop is true, checking both the button's presence and its text content.


159-180: Good negative case testing for button visibility

Test 3 properly verifies the absence of the "Load More" button when hasMoreData is false, using queryByRole instead of getByRole which would throw an error for missing elements.


182-206: Effective interaction testing for "Load More" button

Test 4 verifies that clicking the "Load More" button calls the provided loadMore function, ensuring the button's functionality works as expected.


208-231: Well-rounded integration test for combined functionality

Test 5 confirms that both rows and the "Load More" button can render together correctly, ensuring the components integrate properly.

app/client/src/widgets/TableWidgetV2/component/VirtualTable/BaseVirtualList.tsx (9)

14-14: Correct import for the new LoadMoreButton component

The LoadMoreButton component is properly imported.


20-22: Good extension of the props interface

The ExtendedListChildComponentProps interface is appropriately extended with optional properties for load more functionality.


25-36: Clear component export and prop destructuring

The MemoizedRow component is now exported, which is good for testing and reuse. The props destructuring is well-organized and includes all necessary properties.


53-55: Effective conditional rendering for Load More button

The condition for rendering the LoadMoreButton is clear and correctly placed after all data rows. This ensures the button appears at the bottom of the list when more data is available.


84-86: Consistent props interface extension

The BaseVirtualListProps interface is extended with the same optional properties, maintaining API consistency.


88-89: Good use of a constant for the button row

Using a named constant for the Load More button row makes the code more maintainable and the intent clearer.


90-101: Properly updated component parameter destructuring

The BaseVirtualList function parameters correctly include the new props for load more functionality.


139-150: Correct props forwarding in the memoized renderer

The rowRenderer function properly forwards the hasMoreData and loadMore props to the MemoizedRow component.


152-172: Well-implemented itemCount adjustment

The itemCount calculation correctly accounts for the additional Load More button row when hasMoreData is true, ensuring proper virtualization.


🪧 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.

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 changed the title refactor: Enhance infinite scrolling in TableWidgetV2 to use action button feat: Enhance infinite scrolling in TableWidgetV2 to use action button for load more data Mar 19, 2025
@github-actions github-actions bot added the Enhancement New feature or request label Mar 19, 2025
@jacquesikot jacquesikot changed the title feat: Enhance infinite scrolling in TableWidgetV2 to use action button for load more data feat: Enhance infinite scrolling to use action button for load more data Mar 19, 2025
@jacquesikot jacquesikot marked this pull request as ready for review March 19, 2025 01:26
@jacquesikot jacquesikot added the ok-to-test Required label for CI label Mar 19, 2025
@jacquesikot jacquesikot self-assigned this Mar 19, 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 (3)
app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/VirtualList.tsx (2)

39-51: Consider extracting inline styles for better maintainability

The inline styles for the "Load More" button could be extracted to a constant or styled component for better readability and maintenance.

+const loadMoreButtonStyle = {
+  display: "flex",
+  justifyContent: "flex-start",
+  alignItems: "center",
+  paddingLeft: "10px",
+  cursor: "pointer",
+  zIndex: 1000,
+};

// Then in the component:
-          style={{
-            ...style,
-            display: "flex",
-            justifyContent: "flex-start",
-            alignItems: "center",
-            paddingLeft: "10px",
-            cursor: "pointer",
-            zIndex: 1000,
-          }}
+          style={{
+            ...style,
+            ...loadMoreButtonStyle,
+          }}

83-83: Fix typo in constant name

There's a typo in the constant name - "BUTON" should be "BUTTON".

-const LOAD_MORE_BUTON_ROW = 1;
+const LOAD_MORE_BUTTON_ROW = 1;

Don't forget to update the reference on line 120 as well.

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

70-77: Remove unused dependency in useMemo

The totalRecordsCount dependency is included in the useMemo dependency array, but it's no longer used in the calculation.

-  }, [totalRecordsCount, cachedRows.length]);
+  }, [cachedRows.length]);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 919b290 and 8d2ffda.

📒 Files selected for processing (3)
  • app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/VirtualList.tsx (2 hunks)
  • app/client/src/widgets/TableWidgetV2/component/VirtualTable/InifiniteScrollBody/index.tsx (2 hunks)
  • app/client/src/widgets/TableWidgetV2/component/VirtualTable/InifiniteScrollBody/useInfiniteVirtualization.tsx (4 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
app/client/src/widgets/TableWidgetV2/component/VirtualTable/InifiniteScrollBody/index.tsx (2)
app/client/src/widgets/TableWidgetV2/component/VirtualTable/InifiniteScrollBody/useInfiniteVirtualization.tsx (1) (1)
  • useInfiniteVirtualization (20-84)
app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/VirtualList.tsx (1) (1)
  • FixedInfiniteVirtualList (136-140)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: perform-test / client-build / client-build
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: perform-test / server-build / server-unit-tests
🔇 Additional comments (7)
app/client/src/widgets/TableWidgetV2/component/VirtualTable/InifiniteScrollBody/index.tsx (2)

24-29: Improved hook integration for infinite scrolling

The refactoring to use hasMoreData simplifies the component by removing the need for separate isItemLoaded and loadMoreItems functions. This approach aligns well with the new action button loading strategy.


33-43: Clean prop structure for FixedInfiniteVirtualList

The component now receives the necessary props directly (hasMoreData and loadMore), eliminating the need for the InfiniteLoader component. This reduces complexity and improves code readability.

app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/VirtualList.tsx (3)

13-67: Well-structured MemoizedRow component with clear conditional rendering

The new component handles three distinct scenarios appropriately:

  1. Rendering data rows when index is within bounds
  2. Rendering the "Load More" button when at the boundary with more data available
  3. Rendering empty rows otherwise

The custom equality comparison function helps prevent unnecessary re-renders.


97-109: Good use of memoization for performance optimization

The memoization of both rowsWithLoadMore and rowRenderer is excellent for preventing unnecessary re-renders, especially in a virtualized list where performance is critical.


120-120: Correct adjustment for itemCount with Load More button

The itemCount calculation correctly accounts for the additional "Load More" button row when more data is available.

app/client/src/widgets/TableWidgetV2/component/VirtualTable/InifiniteScrollBody/useInfiniteVirtualization.tsx (2)

10-14: Simplified hook return interface

The change to include hasMoreData instead of isItemLoaded and loadMoreItems streamlines the interface and aligns with the new loading approach.


47-50: Efficient initial loading strategy

The initial load logic is simplified while maintaining good UX by pre-loading enough data (2 pages worth) to ensure smooth scrolling before requiring user interaction.

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 (3)
app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/VirtualList.tsx (3)

83-83: Fix typo in constant name

There's a typo in the constant name: "BUTON" should be "BUTTON".

-const LOAD_MORE_BUTON_ROW = 1;
+const LOAD_MORE_BUTTON_ROW = 1;

Remember to update all references to this constant as well.


97-99: Avoid mutating the rows array

Using Object.assign(rows, { loadMore, hasMoreData }) mutates the original rows array. While this works, it's better to avoid mutations in React.

-  const rowsWithLoadMore = React.useMemo(() => {
-    return Object.assign(rows, { loadMore, hasMoreData });
-  }, [rows, loadMore, hasMoreData]);
+  const rowsWithLoadMore = React.useMemo(() => {
+    return { ...rows, loadMore, hasMoreData };
+  }, [rows, loadMore, hasMoreData]);

120-120: Update the constant reference after fixing the typo

Once you fix the typo in the constant name, update this reference too.

-  itemCount={hasMoreData ? itemCount + LOAD_MORE_BUTON_ROW : itemCount}
+  itemCount={hasMoreData ? itemCount + LOAD_MORE_BUTTON_ROW : itemCount}
📜 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 8d2ffda and fb1e9df.

📒 Files selected for processing (1)
  • app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/VirtualList.tsx (3 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/VirtualList.tsx (2)
app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/Row.tsx (1) (1)
  • Row (16-101)
app/client/src/widgets/TableWidgetV2/component/cellComponents/EmptyCell.tsx (1) (1)
  • EmptyRows (28-193)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: perform-test / client-build / client-build
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: perform-test / server-build / server-unit-tests
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-check-cyclic-deps / check-cyclic-dependencies
  • GitHub Check: client-build / client-build
  • GitHub Check: client-prettier / prettier-check
  • GitHub Check: client-lint / client-lint
🔇 Additional comments (1)
app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/VirtualList.tsx (1)

13-67: Implementation of Load More button looks good 👍

The MemoizedRow component intelligently handles three different rendering scenarios:

  1. Regular row display when the index is within data range
  2. "Load More" button when we're at the end and more data exists
  3. Empty row when neither condition is met

The custom memo comparison function correctly optimizes re-renders by checking for changes in the loadMore and hasMoreData props first.

@jacquesikot jacquesikot added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Mar 19, 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: 1

🧹 Nitpick comments (6)
app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/VirtualList.test.tsx (2)

137-139: Consider extracting string literals as constants.

The "Load more records" aria-label is repeated across multiple test cases. Consider extracting it to a constant for better maintainability.

+const LOAD_MORE_BUTTON_LABEL = "Load more records";
 const loadMoreButton = screen.getByRole("button", {
-  name: "Load more records",
+  name: LOAD_MORE_BUTTON_LABEL,
 });

58-88: Consider simplifying the mock row creation with a default object.

The createMockRows function contains a lot of mocked properties with Jest functions. You could simplify it by creating a default mock object and spreading it.

const createMockRows = (count: number): ReactTableRowType<Record<string, unknown>>[] => {
+  const defaultRow = {
+    getRowProps: jest.fn(),
+    toggleRowExpanded: jest.fn(),
+    toggleRowSelected: jest.fn(),
+    getToggleRowExpandedProps: jest.fn(),
+    getToggleRowSelectedProps: jest.fn(),
+    setState: jest.fn(),
+    isExpanded: false,
+    canExpand: false,
+    depth: 0,
+    state: {},
+    isSelected: false,
+    isSomeSelected: false,
+    isGrouped: false,
+    groupByID: "",
+    groupByVal: "",
+    subRows: [],
+    leafRows: [],
+    allCells: [],
+    cells: [],
+    values: {},
+  };
+
  return Array.from({ length: count }, (_, i) => ({
+    ...defaultRow,
    id: `${i + 1}`,
    original: { id: i + 1, name: `Test ${i + 1}` },
    index: i,
-    cells: [],
-    values: {},
-    getRowProps: jest.fn(),
-    allCells: [],
-    subRows: [],
-    isExpanded: false,
-    canExpand: false,
-    depth: 0,
-    toggleRowExpanded: jest.fn(),
-    state: {},
-    toggleRowSelected: jest.fn(),
-    getToggleRowExpandedProps: jest.fn(),
-    isSelected: false,
-    isSomeSelected: false,
-    isGrouped: false,
-    groupByID: "",
-    groupByVal: "",
-    leafRows: [],
-    getToggleRowSelectedProps: jest.fn(),
-    setState: jest.fn(),
  }));
};
app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/VirtualList.tsx (4)

41-58: Consider using a Button component instead of a div for better accessibility.

While the current implementation has proper role and tabIndex attributes, using a proper Button component would be more semantic and provide better accessibility defaults.

-<div
-  aria-label="Load more records"
-  className="flex items-center justify-start cursor-pointer z-[1000]"
-  onClick={loadMore}
-  role="button"
-  style={{ ...style }}
-  tabIndex={0}
->
+<button
+  aria-label="Load more records"
+  className="flex items-center justify-start cursor-pointer z-[1000] border-0 bg-transparent"
+  onClick={loadMore}
+  style={{ ...style }}
+>
  <Text
    className="underline pl-[10px]"
    style={{
      fontWeight: "var(--ads-v2-font-weight-normal)",
      fontSize: TEXT_SIZES.PARAGRAPH,
      color: Colors.GRAY,
    }}
  >
    Load More
  </Text>
-</div>
+</button>

90-90: Fix typo in constant name.

The constant name has a typo: "BUTON" should be "BUTTON".

-const LOAD_MORE_BUTON_ROW = 1;
+const LOAD_MORE_BUTTON_ROW = 1;

127-127: Update reference to the fixed constant name.

Update to use the corrected constant name.

-itemCount={hasMoreData ? itemCount + LOAD_MORE_BUTON_ROW : itemCount}
+itemCount={hasMoreData ? itemCount + LOAD_MORE_BUTTON_ROW : itemCount}

15-25: Consider creating a named type for the component props.

The component props type is complex and could be reused elsewhere. Consider extracting it to a named type.

+type MemoizedRowProps = ListChildComponentProps & {
+  loadMore?: () => void;
+  hasMoreData?: boolean;
+};

export const MemoizedRow = React.memo(
  function RowComponent({
    data,
    hasMoreData,
    index,
    loadMore,
    style,
-  }: ListChildComponentProps & {
-    loadMore?: () => void;
-    hasMoreData?: boolean;
-  }) {
+  }: MemoizedRowProps) {
📜 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 3d310ff and be02036.

📒 Files selected for processing (3)
  • app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/VirtualList.test.tsx (1 hunks)
  • app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/VirtualList.tsx (3 hunks)
  • app/client/src/widgets/TableWidgetV2/component/VirtualTable/InifiniteScrollBody/useInfiniteVirtualization.test.tsx (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/client/src/widgets/TableWidgetV2/component/VirtualTable/InifiniteScrollBody/useInfiniteVirtualization.test.tsx
🧰 Additional context used
🧬 Code Definitions (2)
app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/VirtualList.test.tsx (1)
app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/VirtualList.tsx (1) (1)
  • FixedInfiniteVirtualList (143-147)
app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/VirtualList.tsx (2)
app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/Row.tsx (1) (1)
  • Row (16-101)
app/client/src/widgets/TableWidgetV2/component/cellComponents/EmptyCell.tsx (1) (1)
  • EmptyRows (28-193)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: perform-test / client-build / client-build
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: perform-test / server-build / server-unit-tests
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-check-cyclic-deps / check-cyclic-dependencies
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-build / client-build
  • GitHub Check: client-prettier / prettier-check
🔇 Additional comments (2)
app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/VirtualList.test.tsx (1)

1-193: Test suite looks good with comprehensive test cases.

The test suite covers all the main scenarios for the FixedInfiniteVirtualList component, including row rendering, "Load More" button display logic, and interaction handling.

app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/VirtualList.tsx (1)

14-74: New MemoizedRow component looks good with clear conditional rendering logic.

The component properly handles three scenarios: rendering a row, a "Load More" button, or an empty row, with appropriate conditional checks.

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

♻️ Duplicate comments (1)
app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/VirtualList.tsx (1)

86-88: ⚠️ Potential issue

Avoid mutating the rows array with Object.assign.

Using Object.assign(rows, {...}) mutates the original rows array. Create a new object instead to avoid potential side effects.

const rowsWithLoadMore = React.useMemo(() => {
-  return Object.assign(rows, { loadMore, hasMoreData });
+  return { ...rows, loadMore, hasMoreData };
}, [rows, loadMore, hasMoreData]);
🧹 Nitpick comments (1)
app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/VirtualList.tsx (1)

72-72: Fix typo in constant name.

The constant name has a spelling error.

-const LOAD_MORE_BUTON_ROW = 1;
+const LOAD_MORE_BUTTON_ROW = 1;
📜 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 be02036 and 1f8a80a.

📒 Files selected for processing (3)
  • app/client/src/ce/constants/messages.ts (1 hunks)
  • app/client/src/widgets/TableWidgetV2/component/LoadMoreButton.tsx (1 hunks)
  • app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/VirtualList.tsx (3 hunks)
🧰 Additional context used
🧬 Code Definitions (2)
app/client/src/widgets/TableWidgetV2/component/LoadMoreButton.tsx (1)
app/client/src/ce/constants/messages.ts (1) (1)
  • TABLE_LOAD_MORE (2634-2634)
app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/VirtualList.tsx (2)
app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/Row.tsx (1) (1)
  • Row (16-101)
app/client/src/widgets/TableWidgetV2/component/cellComponents/EmptyCell.tsx (1) (1)
  • EmptyRows (28-193)
🔇 Additional comments (5)
app/client/src/ce/constants/messages.ts (1)

2634-2634: Clean addition of internationalized text constant.

Adding this constant centralizes UI text and enables internationalization, following the established pattern in the file.

app/client/src/widgets/TableWidgetV2/component/LoadMoreButton.tsx (1)

1-42: Well-structured and accessible LoadMoreButton component.

The component follows best practices with proper accessibility attributes (aria-label, role, tabIndex) and uses the internationalized message constant. The styling also includes appropriate cursor and z-index properties.

app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/VirtualList.tsx (3)

17-56: Good implementation of MemoizedRow with appropriate conditional rendering.

The component cleanly handles three different rendering scenarios based on the index and hasMoreData flag. The custom equality function properly optimizes re-renders.


109-109: Good adjustment of itemCount for the Load More button.

The component correctly adjusts the itemCount to include space for the "Load More" button when hasMoreData is true, using the constant for clarity.


90-98: Effective memoization of the row renderer.

The rowRenderer is properly memoized with the correct dependency array, preventing unnecessary re-renders when only unrelated props change.

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

♻️ Duplicate comments (1)
app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/VirtualList.tsx (1)

86-88: ⚠️ Potential issue

Avoid mutating the rows array with Object.assign

Using Object.assign(rows, {...}) mutates the original rows array. Create a new object instead to avoid potential side effects.

const rowsWithLoadMore = React.useMemo(() => {
-  return Object.assign(rows, { loadMore, hasMoreData });
+  return { ...rows, loadMore, hasMoreData };
}, [rows, loadMore, hasMoreData]);
🧹 Nitpick comments (1)
app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/VirtualList.tsx (1)

72-72: Typo in constant name

There's a typo in the constant name - "BUTON" should be "BUTTON".

-const LOAD_MORE_BUTON_ROW = 1;
+const LOAD_MORE_BUTTON_ROW = 1;
📜 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 1f8a80a and 25d898d.

📒 Files selected for processing (1)
  • app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/VirtualList.tsx (2 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/VirtualList.tsx (3)
app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/Row.tsx (1) (1)
  • Row (21-131)
app/client/src/widgets/TableWidgetV2/component/cellComponents/EmptyCell.tsx (1) (1)
  • EmptyRows (28-193)
app/client/src/widgets/TableWidgetV2/component/VirtualTable/BaseVirtualList.tsx (1) (1)
  • BaseVirtualListProps (61-71)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: perform-test / client-build / client-build
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: perform-test / server-build / server-unit-tests
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-prettier / prettier-check
  • GitHub Check: client-check-cyclic-deps / check-cyclic-dependencies
  • GitHub Check: client-build / client-build
🔇 Additional comments (4)
app/client/src/widgets/TableWidgetV2/component/TableBodyCoreComponents/VirtualList.tsx (4)

16-56: Well-structured MemoizedRow component with optimized rendering

The new MemoizedRow component handles three distinct rendering scenarios: regular rows, a load more button, and empty rows. The custom equality function in the memo wrapper correctly prevents unnecessary re-renders when only data changes but not the loading state props.


68-69: Interface extension maintains backward compatibility

Good approach adding optional props to the existing interface instead of creating a new one. This maintains compatibility with existing code while supporting the new functionality.


90-98: Good use of memoization for rowRenderer

Proper use of useMemo for the rowRenderer function helps prevent unnecessary re-renders. The dependencies array correctly includes only the props that would affect rendering.


108-110: Smart conditional item count handling

The itemCount calculation correctly accounts for the additional "Load More" button row when there's more data available. This ensures the virtual list correctly sizes itself.

…alList in tests and components

This update transitions the VirtualList component to utilize VariableInfiniteVirtualList, enhancing its functionality for handling variable row heights. The changes include updates to test cases and component imports to reflect this new implementation, ensuring improved performance and user experience in infinite scrolling scenarios.
@jacquesikot jacquesikot added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Mar 20, 2025
isItemLoaded: (index: number) => boolean;
itemCount: number;
loadMoreItems: (startIndex: number, stopIndex: number) => Promise<void>;
hasMoreData: boolean;
Copy link
Contributor

@rahulbarwal rahulbarwal Mar 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are going via this route, does it even need this variable? I mean, can this not be calculated by page number?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can calculate with pageSize and rows, but putting it in the hook encapsulates that logic in a related scope. ALternatively we can remove it and have it in the InfiniteScrollBody, but we'd still have to pass it as props to BaseVirtualList. I prefer to encapsulate the logic for this inside the hook.

@github-actions github-actions bot added Query Widgets & IDE Pod All issues related to Query, JS, Eval, Widgets & IDE Table Widget V2 Issues related to Table Widget V2 Task A simple Todo Widgets & Accelerators Pod Issues related to widgets & Accelerators Widgets Product This label groups issues related to widgets labels Mar 21, 2025
@jacquesikot jacquesikot merged commit e038a5c into release Mar 24, 2025
45 checks passed
@jacquesikot jacquesikot deleted the feat/infinite-scroll-load-more-button branch March 24, 2025 04:06
@coderabbitai coderabbitai bot mentioned this pull request Apr 3, 2025
2 tasks
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Apr 12, 2025
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 Query Widgets & IDE Pod All issues related to Query, JS, Eval, Widgets & IDE Table Widget V2 Issues related to Table Widget V2 Task A simple Todo Widgets & Accelerators Pod Issues related to widgets & Accelerators Widgets Product This label groups issues related to widgets

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement(or handle) loading row for seamless data fetch experience [Stretch goal for spring Mar10-Mar21]

2 participants