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

feat: Implement Infinite Scroll while Maintaining Selection Features #39820

Open
wants to merge 1 commit into
base: release
Choose a base branch
from

Conversation

naaa760
Copy link

@naaa760 naaa760 commented Mar 20, 2025

Description:

Integration of infinite scroll with existing table selection features to maintain proper row selection and indices during scrolling.

Tip

TL;DR: Added infinite scroll support to table component while preserving row selection state and index accuracy across page loads.

image

image

Fixes #39814

This PR implements:

Persistent row selection across infinite scroll operations

Accurate row index translation between visible and absolute indices
Reliable triggered row identification
Loading state management
Error handling for data fetching

Key features:

Uses Map data structure to maintain selections by row ID
Implements debounced scroll handling
Provides loading indicators during data fetch
Maintains index consistency during pagination
Includes comprehensive test suite

Dependencies:

None (vanilla JavaScript implementation)

Communication
Should the DevRel and Marketing teams inform users about this change?
[x] Yes
[ ] No
This feature significantly improves table usability with large datasets while maintaining existing selection functionality, which would be valuable information for users.

Summary by CodeRabbit

  • New Features
    • Interactive Data Table: Experience smoother data interaction with dynamic row selection, infinite scrolling, and responsive loading indicators.
    • Google Sheets Integration: Benefit from early support for seamless OAuth2 connectivity in local setups, enhancing integration capabilities.

@naaa760 naaa760 requested a review from a team as a code owner March 20, 2025 08:51
Copy link
Contributor

coderabbitai bot commented Mar 20, 2025

Walkthrough

This pull request introduces a new TableComponent with features like row selection, infinite scrolling, and dynamic data fetching along with a corresponding test suite in TableComponentTest.js. Additionally, it adds a dedicated HTML test page, updates the GitServiceConfig to ensure "localhost" is included in allowed domains, provides new local configuration for Google Sheets OAuth2, and introduces an empty GoogleSheetsPlugin.java file.

Changes

Files Change Summary
TableComponent.js, TableComponentTest.js, index.html Added a new table component that supports infinite scrolling, row selection, and data fetching with associated tests and a test page triggering the tests on DOM load.
app/server/appsmith-git/.../GitServiceConfig.java Introduced a new allowedDomains field and an init method that appends "localhost" if missing.
app/server/appsmith-server/.../application-local.properties Created new configuration properties to support Google Sheets OAuth2 for localhost (client ID, secret, allowed domains, and redirect URI).
app/server/plugins/googlesheetsplugin/.../GoogleSheetsPlugin.java Added a new file for the Google Sheets plugin (currently without content).

Sequence Diagram(s)

Loading
sequenceDiagram
    participant User
    participant TableComponent
    participant DataService
    User->>TableComponent: Scroll near bottom
    TableComponent->>TableComponent: handleScroll (debounced)
    TableComponent->>DataService: fetchData(currentPage, pageSize)
    DataService-->>TableComponent: Return new data
    TableComponent->>TableComponent: renderRows() and update state
Loading
sequenceDiagram
    participant User
    participant TableComponent
    User->>TableComponent: Click on a row (unique ID)
    TableComponent->>TableComponent: handleRowSelection(uniqueID)
    TableComponent->>TableComponent: Update selectedRows map
    TableComponent->>TableComponent: Trigger selection change event

Assessment against linked issues

Objective Addressed Explanation
Row selection and triggered row functionality (#39814)
Index consistency for infinite scrolling (#39814)

Possibly related issues

Possibly related PRs

Suggested labels

Enhancement, Widgets Product, Task, ok-to-test, Query & Widgets Pod, Widgets & Accelerators Pod

Suggested reviewers

  • AmanAgarwal041
  • jacquesikot
  • vivek-appsmith

Poem

In a table of rows that scroll and gleam,
Code dances with data like a dream.
Rows selected with precision and care,
Infinite loading fills the air.
A shining new chapter in code we share!
🚀✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ 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.
  • @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.

@naaa760 naaa760 changed the title feat(Table): Implement Infinite Scroll while Maintaining Selection Features feat(: Implement Infinite Scroll while Maintaining Selection Features Mar 20, 2025
@naaa760 naaa760 changed the title feat(: Implement Infinite Scroll while Maintaining Selection Features feat: Implement Infinite Scroll while Maintaining Selection Features Mar 20, 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: 7

🧹 Nitpick comments (6)
index.html (2)

9-10: Optional improvement: add instructions or default text for test results.
Currently, the <div id="test-results"> is empty. Consider adding a brief message or instructions for clarity.


11-15: Consider adding a fallback or error handling mechanism in the test bootstrap.
If TableComponentTest.runTests() fails, the user might not see any clear indication. Wrapping this call in a try/catch could enhance visibility of errors.

TableComponent.js (2)

44-51: Infinite scroll threshold is hard-coded.
The current 80% threshold is reasonable. However, consider making it configurable for different use cases.


103-114: Optional: enhance fetch error handling.
Currently, the method throws an error on a bad response. Consider retry logic or more user-friendly error messages to improve resilience.

TableComponentTest.js (1)

70-88: Infinite scroll test is valid, but consider verifying appended data.
Current test checks for an increase in data length. Optionally verify the new rows for correctness.

app/server/appsmith-server/src/main/resources/application-local.properties (1)

1-5: Google Sheets OAuth configuration looks good but needs documentation

The OAuth2 configuration for Google Sheets is properly structured with environment variables for sensitive information.

Consider adding:

  1. A comment explaining how to obtain and set the client ID and secret from Google Developer Console
  2. Documentation on how to set up the OAuth consent screen
  3. Verification that the redirect URI matches your OAuth configuration in Google Cloud Console
 # Google Sheets specific configuration for localhost
 oauth2.google.sheets.client-id=${GOOGLE_SHEETS_CLIENT_ID:}
 oauth2.google.sheets.client-secret=${GOOGLE_SHEETS_CLIENT_SECRET:}
 oauth2.google.sheets.allowed-domains=localhost
 oauth2.redirect-uri=http://localhost/oauth2/callback 
+# Instructions to set up OAuth2:
+# 1. Go to https://console.cloud.google.com/
+# 2. Create a project and enable Google Sheets API
+# 3. Configure OAuth consent screen
+# 4. Create OAuth credentials and set GOOGLE_SHEETS_CLIENT_ID and GOOGLE_SHEETS_CLIENT_SECRET environment variables
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 435897e and 6b38228.

📒 Files selected for processing (6)
  • TableComponent.js (1 hunks)
  • TableComponentTest.js (1 hunks)
  • app/server/appsmith-git/src/main/java/com/appsmith/git/configurations/GitServiceConfig.java (2 hunks)
  • app/server/appsmith-server/src/main/resources/application-local.properties (1 hunks)
  • app/server/plugins/googlesheetsplugin/src/main/java/com/appsmith/external/plugins/GoogleSheetsPlugin.java (1 hunks)
  • index.html (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
TableComponentTest.js

[error] 1-103: Avoid classes that contain only static members.

Prefer using simple functions instead of classes with only static members.

(lint/complexity/noStaticOnlyClass)


[error] 4-4: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 5-5: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 6-6: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 7-7: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 8-8: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

🔇 Additional comments (12)
index.html (2)

1-7: HTML structure and script inclusion look fine.
No immediate issues found in the document setup and script references.


16-17: No issues identified; markup closure looks good.

TableComponent.js (5)

27-31: Returning the last selected row.
Implementation is concise and correctly uses Map values.


33-35: Fetching selected rows.
Returning all selected rows is straightforward and correct.


37-43: Check for null or missing row element.
Optional chaining helps, but consider early return if no rowElement or rowId is found to avoid searching visibleData unnecessarily.


95-101: Index translation implementation is straightforward.
Calculation logic for absolute and visible indices is correct.


116-122: Loading state rendering is fine.
Implementation is succinct and aligns with typical UI placeholders.

TableComponentTest.js (4)

21-36: Consider mocking or stubbing data fetch calls.
loadMoreData may attempt to fetch real endpoints. For a robust test, a mock or stub approach ensures consistent test behavior.


38-50: Multiple selection works as intended.
The logic checks out, and the test covers the basics effectively.


51-68: Triggered row identification method is tested thoroughly.
Verifies that the correct row is linked to the mock event data.


90-101: Index consistency test is correct.
Properly verifies getAbsoluteIndex and getVisibleIndex logic.

app/server/appsmith-git/src/main/java/com/appsmith/git/configurations/GitServiceConfig.java (1)

18-20: Configuration property reference looks good

The allowedDomains property is correctly defined with the appropriate Value annotation.

Comment on lines +53 to +72
async loadMoreData() {
if (this.isLoading || this.visibleData.length >= this.totalRows) {
return;
}

this.isLoading = true;

try {
const newData = await this.fetchData(this.currentPage + 1);
this.currentPage += 1;

// Append new data while maintaining selection states
this.visibleData = [...this.visibleData, ...newData];

// Update row rendering while preserving selections
this.renderRows();
} finally {
this.isLoading = false;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Concurrent or repeated scroll events.
Your isLoading flag helps prevent simultaneous fetches, but quickly repeated scroll attempts might still queue up. Consider a more robust guard or cancellation approach if the data fetch is slow.

Comment on lines +13 to +25
handleRowSelection(rowData, isSelected) {
// Use a unique identifier from your data instead of index
const rowId = rowData.id || generateUniqueId(rowData);

if (isSelected) {
this.selectedRows.set(rowId, rowData);
} else {
this.selectedRows.delete(rowId);
}

// Trigger selection change event
this.onSelectionChange(Array.from(this.selectedRows.values()));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify usage of generateUniqueId(rowData) and onSelectionChange.
Ensure these functions or handlers are defined or imported. Otherwise, referencing them will cause errors at runtime.


🏁 Script executed:

#!/bin/bash
# Description: Search the codebase for definitions of generateUniqueId and onSelectionChange
rg -A 5 $'generateUniqueId|onSelectionChange'

Length of output: 51100


Clarify and Fix Function Definitions in TableComponent.js

  • It appears that the client-side code in TableComponent.js is referencing generateUniqueId(rowData) without a clear local definition or import. The search only revealed definitions in server-side files, so please verify if a client-side implementation (or import from a utility module) should be used instead.
  • Ensure that onSelectionChange is correctly defined or passed as a prop. Given its extensive use across the codebase, double-check that its usage in TableComponent.js aligns with the intended event handling.

Comment on lines +1 to +11
class TableComponent {
constructor() {
this.selectedRows = new Map(); // Store selections by unique row ID instead of index
this.visibleData = []; // Currently visible/loaded rows
this.totalRows = 0; // Total number of rows available
this.pageSize = 50; // Number of rows to load per page
this.currentPage = 1;
this.isLoading = false;
this.handleScroll = debounce(this.handleScroll.bind(this), 150);
this.container.addEventListener("scroll", this.handleScroll);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Flag undefined property this.container.
this.container is referenced in the constructor but never declared or assigned. This might cause a runtime error.

constructor() {
  this.selectedRows = new Map();
  this.visibleData = [];
  ...
+ this.container = document.querySelector('#tableContainer'); // or accept container as a constructor parameter
  this.handleScroll = debounce(this.handleScroll.bind(this), 150);
  this.container.addEventListener("scroll", this.handleScroll);
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
class TableComponent {
constructor() {
this.selectedRows = new Map(); // Store selections by unique row ID instead of index
this.visibleData = []; // Currently visible/loaded rows
this.totalRows = 0; // Total number of rows available
this.pageSize = 50; // Number of rows to load per page
this.currentPage = 1;
this.isLoading = false;
this.handleScroll = debounce(this.handleScroll.bind(this), 150);
this.container.addEventListener("scroll", this.handleScroll);
}
class TableComponent {
constructor() {
this.selectedRows = new Map(); // Store selections by unique row ID instead of index
this.visibleData = []; // Currently visible/loaded rows
this.totalRows = 0; // Total number of rows available
this.pageSize = 50; // Number of rows to load per page
this.currentPage = 1;
this.isLoading = false;
this.container = document.querySelector('#tableContainer'); // or accept container as a constructor parameter
this.handleScroll = debounce(this.handleScroll.bind(this), 150);
this.container.addEventListener("scroll", this.handleScroll);
}
}

Comment on lines +74 to +93
renderRows() {
return this.visibleData
.map((rowData) => {
const rowId = rowData.id || generateUniqueId(rowData);
const isSelected = this.selectedRows.has(rowId);

return `
<tr
data-row-id="${rowId}"
class="${isSelected ? "selected" : ""}"
onclick="handleRowSelection(${JSON.stringify(
rowData
)}, !${isSelected})"
>
${this.renderCells(rowData)}
</tr>
`;
})
.join("");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Potential XSS risk with inline JSON.stringify usage.
If rowData includes user-supplied content, inserting it directly into HTML could be risky. Sanitize or escape special characters before stringifying.

<tr
   data-row-id="${rowId}"
-  onclick="handleRowSelection(${JSON.stringify(rowData)}, ...)
+  onclick="handleRowSelection(${escapeHTML(JSON.stringify(rowData))}, ...)
   ...
>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
renderRows() {
return this.visibleData
.map((rowData) => {
const rowId = rowData.id || generateUniqueId(rowData);
const isSelected = this.selectedRows.has(rowId);
return `
<tr
data-row-id="${rowId}"
class="${isSelected ? "selected" : ""}"
onclick="handleRowSelection(${JSON.stringify(
rowData
)}, !${isSelected})"
>
${this.renderCells(rowData)}
</tr>
`;
})
.join("");
}
renderRows() {
return this.visibleData
.map((rowData) => {
const rowId = rowData.id || generateUniqueId(rowData);
const isSelected = this.selectedRows.has(rowId);
return `
<tr
data-row-id="${rowId}"
class="${isSelected ? "selected" : ""}"
onclick="handleRowSelection(${escapeHTML(JSON.stringify(rowData))}, !${isSelected})"
>
${this.renderCells(rowData)}
</tr>
`;
})
.join("");
}

Comment on lines +1 to +19
class TableComponentTest {
static async runTests() {
const tests = [
this.testSelectionPersistence,
this.testMultipleSelections,
this.testTriggeredRow,
this.testInfiniteScroll,
this.testIndexConsistency,
];

for (const test of tests) {
try {
await test();
console.log(`✅ ${test.name} passed`);
} catch (error) {
console.error(`❌ ${test.name} failed:`, error);
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Replace static-only class with plain functions or refer to the class explicitly.
Having only static methods can increase complexity. Additionally, referencing this in a static context can be confusing. Use the class name directly or switch to standalone functions.

static async runTests() {
-  const tests = [
-    this.testSelectionPersistence,
-    this.testMultipleSelections,
-    ...
-  ];
+  const tests = [
+    TableComponentTest.testSelectionPersistence,
+    TableComponentTest.testMultipleSelections,
+    ...
+  ];

  for (const test of tests) {
    ...
  }
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
class TableComponentTest {
static async runTests() {
const tests = [
this.testSelectionPersistence,
this.testMultipleSelections,
this.testTriggeredRow,
this.testInfiniteScroll,
this.testIndexConsistency,
];
for (const test of tests) {
try {
await test();
console.log(`✅ ${test.name} passed`);
} catch (error) {
console.error(`❌ ${test.name} failed:`, error);
}
}
}
class TableComponentTest {
static async runTests() {
const tests = [
TableComponentTest.testSelectionPersistence,
TableComponentTest.testMultipleSelections,
TableComponentTest.testTriggeredRow,
TableComponentTest.testInfiniteScroll,
TableComponentTest.testIndexConsistency,
];
for (const test of tests) {
try {
await test();
console.log(`✅ ${test.name} passed`);
} catch (error) {
console.error(`❌ ${test.name} failed:`, error);
}
}
}
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 1-103: Avoid classes that contain only static members.

Prefer using simple functions instead of classes with only static members.

(lint/complexity/noStaticOnlyClass)


[error] 4-4: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 5-5: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 6-6: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 7-7: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 8-8: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

@@ -0,0 +1 @@

Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Empty file - implementation missing

This file is empty and does not contain any implementation. For a plugin to function properly, it should contain a Java class that implements the necessary interfaces for the Google Sheets integration.

At minimum, the file should include:

package com.appsmith.external.plugins;

import org.springframework.stereotype.Component;
import com.appsmith.external.models.*;
import reactor.core.publisher.Mono;

@Component
public class GoogleSheetsPlugin extends BasePlugin {
    // Implement the required methods for the plugin
}

Comment on lines +21 to +27
@PostConstruct
public void init() {
// Add localhost to allowed domains if not present
if (!allowedDomains.contains("localhost")) {
allowedDomains = allowedDomains + ",localhost";
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add null check for allowedDomains property

The current implementation doesn't handle the case where allowedDomains could be null or empty. This could lead to a NullPointerException.

@PostConstruct
public void init() {
    // Add localhost to allowed domains if not present
-    if (!allowedDomains.contains("localhost")) {
+    if (allowedDomains == null || allowedDomains.isEmpty()) {
+        allowedDomains = "localhost";
+    } else if (!allowedDomains.contains("localhost")) {
        allowedDomains = allowedDomains + ",localhost";
    }
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@PostConstruct
public void init() {
// Add localhost to allowed domains if not present
if (!allowedDomains.contains("localhost")) {
allowedDomains = allowedDomains + ",localhost";
}
}
@PostConstruct
public void init() {
// Add localhost to allowed domains if not present
if (allowedDomains == null || allowedDomains.isEmpty()) {
allowedDomains = "localhost";
} else if (!allowedDomains.contains("localhost")) {
allowedDomains = allowedDomains + ",localhost";
}
}

Copy link

This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.

@github-actions github-actions bot added the Stale label Mar 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task]: Integration of infinite scroll with existing features such as get selected row, get triggered row.
1 participant