diff --git a/app/client/cypress/integration/Regression_TestSuite/ClientSideTests/Widgets/ListV2/Listv2_BasicClientSideData_spec.js b/app/client/cypress/integration/Regression_TestSuite/ClientSideTests/Widgets/ListV2/Listv2_BasicClientSideData_spec.js index 6616b0e56f..6e3702d949 100644 --- a/app/client/cypress/integration/Regression_TestSuite/ClientSideTests/Widgets/ListV2/Listv2_BasicClientSideData_spec.js +++ b/app/client/cypress/integration/Regression_TestSuite/ClientSideTests/Widgets/ListV2/Listv2_BasicClientSideData_spec.js @@ -1,9 +1,13 @@ const simpleListDSL = require("../../../../../fixtures/Listv2/simpleList.json"); const simpleListWithInputAndButtonDSL = require("../../../../../fixtures/Listv2/simpleListWithInputAndButton.json"); const publishLocators = require("../../../../../locators/publishWidgetspage.json"); +const commonlocators = require("../../../../../locators/commonlocators.json"); import { ObjectsRegistry } from "../../../../../support/Objects/Registry"; +const widgetSelector = (name) => `[data-widgetname-cy="${name}"]`; +const containerWidgetSelector = `[type="CONTAINER_WIDGET"]`; + let agHelper = ObjectsRegistry.AggregateHelper; const simpleListData1 = [ @@ -115,4 +119,34 @@ describe("List widget v2 - Basic client side data tests", () => { .should("have.value", index + 1); }); }); + + it("4. Reset pageNo when serverside pagination is enabled", () => { + cy.get(`${widgetSelector("List1")} .rc-pagination-item-3`).click({ + force: true, + }); + + cy.waitUntil(() => + cy.get(commonlocators.listPaginateActivePage).should("have.text", "3"), + ); + + cy.waitUntil(() => + cy + .get( + `${widgetSelector( + "List1", + )} ${containerWidgetSelector} .t--widget-imagewidget`, + ) + .should("have.length", 2), + ); + + cy.openPropertyPane("listwidgetv2"); + cy.togglebar(commonlocators.serverSidePaginationCheckbox); + + // Page number resets + cy.waitUntil(() => + cy.get(commonlocators.listPaginateActivePage).should("have.text", "1"), + ); + + cy.togglebarDisable(commonlocators.serverSidePaginationCheckbox); + }); }); diff --git a/app/client/src/widgets/ListWidgetV2/widget/index.tsx b/app/client/src/widgets/ListWidgetV2/widget/index.tsx index c5b4dec6e4..4e36d0f105 100644 --- a/app/client/src/widgets/ListWidgetV2/widget/index.tsx +++ b/app/client/src/widgets/ListWidgetV2/widget/index.tsx @@ -257,6 +257,11 @@ class ListWidget extends BaseWidget< this.pageSizeUpdated = true; } + if (this.serverPaginationJustEnabled(prevProps)) { + // reset pageNo when serverSide Pagination is just turned on + this.onPageChange(1); + } + if (this.isCurrPageNoGreaterThanMaxPageNo()) { const totalRecords = this.getTotalDataCount(); @@ -805,6 +810,12 @@ class ListWidget extends BaseWidget< return defaultValue; }; + serverPaginationJustEnabled = (prevProps: ListWidgetProps) => { + return Boolean( + !prevProps.serverSidePagination && this.props.serverSidePagination, + ); + }; + shouldPaginate = () => { /** * if client side pagination and not infinite scroll and data is more than page size