From 6d1fd096d1cac41d8ad7e93a7b2be8d799c7aff4 Mon Sep 17 00:00:00 2001 From: rahulramesha <71900764+rahulramesha@users.noreply.github.com> Date: Mon, 8 May 2023 15:26:41 +0530 Subject: [PATCH] fix: layout conversion for git apps by getting actual page list from current list and dynamic binding path fix (#22968) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description This PR provides a fix by checking the page list from current branch before converting the pages in git connected apps. This PR also changes dynamic binding paths verification logic to use lodash's get instead of directly accessing key to cater for nested paths Fixes #22698 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) ## How Has This Been Tested? - Manual ### 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: - [ ] Test plan has been approved by relevant developers - [ ] Test plan has been peer reviewed by QA - [ ] Cypress test cases have been added and approved by either SDET or manual QA - [ ] Organized project review call with relevant stakeholders after Round 1/2 of QA - [ ] Added Test Plan Approved label after reveiwing all Cypress test --- app/client/src/sagas/layoutConversionSagas.ts | 24 +++++++++++++------ .../utils/DSLConversions/fixedToAutoLayout.ts | 8 +++---- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/app/client/src/sagas/layoutConversionSagas.ts b/app/client/src/sagas/layoutConversionSagas.ts index 370ab2d8e7..c5cd40c723 100644 --- a/app/client/src/sagas/layoutConversionSagas.ts +++ b/app/client/src/sagas/layoutConversionSagas.ts @@ -1,5 +1,6 @@ import { setLayoutConversionStateAction } from "actions/autoLayoutActions"; import { ReduxActionTypes } from "@appsmith/constants/ReduxActionConstants"; +import type { Page } from "@appsmith/constants/ReduxActionConstants"; import type { ReduxAction } from "@appsmith/constants/ReduxActionConstants"; import type { AppState } from "@appsmith/reducers"; import { MAIN_CONTAINER_WIDGET_ID } from "constants/WidgetConstants"; @@ -21,7 +22,10 @@ import * as Sentry from "@sentry/react"; import log from "loglevel"; import { saveAllPagesSaga } from "./PageSagas"; import { updateApplicationLayout } from "@appsmith/actions/applicationActions"; -import { getCurrentApplicationId } from "selectors/editorSelectors"; +import { + getCurrentApplicationId, + getPageList, +} from "selectors/editorSelectors"; import { updateApplicationLayoutType } from "./AutoLayoutUpdateSagas"; import AnalyticsUtil from "utils/AnalyticsUtil"; @@ -33,9 +37,11 @@ function* convertFromAutoToFixedSaga(action: ReduxAction) { let appId = ""; let snapshotSaveSuccess = false; try { - appId = yield select(getCurrentApplicationId); + const pageList: Page[] = yield select(getPageList); const pageWidgetsList: PageWidgetsReduxState = yield select(getPageWidgets); + appId = yield select(getCurrentApplicationId); + const notEmptyApp = isNotEmptyApp(pageWidgetsList); if (notEmptyApp) { @@ -55,8 +61,9 @@ function* convertFromAutoToFixedSaga(action: ReduxAction) { const pageLayouts = []; //Convert all the pages into Fixed layout by iterating over the list - for (const [pageId, page] of Object.entries(pageWidgetsList)) { - const { dsl: normalizedDSL, layoutId } = page; + for (const page of pageList) { + const pageId = page?.pageId; + const { dsl: normalizedDSL, layoutId } = pageWidgetsList[pageId]; const fixedLayoutDSL = convertNormalizedDSLToFixed( normalizedDSL, @@ -120,9 +127,11 @@ function* convertFromFixedToAutoSaga() { let appId = ""; let snapshotSaveSuccess = false; try { - appId = yield select(getCurrentApplicationId); + const pageList: Page[] = yield select(getPageList); const pageWidgetsList: PageWidgetsReduxState = yield select(getPageWidgets); + appId = yield select(getCurrentApplicationId); + const notEmptyApp = isNotEmptyApp(pageWidgetsList); if (notEmptyApp) { @@ -141,8 +150,9 @@ function* convertFromFixedToAutoSaga() { const pageLayouts = []; - for (const [pageId, page] of Object.entries(pageWidgetsList)) { - const { dsl: normalizedDSL, layoutId } = page; + for (const page of pageList) { + const pageId = page?.pageId; + const { dsl: normalizedDSL, layoutId } = pageWidgetsList[pageId]; const fixedDSL: DSLWidget = CanvasWidgetsNormalizer.denormalize( MAIN_CONTAINER_WIDGET_ID, diff --git a/app/client/src/utils/DSLConversions/fixedToAutoLayout.ts b/app/client/src/utils/DSLConversions/fixedToAutoLayout.ts index a5971e9514..2b2d6175c4 100644 --- a/app/client/src/utils/DSLConversions/fixedToAutoLayout.ts +++ b/app/client/src/utils/DSLConversions/fixedToAutoLayout.ts @@ -3,7 +3,7 @@ import { layoutConfigurations, MAIN_CONTAINER_WIDGET_ID, } from "constants/WidgetConstants"; -import { partition } from "lodash"; +import { get, partition } from "lodash"; import CanvasWidgetsNormalizer from "normalizers/CanvasWidgetsNormalizer"; import type { FlexLayer } from "utils/autoLayout/autoLayoutTypes"; import { alterLayoutForDesktop } from "utils/autoLayout/AutoLayoutUtils"; @@ -822,10 +822,8 @@ function verifyDynamicPathBindingList( const dynamicBindingPathList: DynamicPath[] = []; for (const dynamicBindingPath of widget.dynamicBindingPathList) { //if the values are not dynamic, remove from the dynamic binding path list - if ( - !widget[dynamicBindingPath.key] || - !isDynamicValue(widget[dynamicBindingPath.key]) - ) { + const dynamicValue = get(widget, dynamicBindingPath.key); + if (!dynamicValue || !isDynamicValue(dynamicValue)) { continue; }