Skip to content

Commit

Permalink
#1183 Translate return type of function in Expression Builder (#1184)
Browse files Browse the repository at this point in the history
  • Loading branch information
nmgokhale authored Sep 21, 2022
1 parent 91e9a1b commit 3462080
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,55 @@ describe("expression-builder renders correctly", () => {
expect(functionsTable).to.have.length(1);
expect(functionsTable.find(".properties-ft-empty-table").text()).to.equal(expressionInfo.resources[MESSAGE_KEYS.EXPRESSION_NO_FUNCTIONS]);
});

it("Functions table should display 'Return' column from return_type_label, default to return_type if undefined", () => {
const wrapper = mountWithIntl(
<Provider store={controller.getStore()}>
<ExpressionBuilder
control={control}
controller={controller}
propertyId={propertyId}
/>
</Provider>
);
wrapper.find("button.expresson-builder-function-tab").simulate("click");

// Verify Return column in "General Functions" table
let functionsTable = wrapper.find("div.properties-functions-table").find(".ReactVirtualized__Table");
expect(functionsTable).to.have.length(1);
let rows = tableUtils.getTableRows(functionsTable);
expect(rows).to.have.length(4);
rows.forEach((row, idx) => {
const functionInfo = ExpressionInfo.actual.functionCategories["General Functions"].functionList[idx];
// Verify values in "Return" column match with "return_type_label". Default to "return_type".
const expectedReturnType = functionInfo.locReturnType ? functionInfo.locReturnType : functionInfo.return_type;
const actualReturnType = row.find(".ReactVirtualized__Table__rowColumn")
.at(1)
.text();
expect(expectedReturnType).to.eql(actualReturnType);
});

// Navigate to Information table
var dropDown = wrapper.find("div.properties-expression-function-select .bx--list-box__field");
dropDown.simulate("click");
var dropDownList = wrapper.find("div.bx--list-box__menu .bx--list-box__menu-item");
dropDownList.at(2).simulate("click");
expect(wrapper.find("div.properties-expression-function-select span").text()).to.equal("Information");

// Verify Return column in "Information" table
functionsTable = wrapper.find("div.properties-functions-table").find(".ReactVirtualized__Table");
rows = tableUtils.getTableRows(functionsTable);
expect(rows).to.have.length(3);
rows.forEach((row, idx) => {
const functionInfo = ExpressionInfo.actual.functionCategories.Information.functionList[idx];
// Verify values in "Return" column match with "return_type_label". Default to "return_type".
const expectedReturnType = functionInfo.locReturnType ? functionInfo.locReturnType : functionInfo.return_type;
const actualReturnType = row.find(".ReactVirtualized__Table__rowColumn")
.at(1)
.text();
expect(expectedReturnType).to.eql(actualReturnType);
});
});
});

describe("expression-builder select from tables correctly", () => {
Expand Down Expand Up @@ -744,7 +793,7 @@ describe("ExpressionBuilder filters and sorts correctly", () => {
functionTable = wrapper.find("div.properties-functions-table");
rows = tableUtils.getTableRows(functionTable);
expect(rows).to.have.length(1);
expect(rows.at(0).text()).to.equal("to_integer(Item)Integer");
expect(rows.at(0).text()).to.equal("to_integer(Item)[Esperanto~Integer~~eo]");
});
it("expression builder sorts fields table", () => {
reset();
Expand Down Expand Up @@ -811,7 +860,7 @@ describe("ExpressionBuilder filters and sorts correctly", () => {
const rows = tableUtils.getTableRows(functionTable);
const sortHeaders = functionTable.find(".ReactVirtualized__Table__sortableHeaderColumn");
expect(rows).to.have.length(4);
expect(rows.at(0).text()).to.equal("to_integer(Item)Integer");
expect(rows.at(0).text()).to.equal("to_integer(Item)[Esperanto~Integer~~eo]");
expect(sortHeaders).to.have.length(2);

tableUtils.clickHeaderColumnSort(functionTable, 0);
Expand Down Expand Up @@ -935,7 +984,7 @@ describe("expression builder correctly runs Recently Used dropdown options", ()
funcRows = tableUtils.getTableRows(wrapper.find("div.properties-functions-table-container"));
expect(funcRows).to.have.length(2);
expect(funcRows.at(0).text()).to.equal("count_equal(Item, List)Integer");
expect(funcRows.at(1).text()).to.equal("to_integer(Item)Integer");
expect(funcRows.at(1).text()).to.equal("to_integer(Item)[Esperanto~Integer~~eo]");
// check that reusing a function will move it to the top of Recently Used
dropDown = wrapper.find("div.properties-expression-function-select .bx--list-box__field");
dropDown.simulate("click");
Expand All @@ -952,7 +1001,7 @@ describe("expression builder correctly runs Recently Used dropdown options", ()
// order of rows should be reversed
funcRows = tableUtils.getTableRows(wrapper.find("div.properties-functions-table-container"));
expect(funcRows).to.have.length(2);
expect(funcRows.at(0).text()).to.equal("to_integer(Item)Integer");
expect(funcRows.at(0).text()).to.equal("to_integer(Item)[Esperanto~Integer~~eo]");
expect(funcRows.at(1).text()).to.equal("count_equal(Item, List)Integer");
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@
"resource_key": "to_integer.label"
},
"return_type": "Integer",
"return_type_label": {
"resource_key": "to_integer.returnType.label"
},
"id": "to_integer",
"parameters": [
{
Expand Down Expand Up @@ -276,6 +279,9 @@
"default": "@BLANK"
},
"return_type": "Boolean",
"return_type_label": {
"default": "Return type defined in return_type_label"
},
"id": "@BLANK",
"parameters": [
{
Expand Down Expand Up @@ -969,6 +975,7 @@
"group.GeneralFunctions.label": "General Functions",
"to_integer.label": "to_integer",
"to_integer.item.param": "Item",
"to_integer.returnType.label": "[Esperanto~Integer~~eo]",
"to_integer.item.help": "Converts ITEM to an integer. ITEM must be a string, or a number.",
"expression.no.functions": "There are no functions",
"expression.fields.empty.table.label": "There are no fields",
Expand Down Expand Up @@ -1150,6 +1157,9 @@
"resource_key": "to_integer.label"
},
"return_type": "Integer",
"return_type_label": {
"resource_key": "to_integer.returnType.label"
},
"id": "to_integer",
"parameters": [
{
Expand All @@ -1165,7 +1175,8 @@
},
"locLabel": "to_integer(Item)",
"help": "Converts ITEM to an integer. ITEM must be a string, or a number.",
"value": "to_integer(?)"
"value": "to_integer(?)",
"locReturnType": "[Esperanto~Integer~~eo]"
},
{
"label": {
Expand Down Expand Up @@ -1281,6 +1292,9 @@
"resource_key": "to_integer.label"
},
"return_type": "Integer",
"return_type_label": {
"resource_key": "to_integer.returnType.label"
},
"id": "to_integer",
"parameters": [
{
Expand All @@ -1296,13 +1310,17 @@
},
"locLabel": "to_integer(Item)",
"help": "Converts ITEM to an integer. ITEM must be a string, or a number.",
"value": "to_integer(?)"
"value": "to_integer(?)",
"locReturnType": "[Esperanto~Integer~~eo]"
},
{
"label": {
"default": "@BLANK"
},
"return_type": "Boolean",
"return_type_label": {
"default": "Return type defined in return_type_label"
},
"id": "@BLANK",
"parameters": [
{
Expand All @@ -1316,7 +1334,8 @@
},
"locLabel": "@BLANK(Item)",
"help": "Returns true if the value of FIELD is blank according to the definition for FIELD in an upstream type node.",
"value": "@BLANK(?)"
"value": "@BLANK(?)",
"locReturnType": "Return type defined in return_type_label"
},
{
"label": {
Expand Down Expand Up @@ -1845,6 +1864,9 @@
"default": "@BLANK"
},
"return_type": "Boolean",
"return_type_label": {
"default": "Return type defined in return_type_label"
},
"id": "@BLANK",
"parameters": [
{
Expand All @@ -1858,7 +1880,8 @@
},
"locLabel": "@BLANK(Item)",
"help": "Returns true if the value of FIELD is blank according to the definition for FIELD in an upstream type node.",
"value": "@BLANK(?)"
"value": "@BLANK(?)",
"locReturnType": "Return type defined in return_type_label"
},
{
"label": {
Expand Down Expand Up @@ -1896,6 +1919,9 @@
"resource_key": "to_integer.label"
},
"return_type": "Integer",
"return_type_label": {
"resource_key": "to_integer.returnType.label"
},
"id": "to_integer",
"parameters": [
{
Expand All @@ -1911,7 +1937,8 @@
},
"locLabel": "to_integer(Item)",
"help": "Converts ITEM to an integer. ITEM must be a string, or a number.",
"value": "to_integer(?)"
"value": "to_integer(?)",
"locReturnType": "[Esperanto~Integer~~eo]"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,9 @@ export default class ExpressionSelectFieldOrFunction extends React.Component {
const columns = [];
if (!this.state.functionFilterText || this.state.functionFilterText.length === 0 ||
(catFunction.locLabel.toLowerCase().indexOf(this.state.functionFilterText.toLowerCase()) > -1)) {
const returnType = catFunction.locReturnType ? catFunction.locReturnType : catFunction.return_type;
columns.push({ column: "function", content: this.createContentObject(catFunction.locLabel), value: catFunction.locLabel });
columns.push({ column: "return", content: this.createContentObject(catFunction.return_type), value: catFunction.return_type });
columns.push({ column: "return", content: this.createContentObject(returnType), value: returnType });
table.rows.push({ columns: columns, rowKey: index });
if (index === this.state.functionSelected) {
table.helpContainer = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import logger from "../../../../utils/logger";
import { L10nProvider } from "../../util/L10nProvider";
import { L10nProvider, ResourceDef } from "../../util/L10nProvider";
import { cloneDeep, propertyOf } from "lodash";

function setExpressionInfo(inExpressionInfo) {
Expand Down Expand Up @@ -90,6 +90,11 @@ function _genFunctionParameters(functionInfoList, l10nProvider) {
newEntry.locLabel = l10nProvider.l10nLabel(newEntry, newEntry.id);
newEntry.help = l10nProvider.l10nDesc(newEntry, newEntry.locLabel);
newEntry.value = newEntry.locLabel;
// Translatable return type of function
if (newEntry.return_type_label) {
const returnTypeLabel = ResourceDef.make(newEntry.return_type_label);
newEntry.locReturnType = l10nProvider.l10nResource(returnTypeLabel);
}
if (Array.isArray(functionInfo.parameters)) {
// if the function label has any parameter substituion char '?' then replace with parameter label
if (newEntry.locLabel && newEntry.locLabel.indexOf("?") !== -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,9 @@
"default": "is_integer"
},
"return_type": "Boolean",
"return_type_label": {
"resource_key": "is_integer_1.returnType.label"
},
"parameters": [
{
"label": {
Expand Down Expand Up @@ -6507,6 +6510,7 @@
"globals.label": "Globals",
"expression.no.functions": "There are no functions",
"expression.fields.empty.table.label": "There are no fields",
"expression.values.empty.table.label": "There are no values"
"expression.values.empty.table.label": "There are no values",
"is_integer_1.returnType.label": "[Esperanto~Boolean~~eo]"
}
}

0 comments on commit 3462080

Please sign in to comment.