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", + }, + ]; + } + } + }); +}