diff --git a/canvas_modules/common-canvas/__tests__/common-properties/controls/expression-test.js b/canvas_modules/common-canvas/__tests__/common-properties/controls/expression-test.js index e836d4b0a2..ec611acfc9 100644 --- a/canvas_modules/common-canvas/__tests__/common-properties/controls/expression-test.js +++ b/canvas_modules/common-canvas/__tests__/common-properties/controls/expression-test.js @@ -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( + + + + ); + 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", () => { @@ -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(); @@ -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); @@ -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"); @@ -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"); }); }); diff --git a/canvas_modules/common-canvas/__tests__/test_resources/json/expression-function-list.json b/canvas_modules/common-canvas/__tests__/test_resources/json/expression-function-list.json index 91fb1229bd..759218fa87 100644 --- a/canvas_modules/common-canvas/__tests__/test_resources/json/expression-function-list.json +++ b/canvas_modules/common-canvas/__tests__/test_resources/json/expression-function-list.json @@ -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": [ { @@ -276,6 +279,9 @@ "default": "@BLANK" }, "return_type": "Boolean", + "return_type_label": { + "default": "Return type defined in return_type_label" + }, "id": "@BLANK", "parameters": [ { @@ -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", @@ -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": [ { @@ -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": { @@ -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": [ { @@ -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": [ { @@ -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": { @@ -1845,6 +1864,9 @@ "default": "@BLANK" }, "return_type": "Boolean", + "return_type_label": { + "default": "Return type defined in return_type_label" + }, "id": "@BLANK", "parameters": [ { @@ -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": { @@ -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": [ { @@ -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]" } ] }, diff --git a/canvas_modules/common-canvas/src/common-properties/controls/expression/expression-builder/expression-select-field-function.jsx b/canvas_modules/common-canvas/src/common-properties/controls/expression/expression-builder/expression-select-field-function.jsx index 73b639660f..3a5f9672b2 100644 --- a/canvas_modules/common-canvas/src/common-properties/controls/expression/expression-builder/expression-select-field-function.jsx +++ b/canvas_modules/common-canvas/src/common-properties/controls/expression/expression-builder/expression-select-field-function.jsx @@ -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 = ( diff --git a/canvas_modules/common-canvas/src/common-properties/controls/expression/expressionInfo-parser.js b/canvas_modules/common-canvas/src/common-properties/controls/expression/expressionInfo-parser.js index e28658d878..de8fe285e3 100644 --- a/canvas_modules/common-canvas/src/common-properties/controls/expression/expressionInfo-parser.js +++ b/canvas_modules/common-canvas/src/common-properties/controls/expression/expressionInfo-parser.js @@ -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) { @@ -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) { diff --git a/canvas_modules/harness/src/client/constants/json/functionlist.json b/canvas_modules/harness/src/client/constants/json/functionlist.json index e3029505bb..27033aab00 100644 --- a/canvas_modules/harness/src/client/constants/json/functionlist.json +++ b/canvas_modules/harness/src/client/constants/json/functionlist.json @@ -1086,6 +1086,9 @@ "default": "is_integer" }, "return_type": "Boolean", + "return_type_label": { + "resource_key": "is_integer_1.returnType.label" + }, "parameters": [ { "label": { @@ -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]" } }