fix: Migration to convert old defaultOptionValue expression to new one in Select & multi select widget(#16836)

This commit is contained in:
balajisoundar 2022-09-19 17:53:07 +05:30 committed by GitHub
parent 6fc2b1680e
commit 79073d82b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 1890 additions and 1 deletions

View File

@ -70,7 +70,7 @@ export const layoutConfigurations: LayoutConfigurations = {
FLUID: { minWidth: -1, maxWidth: -1 },
};
export const LATEST_PAGE_VERSION = 62;
export const LATEST_PAGE_VERSION = 63;
export const GridDefaults = {
DEFAULT_CELL_SIZE: 1,

View File

@ -15,6 +15,7 @@ import * as inputCurrencyMigration from "./migrations/CurrencyInputWidgetMigrati
import * as radioGroupMigration from "./migrations/RadioGroupWidget";
import * as propertyPaneMigrations from "./migrations/PropertyPaneMigrations";
import * as themingMigration from "./migrations/ThemingMigrations";
import * as selectWidgetMigration from "./migrations/SelectWidget";
import { LATEST_PAGE_VERSION } from "constants/WidgetConstants";
import { originalDSLForDSLMigrations } from "./testDSLs";
@ -604,6 +605,15 @@ const migrations: Migration[] = [
],
version: 61,
},
{
functionLookup: [
{
moduleObj: selectWidgetMigration,
functionName: "MigrateSelectTypeWidgetDefaultValue",
},
],
version: 62,
},
];
const mockFnObj: Record<number, any> = {};

View File

@ -60,6 +60,7 @@ import { migrateCurrencyInputWidgetDefaultCurrencyCode } from "./migrations/Curr
import { migrateRadioGroupAlignmentProperty } from "./migrations/RadioGroupWidget";
import { migrateCheckboxSwitchProperty } from "./migrations/PropertyPaneMigrations";
import { migrateChartWidgetReskinningData } from "./migrations/ChartWidgetReskinningMigrations";
import { MigrateSelectTypeWidgetDefaultValue } from "./migrations/SelectWidget";
/**
* adds logBlackList key for all list widget children
@ -1109,8 +1110,14 @@ export const transformDSL = (
if (currentDSL.version === 61) {
currentDSL = migrateChartWidgetReskinningData(currentDSL);
currentDSL.version = 62;
}
if (currentDSL.version === 62) {
currentDSL = MigrateSelectTypeWidgetDefaultValue(currentDSL);
currentDSL.version = LATEST_PAGE_VERSION;
}
return currentDSL;
};

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,36 @@
import {
getBindingTemplate,
stringToJS,
} from "components/propertyControls/SelectDefaultValueControl";
import { isDynamicValue } from "utils/DynamicBindingUtils";
import { WidgetProps } from "widgets/BaseWidget";
import { DSLWidget } from "widgets/constants";
const SelectTypeWidgets = ["SELECT_WIDGET", "MULTI_SELECT_WIDGET_V2"];
export function MigrateSelectTypeWidgetDefaultValue(currentDSL: DSLWidget) {
currentDSL.children = currentDSL.children?.map((child: WidgetProps) => {
if (SelectTypeWidgets.includes(child.type)) {
const defaultOptionValue = child.defaultOptionValue;
const { prefixTemplate, suffixTemplate } = getBindingTemplate(
child.widgetName,
);
if (
typeof defaultOptionValue === "string" &&
isDynamicValue(defaultOptionValue) &&
!defaultOptionValue.endsWith(suffixTemplate) &&
!defaultOptionValue.startsWith(prefixTemplate)
) {
child.defaultOptionValue = `${prefixTemplate}${stringToJS(
defaultOptionValue,
)}${suffixTemplate}`;
}
} else if (child.children && child.children.length > 0) {
child = MigrateSelectTypeWidgetDefaultValue(child);
}
return child;
});
return currentDSL;
}