fix: Migration to convert old defaultOptionValue expression to new one in Select & multi select widget(#16836)
This commit is contained in:
parent
6fc2b1680e
commit
79073d82b7
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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> = {};
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
|
|||
1836
app/client/src/utils/migrations/SelectWidget.test.ts
Normal file
1836
app/client/src/utils/migrations/SelectWidget.test.ts
Normal file
File diff suppressed because it is too large
Load Diff
36
app/client/src/utils/migrations/SelectWidget.ts
Normal file
36
app/client/src/utils/migrations/SelectWidget.ts
Normal 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;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user