From e56e3534008ec11c4bd5069f17da9d67d440c84d Mon Sep 17 00:00:00 2001 From: rahulramesha <71900764+rahulramesha@users.noreply.github.com> Date: Sun, 14 May 2023 22:40:20 +0530 Subject: [PATCH] fix: widget columns to have integers after conversion to fixed layout and redirect to home page while restoring if the page does not exist in the restored snapshot (#23144) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description This PR makes a change to make sure the widget's horizontal columns are integers, Also adding code to use the page list returned by the application while restoring snapshot #### PR fixes following issue(s) Fixes #23133 Fixes #23192 #### Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video > > #### Type of change - Bug fix (non-breaking change which fixes an issue)> ## Testing #### How Has This Been Tested? - [ ] Manual - [ ] Jest #### Test Plan > Add Testsmith test cases links that relate to this PR > > #### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) > > > ## Checklist: #### Dev activity - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Test-plan-implementation#speedbreaker-features-to-consider-for-every-change) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans/_edit#areas-of-interest) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed --- app/client/src/sagas/SnapshotSagas.ts | 23 ++++++++++++------- .../utils/DSLConversions/autoToFixedLayout.ts | 8 +++---- .../tests/autoToFixedLayout.test.ts | 18 +++++++-------- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/app/client/src/sagas/SnapshotSagas.ts b/app/client/src/sagas/SnapshotSagas.ts index 9429d62ba0..2c60e80ba0 100644 --- a/app/client/src/sagas/SnapshotSagas.ts +++ b/app/client/src/sagas/SnapshotSagas.ts @@ -4,6 +4,7 @@ import { } from "actions/autoLayoutActions"; import type { ApiResponse } from "api/ApiResponses"; import ApplicationApi from "@appsmith/api/ApplicationApi"; +import type { PageDefaultMeta } from "@appsmith/api/ApplicationApi"; import { ReduxActionTypes } from "@appsmith/constants/ReduxActionConstants"; import log from "loglevel"; import type { SnapShotDetails } from "reducers/uiReducers/layoutConversionReducer"; @@ -95,6 +96,20 @@ function* restoreApplicationFromSnapshotSaga() { getLogToSentryFromResponse(response), ); + // update the pages list temporarily with incomplete data. + if (response?.data?.pages) { + yield put({ + type: ReduxActionTypes.FETCH_PAGE_LIST_SUCCESS, + payload: { + pages: response.data.pages.map((page: PageDefaultMeta) => ({ + pageId: page.id, + isDefault: page.isDefault, + })), + applicationId, + }, + }); + } + //update layout positioning type from yield call( updateApplicationLayoutType, @@ -103,14 +118,6 @@ function* restoreApplicationFromSnapshotSaga() { : AppPositioningTypes.FIXED, ); - if (response?.data?.applicationDetail?.appPositioning?.type) { - //update layout positioning type from response - yield call( - updateApplicationLayoutType, - response.data.applicationDetail.appPositioning.type, - ); - } - if (isValidResponse) { //update conversion form state to success yield put( diff --git a/app/client/src/utils/DSLConversions/autoToFixedLayout.ts b/app/client/src/utils/DSLConversions/autoToFixedLayout.ts index de48eda692..db632dc09e 100644 --- a/app/client/src/utils/DSLConversions/autoToFixedLayout.ts +++ b/app/client/src/utils/DSLConversions/autoToFixedLayout.ts @@ -202,8 +202,8 @@ function processMobileCanvasChildren( ...currWidget, topRow: getTopRow(currWidget, true), bottomRow: getBottomRow(currWidget, true), - leftColumn: getLeftColumn(currWidget, true), - rightColumn: getRightColumn(currWidget, true), + leftColumn: Math.floor(getLeftColumn(currWidget, true)), + rightColumn: Math.floor(getRightColumn(currWidget, true)), }; currWidgets = convertAutoWidgetToFixed(currWidgets, childId, true); @@ -261,8 +261,8 @@ function processCanvasChildren( ...currWidget, topRow: getTopRow(currWidget, false), bottomRow: getBottomRow(currWidget, false), - leftColumn, - rightColumn, + leftColumn: Math.floor(leftColumn), + rightColumn: Math.floor(rightColumn), }; currWidgets = convertAutoWidgetToFixed(currWidgets, childId, false); diff --git a/app/client/src/utils/DSLConversions/tests/autoToFixedLayout.test.ts b/app/client/src/utils/DSLConversions/tests/autoToFixedLayout.test.ts index 626af35a96..d56890e037 100644 --- a/app/client/src/utils/DSLConversions/tests/autoToFixedLayout.test.ts +++ b/app/client/src/utils/DSLConversions/tests/autoToFixedLayout.test.ts @@ -564,7 +564,7 @@ describe("test Auto to Fixed Conversion methods", () => { leftColumn: 0, minWidth: 120, parentId: "vv54unn046", - rightColumn: 17.375565610859727, + rightColumn: 17, topRow: 0, type: "BUTTON_WIDGET", widgetId: "5c6gd8ynfa", @@ -696,7 +696,7 @@ describe("test Auto to Fixed Conversion methods", () => { minWidth: 120, parentId: "0", parentRowSpace: 10, - rightColumn: 17.375565610859727, + rightColumn: 17, topRow: 18.599999999999998, type: "BUTTON_WIDGET", widgetId: "n123229jea", @@ -718,7 +718,7 @@ describe("test Auto to Fixed Conversion methods", () => { leftColumn: 0, minWidth: 120, parentId: "0", - rightColumn: 17.375565610859727, + rightColumn: 17, topRow: 13.399999999999999, type: "BUTTON_WIDGET", widgetId: "p6em4n29z7", @@ -741,7 +741,7 @@ describe("test Auto to Fixed Conversion methods", () => { leftColumn: 0, minWidth: 120, parentId: "mw6t1nvt67", - rightColumn: 17.375565610859727, + rightColumn: 17, topRow: 5.2, type: "BUTTON_WIDGET", widgetId: "u0cd188upj", @@ -768,7 +768,7 @@ describe("test Auto to Fixed Conversion methods", () => { }, wixla6nh38: { bottomRow: 7, - leftColumn: 17.375565610859727, + leftColumn: 17, minWidth: 450, parentId: "vv54unn046", rightColumn: 64, @@ -880,7 +880,7 @@ describe("test Auto to Fixed Conversion methods", () => { leftColumn: 0, minWidth: 120, parentId: "vv54unn046", - rightColumn: 17.375565610859727, + rightColumn: 17, topRow: 0, type: "BUTTON_WIDGET", widgetId: "5c6gd8ynfa", @@ -1012,7 +1012,7 @@ describe("test Auto to Fixed Conversion methods", () => { minWidth: 120, parentId: "0", parentRowSpace: 10, - rightColumn: 17.375565610859727, + rightColumn: 17, topRow: 27.000000000000004, type: "BUTTON_WIDGET", widgetId: "n123229jea", @@ -1034,7 +1034,7 @@ describe("test Auto to Fixed Conversion methods", () => { leftColumn: 0, minWidth: 120, parentId: "0", - rightColumn: 17.375565610859727, + rightColumn: 17, topRow: 22.200000000000003, type: "BUTTON_WIDGET", widgetId: "p6em4n29z7", @@ -1057,7 +1057,7 @@ describe("test Auto to Fixed Conversion methods", () => { leftColumn: 0, minWidth: 120, parentId: "mw6t1nvt67", - rightColumn: 17.375565610859727, + rightColumn: 17, topRow: 4.8, type: "BUTTON_WIDGET", widgetId: "u0cd188upj",