From eb899929bff342c765480ba2d7b5795a5f808713 Mon Sep 17 00:00:00 2001 From: Rahul Barwal Date: Wed, 30 Apr 2025 15:04:03 +0530 Subject: [PATCH] fix: simplify table reset logic in TableWidgetV2 (#40486) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description Problem The table state wasn't being reset automatically, causing issues with individual page numbers and data properties. Root cause Using manual page number handling led to unexpected outcomes due to not having an automatic reset mechanism for the table state when infinite scroll was enabled or disabled. Solution To mitigate this issue, we have utilized in-built evaluations and the reset widget method to properly reset the widget. Fixes: #40452 ## Automation /ok-to-test tags="@tag.Widget" ### :mag: Cypress test results > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: > Commit: 32f17cca1ab2c8c735fd9a10d359ae5a95e9f6c9 > Cypress dashboard. > Tags: `@tag.Widget` > Spec: >
Wed, 30 Apr 2025 07:28:01 UTC ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [ ] No ## Summary by CodeRabbit - **Refactor** - Simplified the table reset process for infinite scroll by streamlining internal logic, resulting in a more efficient reset experience for users. No visible changes to the interface or features. --- .../widgets/TableWidgetV2/widget/index.tsx | 42 +------------------ 1 file changed, 2 insertions(+), 40 deletions(-) diff --git a/app/client/src/widgets/TableWidgetV2/widget/index.tsx b/app/client/src/widgets/TableWidgetV2/widget/index.tsx index 4d8847c12e..6b3c490122 100644 --- a/app/client/src/widgets/TableWidgetV2/widget/index.tsx +++ b/app/client/src/widgets/TableWidgetV2/widget/index.tsx @@ -140,6 +140,7 @@ import { isColumnTypeEditable, updateAndSyncTableLocalColumnOrders, } from "./utilities"; +import resetWidget from "workers/Evaluation/fns/resetWidget"; const ReactTableComponent = lazy(async () => retryPromise(async () => import("../component")), @@ -3064,46 +3065,7 @@ class TableWidgetV2 extends BaseWidget { } resetTableForInfiniteScroll = () => { - const { - infiniteScrollEnabled, - pushBatchMetaUpdates, - updateWidgetMetaProperty, - } = this.props; - - if (infiniteScrollEnabled) { - // reset the cachedRows - const isAlreadyOnFirstPage = this.props.pageNo === 1; - const data = isAlreadyOnFirstPage ? { 1: this.props.tableData } : {}; - - pushBatchMetaUpdates("cachedTableData", data); - pushBatchMetaUpdates("endOfData", false); - - // Explicitly reset specific meta properties - updateWidgetMetaProperty("selectedRowIndex", undefined); - updateWidgetMetaProperty("selectedRowIndices", undefined); - updateWidgetMetaProperty("searchText", undefined); - updateWidgetMetaProperty("triggeredRowIndex", undefined); - updateWidgetMetaProperty("filters", []); - updateWidgetMetaProperty("sortOrder", { - column: "", - order: null, - }); - updateWidgetMetaProperty("transientTableData", {}); - updateWidgetMetaProperty("updatedRowIndex", -1); - updateWidgetMetaProperty("editableCell", defaultEditableCell); - updateWidgetMetaProperty("columnEditableCellValue", {}); - updateWidgetMetaProperty("selectColumnFilterText", {}); - updateWidgetMetaProperty("isAddRowInProgress", false); - updateWidgetMetaProperty("newRowContent", undefined); - updateWidgetMetaProperty("newRow", undefined); - updateWidgetMetaProperty("previousPageVisited", false); - updateWidgetMetaProperty("nextPageVisited", false); - - // reset and reload page - if (!isAlreadyOnFirstPage) { - this.updatePageNumber(1, EventType.ON_NEXT_PAGE); - } - } + resetWidget(this.props.widgetId, false); }; }