PromucFlow_constructor/app/client/cypress/support/Pages
Jacques Ikot 5a6479c5dd
feat: reset table when infinite scroll is turned on (#40066)
## 🐞 Problem

We've identified several issues with the TableWidgetV2's infinite scroll
functionality:

- **Stale Data After Toggle**  
When users enable infinite scroll for the first time, the table's state
and cached data aren't properly reset, potentially leading to incorrect
data display and inconsistent behavior.

- **Height Changes Breaking Existing Data**  
When a table's height is increased while infinite scroll is enabled, the
existing cached data becomes invalid due to changing offsets, but the
table wasn't resetting its state accordingly.

- **Empty Initial View**  
When loading a table with infinite scroll enabled, rows were not visible
during the initial load until data was fetched, creating a jarring user
experience.

- **Disabled Properties Still Rendering Controls**  
Property controls that should be disabled (based on section disabling
conditions) were still being rendered and active, causing unexpected
behavior.

---

##  Solution

### 1. Implement Table Reset on Infinite Scroll Toggle

Added a new method `resetTableForInfiniteScroll()` that properly resets
the table's state when infinite scroll is enabled. This method:

- Clears cached table data  
- Resets the "end of data" flag  
- Resets all meta properties to their default values  
- Sets the page number back to `1` and triggers a page load

```ts
resetTableForInfiniteScroll = () => {
  const { infiniteScrollEnabled, pushBatchMetaUpdates } = this.props;

  if (infiniteScrollEnabled) {
    // reset the cachedRows
    pushBatchMetaUpdates("cachedTableData", {});
    pushBatchMetaUpdates("endOfData", false);

    // reset the meta properties
    const metaProperties = Object.keys(TableWidgetV2.getMetaPropertiesMap());
    metaProperties.forEach((prop) => {
      if (prop !== "pageNo") {
        const defaultValue = TableWidgetV2.getMetaPropertiesMap()[prop];
        this.props.updateWidgetMetaProperty(prop, defaultValue);
      }
    });

    // reset and reload page
    this.updatePageNumber(1, EventType.ON_NEXT_PAGE);
  }
};
```

---

### 2. Reset on Height Changes

Added a check in `componentDidUpdate` to detect height changes and reset
the table when needed:

```ts
// Reset widget state when height changes while infinite scroll is enabled
if (
  infiniteScrollEnabled &&
  prevProps.componentHeight !== componentHeight
) {
  this.resetTableForInfiniteScroll();
}
```

---

### 3. Improved Empty State Rendering

Modified the `InfiniteScrollBodyComponent` to show placeholder rows
during initial load by using the maximum of `rows.length` and
`pageSize`:

```ts
const itemCount = useMemo(
  () => Math.max(rows.length, pageSize),
  [rows.length, pageSize],
);
```

This ensures the table maintains its expected height and appearance even
before data is loaded.

---

### 4. Fixed Property Control Rendering

Fixed the `PropertyControl` component to respect the `isControlDisabled`
flag by conditionally rendering the control:

```ts
{!isControlDisabled &&
  PropertyControlFactory.createControl(
    config,
    {
      onPropertyChange: onPropertyChange,
      // ...other props
    },
    // ...other args
  )}
```

This prevents disabled controls from being rendered and potentially
causing issues.

---

These improvements significantly enhance the stability and user
experience of **TableWidgetV2**'s infinite scroll functionality.


Fixes #39377 

## Automation

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

### 🔍 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/14373134089>
> Commit: 2b0715bbbe2e9a254cd287f831329be529a17c3c
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=14373134089&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Table, @tag.Widget, @tag.Binding, @tag.Sanity,
@tag.PropertyPane`
> Spec:
> <hr>Thu, 10 Apr 2025 07:15:53 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

- **New Features**
- Property panels now display controls only when enabled, enhancing
clarity.
- Table widgets offer smoother infinite scrolling with automatic resets
on state or size changes.
- Columns dynamically adjust for optimal display when infinite scrolling
is active.
- **Bug Fixes**
- Improved handling of item counts and loading states in infinite
scrolling.
- **Refactor**
- Improved performance through optimized item computations and
streamlined scrolling logic.
	- Removed redundant loading button logic for a cleaner user experience.
- **Tests**
- Expanded test scenarios to verify improved content wrapping and rich
HTML rendering in table cells, with a focus on internal logic and
behavior.
- Enhanced clarity and robustness of infinite scroll tests by verifying
loading through scrolling actions.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Rahul Barwal <rahul.barwal@appsmith.com>
2025-04-10 03:58:15 -07:00
..
Anvil chore: export anvil locators (#39624) 2025-03-07 18:11:11 +05:30
AppSettings test: regression tests for import flow (#38457) 2025-01-12 14:28:05 +05:30
IDE chore: Removing the feature flag for using Entity Item component from ADS templates (#39093) 2025-03-14 17:40:02 +05:30
AdminSettings.ts feat: Updating admin settings page as per new designs (#40101) 2025-04-07 15:44:20 +05:30
AggregateHelper.ts chore: Removing the feature flag for using Entity Item component from ADS templates (#39093) 2025-03-14 17:40:02 +05:30
ApiPage.ts chore: entity tabs replacement (#38989) 2025-02-06 11:33:54 +03:00
AssertHelper.ts test: Cypress | Downgrade Cypress to 13.5.1 (#31011) 2024-02-09 13:33:30 +05:30
AutoLayout.ts fix: missing methods in gitexecutorceimpl (#32614) 2024-04-12 06:21:01 +05:30
Canvas.ts chore: cypress test for canvas view mode (#32354) 2024-04-03 14:52:09 +05:30
CommunityTemplates.ts fix: default port numbers for the datasources (#32901) 2024-04-30 13:15:11 +05:30
DataSources.ts test: Add cypress tests for Hubspot Datasource functionalities (#39419) 2025-02-25 17:34:11 +05:30
DebuggerHelper.ts chore: Debugger Quick wins (#37954) 2024-12-10 14:43:40 +00:00
DeployModeHelper.ts fix: Fix for the embedded case (#38101) 2024-12-13 15:04:00 +05:30
EditorNavigation.ts chore: Removing the feature flag for using Entity Item component from ADS templates (#39093) 2025-03-14 17:40:02 +05:30
EntityExplorer.ts chore: Removing the feature flag for using Entity Item component from ADS templates (#39093) 2025-03-14 17:40:02 +05:30
FakerHelper.ts
GitSync.ts chore: update select component (#38954) 2025-02-06 13:10:25 +05:30
GSheetHelper.ts feat: Enable new toolbar for cypress (#37148) 2024-12-03 09:21:43 +05:30
HomePage.ts fix: Use Spring's native CSRF protection, and fix login page (#37292) 2025-03-08 21:01:02 +05:30
InviteModal.ts
JSEditor.ts chore: Removing the feature flag for using Entity Item component from ADS templates (#39093) 2025-03-14 17:40:02 +05:30
LibraryInstaller.ts
MultipleEnvironments.ts
Onboarding.ts chore: removed onboarding flags ab_create_new_apps_enabled , ab_start_with_data_default_enabled (#31384) 2024-03-15 11:13:14 +05:30
PageList.ts chore: Removing the feature flag for using Entity Item component from ADS templates (#39093) 2025-03-14 17:40:02 +05:30
PartialImportExport.ts test: adding test for page functionality (#38538) 2025-01-18 20:26:42 +05:30
PeekOverlay.ts feat: Inspect State CTA for discovery (#39100) 2025-02-14 21:57:08 +05:30
PluginActionForm.ts feat: Enable new toolbar for cypress (#37148) 2024-12-03 09:21:43 +05:30
PropertyPane.ts test: new test cases framework functions and Action selector (#37566) 2024-12-16 16:41:54 +05:30
Table.ts feat: reset table when infinite scroll is turned on (#40066) 2025-04-10 03:58:15 -07:00
Tabs.ts
Templates.ts chore: Add spec for create new app from template (#31311) 2024-02-28 14:42:35 +05:30
WDSWidgets.ts fix: Anvil toggleable widgets not working when native callbacks are used for AnvilFlexComponent (#31125) 2024-02-15 11:00:57 +05:30