-
Notifications
You must be signed in to change notification settings - Fork 4.4k
fix:JSONForm > Switch Field: label position has no effect, label wrap… #34298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: release
Are you sure you want to change the base?
Changes from all commits
bf7cc79
ea3361c
f3ab0fa
36d870d
a62edd3
0bb8ff6
a71c61f
bfd3bc8
fa0bba4
530e1b0
a76c18b
c63bf04
721ed5b
058715c
6025bf2
fd03737
9d4e6b6
20a0eb2
bb879f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
| }); | ||
rahulbarwal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| ); | ||
| 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", | ||
| }; | ||
| } | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
| }); | ||
|
Comment on lines
+7
to
+46
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The migration logic is correct, but there's room for improvement. 🚀 The function correctly traverses the DSL and applies the necessary migrations for "Switch" and "Checkbox" fields. However, consider the following suggestions to enhance the code:
Here's an example of how you can refactor the code: const migrateCheckboxField = (field: any) => {
if (field.alignWidget === "LEFT") {
field.labelPosition = "Right";
} else if (field.alignWidget === "RIGHT") {
field.alignWidget = "LEFT";
field.labelPosition = "Left";
}
};
const migrateSwitchField = (field: any) => {
if (field.alignWidget === "RIGHT") {
field.alignWidget = "LEFT";
}
};
const migrateField = (field: any) => {
if (field.fieldType === "Switch") {
migrateSwitchField(field);
} else if (field.fieldType === "Checkbox") {
migrateCheckboxField(field);
}
if (field.children) {
Object.values(field.children).forEach(migrateField);
}
};
export const migrateJsonFormWidgetLabelPositonAndAlignment = (
currentDSL: DSLWidget,
) => {
return traverseDSLAndMigrate(currentDSL, (widget: WidgetProps) => {
if (widget.type === "JSON_FORM_WIDGET") {
Object.values(widget.schema).forEach(migrateField);
}
});
};These changes will make the code more maintainable and easier to understand. Let me know if you have any further questions! |
||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.