WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import {
agHelper,
draggableWidgets,
entityExplorer,
propPane,
} from "../../../../../support/Objects/ObjectsCore";

const commonlocators = require("../../../../../locators/commonlocators.json");
const widgetsPage = require("../../../../../locators/Widgets.json");

// this spec will have a json form with two textinput fields and one is updated to switch field
// We will check the position property by clicking on the left and right position buttons
// here only alignment changes and the fields order in the dom changes so no assertions were added

describe(
"JSON Form Widget Custom Field",
{ tags: ["@tag.Widget", "@tag.JSONForm"] },
() => {
const schema = {
name: "John",
education: "1",
};

it("verifies the label position and alignment", () => {
entityExplorer.DragDropWidgetNVerify(draggableWidgets.JSONFORM, 300, 100);
propPane.EnterJSContext(
"sourcedata",
JSON.stringify(schema),
true,
false,
);
propPane.ChangeJsonFormFieldType("Education", "Switch");
agHelper.AssertClassExists(
widgetsPage.switchlabel,
widgetsPage.switchAlignRight,
);
agHelper
.GetNClick(commonlocators.optionposition)
.last()
.click({ force: true });
agHelper.GetNClick(widgetsPage.rightAlign).first().click({ force: true });
agHelper.AssertClassExists(
widgetsPage.switchlabel,
widgetsPage.switchAlignLeft,
);
agHelper
.GetNClick(commonlocators.optionpositionL)
.last()
.click({ force: true });
agHelper.AssertClassExists(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Harshithazemoso Do we need only class assert here? Just want to clarify this case is need from cypress side or unit testing can also help here.

widgetsPage.switchlabel,
widgetsPage.switchAlignRight,
);
propPane.NavigateBackToPropertyPane();
});
},
);
3 changes: 3 additions & 0 deletions app/client/cypress/locators/Widgets.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@
"codeScannerNewScanButton": "//*[text()='Scan Code']/parent::button",
"codeScannerClose": ".code-scanner-close",
"codeScannerModal": ".code-scanner-content",
"switchlabel": "label.bp3-switch",
"switchAlignRight": "bp3-align-right",
"switchAlignLeft": "bp3-align-left",
"showResult": ".t--property-control-showresult input[type='checkbox']",
"infiniteLoading": ".t--property-control-infiniteloading input[type='checkbox']",
"counterclockwise": ".t--property-control-counterclockwise input[type='checkbox']",
Expand Down
8 changes: 7 additions & 1 deletion app/client/packages/dsl/src/migrate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ import { migrateDefaultValuesForCustomEChart } from "./migrations/085-migrate-de
import { migrateTableServerSideFiltering } from "./migrations/086-migrate-table-server-side-filtering";
import { migrateChartwidgetCustomEchartConfig } from "./migrations/087-migrate-chart-widget-customechartdata";
import { migrateCustomWidgetDynamicHeight } from "./migrations/088-migrate-custom-widget-dynamic-height";
import { migrateJsonFormWidgetLabelPositonAndAlignment } from "./migrations/089-migrate-jsonformwidget-labelposition-and-alignment";
import type { DSLWidget } from "./types";

export const LATEST_DSL_VERSION = 89;
export const LATEST_DSL_VERSION = 90;

export const calculateDynamicHeight = () => {
const DEFAULT_GRID_ROW_HEIGHT = 10;
Expand Down Expand Up @@ -592,6 +593,11 @@ const migrateVersionedDSL = (currentDSL: DSLWidget, newPage = false) => {

if (currentDSL.version === 88) {
currentDSL = migrateCustomWidgetDynamicHeight(currentDSL);
currentDSL.version = 89;
}

if (currentDSL.version === 89) {
currentDSL = migrateJsonFormWidgetLabelPositonAndAlignment(currentDSL);
currentDSL.version = LATEST_DSL_VERSION;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import type { DSLWidget, WidgetProps } from "../types";
import { traverseDSLAndMigrate } from "../utils";

export const migrateJsonFormWidgetLabelPositonAndAlignment = (
currentDSL: DSLWidget,
) => {
return traverseDSLAndMigrate(currentDSL, (widget: WidgetProps) => {
if (widget.type == "JSON_FORM_WIDGET") {
const jsonFormWidgetProps = widget;
Object.keys(jsonFormWidgetProps.schema).forEach((key) => {
const field = jsonFormWidgetProps.schema[key];
if (field.children) {
Object.keys(field.children).forEach((childKey) => {
const childField = field.children[childKey];

if (
childField.fieldType === "Switch" &&
childField.alignWidget === "RIGHT"
) {
childField.alignWidget = "LEFT";
}

if (
childField.fieldType === "Checkbox" &&
childField.alignWidget === "LEFT"
) {
field.children[childKey] = {
...childField,
labelPosition: "Right",
};
}
if (
childField.fieldType === "Checkbox" &&
childField.alignWidget === "RIGHT"
) {
childField.alignWidget = "LEFT";
field.children[childKey] = {
...childField,
labelPosition: "Left",
};
}
});
}
});
}
});
};
10 changes: 10 additions & 0 deletions app/client/packages/dsl/src/migrate/tests/DSLMigration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import * as m85 from "../migrations/085-migrate-default-values-for-custom-echart
import * as m86 from "../migrations/086-migrate-table-server-side-filtering";
import * as m87 from "../migrations/087-migrate-chart-widget-customechartdata";
import * as m88 from "../migrations/088-migrate-custom-widget-dynamic-height";
import * as m89 from "../migrations/089-migrate-jsonformwidget-labelposition-and-alignment";

interface Migration {
functionLookup: {
Expand Down Expand Up @@ -920,6 +921,15 @@ const migrations: Migration[] = [
],
version: 88,
},
{
functionLookup: [
{
moduleObj: m89,
functionName: "migrateJsonFormWidgetLabelPositonAndAlignment",
},
],
version: 89,
},
];

const mockFnObj: Record<number, any> = {};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
import { migrateJsonFormWidgetLabelPositonAndAlignment } from "../migrations/089-migrate-jsonformwidget-labelposition-and-alignment";
import type { DSLWidget } from "../types";

const inputDsl: DSLWidget = {
widgetName: "MainContainer",
backgroundColor: "none",
rightColumn: 1118,
snapColumns: 16,
detachFromLayout: true,
widgetId: "0",
topRow: 0,
bottomRow: 1280,
containerStyle: "none",
snapRows: 33,
parentRowSpace: 1,
type: "CANVAS_WIDGET",
canExtend: true,
version: 15,
minHeight: 1292,
parentColumnSpace: 1,
dynamicTriggerPathList: [],
dynamicBindingPathList: [],
leftColumn: 0,
isLoading: false,
parentId: "",
renderMode: "CANVAS",
children: [
{
widgetName: "JSONForm1",
type: "JSON_FORM_WIDGET",
schema: {
field1: {
fieldType: "OBJECT",
children: {
switchField: {
accessor: "Test Switch",
accentColor: "#553DE9",
alignWidget: "RIGHT",
boxShadow: "none",
children: {},
dataType: "STRING",
defaultValue: "",
fieldType: "Switch",
identifier: "TEST_IDENTIFIER",
isCustomField: false,
isDisabled: false,
isRequired: false,
isVisible: true,
label: "Test Switch",
labelPosition: "Right",
labelStyle: "",
labelTextColor: "",
labelTextSize: "0.875rem",
originalIdentifier: "Test Switch",
position: 0,
sourceData: "har",
tooltip: "",
},
checkboxField1: {
accessor: "Test Checkbox 1",
accentColor: "#553DE9",
alignWidget: "LEFT",
boxShadow: "none",
children: {},
dataType: "STRING",
defaultValue: "",
fieldType: "Checkbox",
identifier: "TEST_IDENTIFIER_1",
isCustomField: false,
isDisabled: false,
isRequired: false,
isVisible: true,
label: "Test Checkbox 1",
labelPosition: "Left",
labelStyle: "",
labelTextColor: "",
labelTextSize: "0.875rem",
originalIdentifier: "Test Checkbox 1",
position: 1,
sourceData: "har",
tooltip: "",
},
checkboxField2: {
accessor: "Test Checkbox 2",
accentColor: "#553DE9",
alignWidget: "RIGHT",
boxShadow: "none",
children: {},
dataType: "STRING",
defaultValue: "",
fieldType: "Checkbox",
identifier: "TEST_IDENTIFIER_2",
isCustomField: false,
isDisabled: false,
isRequired: false,
isVisible: true,
label: "Test Checkbox 2",
labelPosition: "Left",
labelStyle: "",
labelTextColor: "",
labelTextSize: "0.875rem",
originalIdentifier: "Test Checkbox 2",
position: 2,
sourceData: "har",
tooltip: "",
},
},
},
},
widgetId: "jsonForm1",
dynamicBindingPathList: [],
renderMode: "CANVAS",
},
],
};

const outputDsl: DSLWidget = {
widgetName: "MainContainer",
backgroundColor: "none",
rightColumn: 1118,
snapColumns: 16,
detachFromLayout: true,
widgetId: "0",
topRow: 0,
bottomRow: 1280,
containerStyle: "none",
snapRows: 33,
parentRowSpace: 1,
type: "CANVAS_WIDGET",
canExtend: true,
version: 15,
minHeight: 1292,
parentColumnSpace: 1,
dynamicTriggerPathList: [],
dynamicBindingPathList: [],
leftColumn: 0,
isLoading: false,
parentId: "",
renderMode: "CANVAS",
children: [
{
widgetName: "JSONForm1",
type: "JSON_FORM_WIDGET",
schema: {
field1: {
fieldType: "OBJECT",
children: {
switchField: {
accessor: "Test Switch",
accentColor: "#553DE9",
alignWidget: "LEFT",
boxShadow: "none",
children: {},
dataType: "STRING",
defaultValue: "",
fieldType: "Switch",
identifier: "TEST_IDENTIFIER",
isCustomField: false,
isDisabled: false,
isRequired: false,
isVisible: true,
label: "Test Switch",
labelPosition: "Right",
labelStyle: "",
labelTextColor: "",
labelTextSize: "0.875rem",
originalIdentifier: "Test Switch",
position: 0,
sourceData: "har",
tooltip: "",
},
checkboxField1: {
accessor: "Test Checkbox 1",
accentColor: "#553DE9",
alignWidget: "LEFT",
boxShadow: "none",
children: {},
dataType: "STRING",
defaultValue: "",
fieldType: "Checkbox",
identifier: "TEST_IDENTIFIER_1",
isCustomField: false,
isDisabled: false,
isRequired: false,
isVisible: true,
label: "Test Checkbox 1",
labelPosition: "Right",
labelStyle: "",
labelTextColor: "",
labelTextSize: "0.875rem",
originalIdentifier: "Test Checkbox 1",
position: 1,
sourceData: "har",
tooltip: "",
},
checkboxField2: {
accessor: "Test Checkbox 2",
accentColor: "#553DE9",
alignWidget: "LEFT",
boxShadow: "none",
children: {},
dataType: "STRING",
defaultValue: "",
fieldType: "Checkbox",
identifier: "TEST_IDENTIFIER_2",
isCustomField: false,
isDisabled: false,
isRequired: false,
isVisible: true,
label: "Test Checkbox 2",
labelPosition: "Left",
labelStyle: "",
labelTextColor: "",
labelTextSize: "0.875rem",
originalIdentifier: "Test Checkbox 2",
position: 2,
sourceData: "har",
tooltip: "",
},
},
},
},
widgetId: "jsonForm1",
dynamicBindingPathList: [],
renderMode: "CANVAS",
},
],
};

describe("JSON Form Widget Property Migration", () => {
it("should migrate JSON Form widget properties correctly", () => {
const newDsl = migrateJsonFormWidgetLabelPositonAndAlignment(inputDsl);
expect(JSON.stringify(newDsl)).toBe(JSON.stringify(outputDsl));
});
});
Loading