Skip to content
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

fix: Revert "fix: Correct Select Widget Mapping for Dynamic Label and Value Keys (#35862)" #38250

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -7,7 +7,6 @@ import {
locators,
propPane,
widgetLocators,
jsEditor,
} from "../../../../../support/Objects/ObjectsCore";
import EditorNavigation, {
EntityType,
Expand All @@ -21,24 +20,6 @@ describe(
entityExplorer.DragDropWidgetNVerify(draggableWidgets.SELECT);
});

const validateLabelAndValueKey = (labelKey: string, valueKey: string) => {
// Validate Label key
propPane.ToggleJSMode("Label key", true);
propPane.UpdatePropertyFieldValue("Label key", labelKey);
agHelper.SelectDropDown("Blue");
agHelper.ReadSelectedDropDownValue().then(($selectedValue) => {
expect($selectedValue).to.eq("Blue");
});

// Validate Value key
propPane.ToggleJSMode("Value key", true);
propPane.UpdatePropertyFieldValue("Value key", valueKey);
agHelper.SelectDropDown("Blue");
agHelper.ReadSelectedDropDownValue().then(($selectedValue) => {
expect($selectedValue).to.eq("Blue");
});
};

it("1. Validate Label properties - Text , Position , Alignment , Width(in columns)", function () {
//Text
propPane.TypeTextIntoField("Text", "Select Value");
Expand Down Expand Up @@ -318,37 +299,5 @@ describe(
deployMode.DeployApp(locators._widgetInDeployed(draggableWidgets.FORM));
cy.get(locators._selectClearButton_testId).should("not.exist");
});

it("10.Validate using function inside label key and value key returns correct label options", () => {
// Navigate back to the editor
deployMode.NavigateBacktoEditor();

// Select the widget
EditorNavigation.SelectEntityByName("Select1", EntityType.Widget);

// Validate keys
validateLabelAndValueKey("{{(() => 'name')()}}", "{{(() => 'code')()}}");

// Create JS Object with array data
jsEditor.CreateJSObject(
`export default {
array: [1, 2, 3]
}`,
{
completeReplace: true,
toRun: false,
prettify: true,
},
);

// Select the widget
EditorNavigation.SelectEntityByName("Select1", EntityType.Widget);

// Validate keys
validateLabelAndValueKey(
"{{JSObject1.array.length > 0 ? 'name' : ''}}",
"{{JSObject1.array.length > 0 ? 'code' : ''}}",
);
});
},
);
4 changes: 2 additions & 2 deletions app/client/src/widgets/SelectWidget/widget/derived.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ export default {
if (typeof props.optionLabel === "string") {
labels = sourceData.map((d) => d[props.optionLabel]);
} else if (_.isArray(props.optionLabel)) {
labels = sourceData.map((d, i) => d[props.optionLabel[i]]);
labels = props.optionLabel;
}

if (typeof props.optionValue === "string") {
values = sourceData.map((d) => d[props.optionValue]);
} else if (_.isArray(props.optionValue)) {
values = sourceData.map((d, i) => d[props.optionValue[i]]);
values = props.optionValue;
}
Comment on lines 8 to 18
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider adding type validation for array inputs

Since this is reverting a previous fix, we should ensure type safety for array inputs to prevent runtime errors.

Consider adding validation:

    } else if (_.isArray(props.optionLabel)) {
+     if (!props.optionLabel.every(label => label !== undefined)) {
+       console.warn("Invalid labels found in optionLabel array");
+     }
      labels = props.optionLabel;
    }

    if (typeof props.optionValue === "string") {
      values = sourceData.map((d) => d[props.optionValue]);
    } else if (_.isArray(props.optionValue)) {
+     if (!props.optionValue.every(value => value !== undefined)) {
+       console.warn("Invalid values found in optionValue array");
+     }
      values = props.optionValue;
    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (typeof props.optionLabel === "string") {
labels = sourceData.map((d) => d[props.optionLabel]);
} else if (_.isArray(props.optionLabel)) {
labels = sourceData.map((d, i) => d[props.optionLabel[i]]);
labels = props.optionLabel;
}
if (typeof props.optionValue === "string") {
values = sourceData.map((d) => d[props.optionValue]);
} else if (_.isArray(props.optionValue)) {
values = sourceData.map((d, i) => d[props.optionValue[i]]);
values = props.optionValue;
}
if (typeof props.optionLabel === "string") {
labels = sourceData.map((d) => d[props.optionLabel]);
} else if (_.isArray(props.optionLabel)) {
if (!props.optionLabel.every(label => label !== undefined)) {
console.warn("Invalid labels found in optionLabel array");
}
labels = props.optionLabel;
}
if (typeof props.optionValue === "string") {
values = sourceData.map((d) => d[props.optionValue]);
} else if (_.isArray(props.optionValue)) {
if (!props.optionValue.every(value => value !== undefined)) {
console.warn("Invalid values found in optionValue array");
}
values = props.optionValue;
}


return sourceData.map((d, i) => ({
Expand Down
Loading