From f2ceaca664d110a612e5917cce1a82d3a1b9fb2a Mon Sep 17 00:00:00 2001 From: balajisoundar Date: Tue, 15 Aug 2023 12:28:42 +0530 Subject: [PATCH] =?UTF-8?q?chore:=20Add=20sourceData=20of=20select=20and?= =?UTF-8?q?=20multi=20select=20widgets=20to=20dynamiPro=E2=80=A6=20(#26308?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …pertyPathList > Pull Request Template > > Use this template to quickly create a well written pull request. Delete all quotes before creating the pull request. > ## Description > Add a TL;DR when description is extra long (helps content team) > > Please include a summary of the changes and which issue has been fixed. Please also include relevant motivation > and context. List any dependencies that are required for this change > > Links to Notion, Figma or any other documents that might be relevant to the PR > > #### PR fixes following issue(s) Fixes https://github.com/appsmithorg/appsmith/issues/26307 > if no issue exists, please create an issue and ask the maintainers about this first > > #### 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 > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) - Breaking change (fix or feature that would cause existing functionality to not work as expected) - Chore (housekeeping or task changes that don't impact user perception) - This change requires a documentation update > > > ## Testing > #### How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Also list any relevant details for your test configuration. > Delete anything that is not relevant - [ ] Manual - [ ] Jest - [ ] Cypress > > #### 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/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#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/constants/WidgetConstants.tsx | 2 +- app/client/src/utils/DSLMigration.test.ts | 9 + app/client/src/utils/DSLMigrations.ts | 6 + .../src/utils/migrations/SelectWidget.test.ts | 204 ++++++++++++++++++ .../src/utils/migrations/SelectWidget.ts | 29 +++ 5 files changed, 249 insertions(+), 1 deletion(-) diff --git a/app/client/src/constants/WidgetConstants.tsx b/app/client/src/constants/WidgetConstants.tsx index 8aae88d9ad..0e4115044d 100644 --- a/app/client/src/constants/WidgetConstants.tsx +++ b/app/client/src/constants/WidgetConstants.tsx @@ -71,7 +71,7 @@ export const layoutConfigurations: LayoutConfigurations = { FLUID: { minWidth: -1, maxWidth: -1 }, }; -export const LATEST_PAGE_VERSION = 84; +export const LATEST_PAGE_VERSION = 85; export const GridDefaults = { DEFAULT_CELL_SIZE: 1, diff --git a/app/client/src/utils/DSLMigration.test.ts b/app/client/src/utils/DSLMigration.test.ts index 42a82f4590..ee89bcf530 100644 --- a/app/client/src/utils/DSLMigration.test.ts +++ b/app/client/src/utils/DSLMigration.test.ts @@ -810,6 +810,15 @@ const migrations: Migration[] = [ ], version: 83, }, + { + functionLookup: [ + { + moduleObj: selectWidgetMigration, + functionName: "migrateSelectWidgetAddSourceDataPropertyPathList", + }, + ], + version: 84, + }, ]; const mockFnObj: Record = {}; diff --git a/app/client/src/utils/DSLMigrations.ts b/app/client/src/utils/DSLMigrations.ts index 584f3c359f..9838685593 100644 --- a/app/client/src/utils/DSLMigrations.ts +++ b/app/client/src/utils/DSLMigrations.ts @@ -75,6 +75,7 @@ import { migrateCheckboxSwitchProperty } from "./migrations/PropertyPaneMigratio import { migrateChartWidgetReskinningData } from "./migrations/ChartWidgetReskinningMigrations"; import { MigrateSelectTypeWidgetDefaultValue, + migrateSelectWidgetAddSourceDataPropertyPathList, migrateSelectWidgetOptionToSourceData, migrateSelectWidgetSourceDataBindingPathList, } from "./migrations/SelectWidget"; @@ -1215,6 +1216,11 @@ export const transformDSL = (currentDSL: DSLWidget, newPage = false) => { if (currentDSL.version == 83) { currentDSL = migrateAddShowHideDataPointLabels(currentDSL); + currentDSL.version = 84; + } + + if (currentDSL.version === 84) { + currentDSL = migrateSelectWidgetAddSourceDataPropertyPathList(currentDSL); currentDSL.version = LATEST_PAGE_VERSION; } diff --git a/app/client/src/utils/migrations/SelectWidget.test.ts b/app/client/src/utils/migrations/SelectWidget.test.ts index 6a5ff3606f..2bf5fe3399 100644 --- a/app/client/src/utils/migrations/SelectWidget.test.ts +++ b/app/client/src/utils/migrations/SelectWidget.test.ts @@ -1,6 +1,7 @@ import type { DSLWidget } from "widgets/constants"; import { MigrateSelectTypeWidgetDefaultValue, + migrateSelectWidgetAddSourceDataPropertyPathList, migrateSelectWidgetSourceDataBindingPathList, } from "./SelectWidget"; @@ -1965,3 +1966,206 @@ describe("migrateSelectWidgetSourceDataBindingPathList", () => { }); }); }); + +describe("migrateSelectWidgetAddSourceDataPropertyPathList", () => { + test("should test that sourceData is added to the dynamicPropertyPathList", () => { + const result = migrateSelectWidgetAddSourceDataPropertyPathList({ + children: [ + { + type: "TABLE_WIDGET_V2", + options: [], + dynamicPropertyPathList: [ + { + key: "optionValue", + }, + { + key: "sourceData", + }, + { + key: "optionLabel", + }, + ], + }, + { + type: "TABLE_WIDGET_V2", + options: [], + dynamicPropertyPathList: [ + { + key: "optionValue", + }, + { + key: "optionLabel", + }, + ], + }, + { + type: "TABLE_WIDGET_V2", + options: [], + }, + { + type: "SELECT_WIDGET", + options: [], + dynamicPropertyPathList: [ + { + key: "optionValue", + }, + { + key: "sourceData", + }, + { + key: "optionLabel", + }, + ], + }, + { + type: "SELECT_WIDGET", + options: [], + dynamicPropertyPathList: [ + { + key: "optionValue", + }, + { + key: "optionLabel", + }, + ], + }, + { + type: "MULTI_SELECT_WIDGET_V2", + options: [], + dynamicPropertyPathList: [ + { + key: "optionLabel", + }, + { + key: "sourceData", + }, + { + key: "optionValue", + }, + ], + }, + { + type: "MULTI_SELECT_WIDGET_V2", + options: [], + dynamicPropertyPathList: [ + { + key: "optionLabel", + }, + { + key: "optionValue", + }, + ], + }, + { + type: "MULTI_SELECT_WIDGET_V2", + options: [], + }, + ], + } as any as DSLWidget); + + expect(result).toEqual({ + children: [ + { + type: "TABLE_WIDGET_V2", + options: [], + dynamicPropertyPathList: [ + { + key: "optionValue", + }, + { + key: "sourceData", + }, + { + key: "optionLabel", + }, + ], + }, + { + type: "TABLE_WIDGET_V2", + options: [], + dynamicPropertyPathList: [ + { + key: "optionValue", + }, + { + key: "optionLabel", + }, + ], + }, + { + type: "TABLE_WIDGET_V2", + options: [], + }, + { + type: "SELECT_WIDGET", + options: [], + dynamicPropertyPathList: [ + { + key: "optionValue", + }, + { + key: "sourceData", + }, + { + key: "optionLabel", + }, + ], + }, + { + type: "SELECT_WIDGET", + options: [], + dynamicPropertyPathList: [ + { + key: "optionValue", + }, + { + key: "optionLabel", + }, + { + key: "sourceData", + }, + ], + }, + { + type: "MULTI_SELECT_WIDGET_V2", + options: [], + dynamicPropertyPathList: [ + { + key: "optionLabel", + }, + { + key: "sourceData", + }, + { + key: "optionValue", + }, + ], + }, + { + type: "MULTI_SELECT_WIDGET_V2", + options: [], + dynamicPropertyPathList: [ + { + key: "optionLabel", + }, + { + key: "optionValue", + }, + { + key: "sourceData", + }, + ], + }, + { + type: "MULTI_SELECT_WIDGET_V2", + options: [], + dynamicPropertyPathList: [ + { + key: "sourceData", + }, + ], + }, + ], + }); + }); +}); diff --git a/app/client/src/utils/migrations/SelectWidget.ts b/app/client/src/utils/migrations/SelectWidget.ts index c983a43829..0886c04366 100644 --- a/app/client/src/utils/migrations/SelectWidget.ts +++ b/app/client/src/utils/migrations/SelectWidget.ts @@ -74,3 +74,32 @@ export function migrateSelectWidgetSourceDataBindingPathList( } }); } + +/* + * Migration to add sourceData to the dynamicPropertyPathList + */ +export function migrateSelectWidgetAddSourceDataPropertyPathList( + currentDSL: DSLWidget, +) { + return traverseDSLAndMigrate(currentDSL, (widget: WidgetProps) => { + if (["SELECT_WIDGET", "MULTI_SELECT_WIDGET_V2"].includes(widget.type)) { + const dynamicPropertyPathList = widget.dynamicPropertyPathList; + + const sourceDataIndex = dynamicPropertyPathList + ?.map((d) => d.key) + .indexOf("sourceData"); + + if (sourceDataIndex && sourceDataIndex === -1) { + dynamicPropertyPathList?.push({ + key: "sourceData", + }); + } else if (!Array.isArray(dynamicPropertyPathList)) { + widget.dynamicPropertyPathList = [ + { + key: "sourceData", + }, + ]; + } + } + }); +}