-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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 16 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]; | ||
rahulbarwal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if (field.children) { | ||
| Object.keys(field.children).forEach((childKey) => { | ||
| const childField = field.children[childKey]; | ||
rahulbarwal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if ( | ||
| childField.fieldType === "Switch" && | ||
| childField.alignWidget === "RIGHT" | ||
| ) { | ||
| childField.alignWidget = "LEFT"; | ||
| } | ||
|
|
||
| if ( | ||
| childField.fieldType === "Checkbox" && | ||
| childField.alignWidget === "LEFT" | ||
| ) { | ||
| field.children[childKey] = { | ||
| ...childField, | ||
| labelPosition: "Right", | ||
| }; | ||
rahulbarwal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| if ( | ||
| childField.fieldType === "Checkbox" && | ||
| childField.alignWidget === "RIGHT" | ||
| ) { | ||
| childField.alignWidget = "LEFT"; | ||
| field.children[childKey] = { | ||
| ...childField, | ||
| labelPosition: "Left", | ||
| }; | ||
| } | ||
| }); | ||
| } | ||
| }); | ||
| } | ||
| }); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -23,6 +23,7 @@ type SwitchComponentOwnProps = FieldComponentBaseProps & | |||||||
| alignWidget: AlignWidget; | ||||||||
| accentColor?: string; | ||||||||
| onChange?: string; | ||||||||
| labelPosition: LabelPosition; | ||||||||
| }; | ||||||||
|
|
||||||||
| type SwitchFieldProps = BaseFieldComponentProps<SwitchComponentOwnProps>; | ||||||||
|
|
@@ -36,6 +37,7 @@ const COMPONENT_DEFAULT_VALUES: SwitchComponentOwnProps = { | |||||||
| isVisible: true, | ||||||||
| labelTextSize: BASE_LABEL_TEXT_SIZE, | ||||||||
| label: "", | ||||||||
| labelPosition: LabelPosition.Left, | ||||||||
| }; | ||||||||
|
|
||||||||
| const isValid = (value: boolean, schemaItem: SwitchFieldProps["schemaItem"]) => | ||||||||
|
|
@@ -99,7 +101,7 @@ function SwitchField({ | |||||||
| isLoading={false} | ||||||||
| isSwitchedOn={value ?? false} | ||||||||
| label="" | ||||||||
| labelPosition={LabelPosition.Left} | ||||||||
| labelPosition={schemaItem.labelPosition} | ||||||||
|
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 assignment within the expression should be avoided as it can lead to confusion and potential bugs. Consider restructuring this part of the code to separate the assignment from the expression. - labelPosition={schemaItem.labelPosition}
+ const labelPos = schemaItem.labelPosition;
+ labelPosition={labelPos}Committable suggestion
Suggested change
|
||||||||
| onChange={onSwitchChange} | ||||||||
| widgetId="" | ||||||||
| /> | ||||||||
|
|
@@ -109,18 +111,21 @@ function SwitchField({ | |||||||
| schemaItem.accentColor, | ||||||||
| schemaItem.isDisabled, | ||||||||
| onSwitchChange, | ||||||||
| schemaItem.labelPosition, | ||||||||
| value, | ||||||||
| ], | ||||||||
| ); | ||||||||
|
|
||||||||
| return ( | ||||||||
| <Field | ||||||||
| accessor={schemaItem.accessor} | ||||||||
| alignField={schemaItem.alignWidget} | ||||||||
| defaultValue={passedDefaultValue ?? schemaItem.defaultValue} | ||||||||
| fieldClassName={fieldClassName} | ||||||||
| inlineLabel | ||||||||
| isRequiredField={schemaItem.isRequired} | ||||||||
| label={schemaItem.label} | ||||||||
| labelPosition={schemaItem.labelPosition} | ||||||||
| labelStyle={schemaItem.labelStyle} | ||||||||
| labelTextColor={schemaItem.labelTextColor} | ||||||||
| labelTextSize={schemaItem.labelTextSize} | ||||||||
|
|
||||||||
Uh oh!
There was an error while loading. Please reload this page.