From 71555f5d8e53479585f798dc5c58e9fc5b06ee62 Mon Sep 17 00:00:00 2001 From: Neha Gokhale Date: Mon, 30 Oct 2023 15:33:43 -0700 Subject: [PATCH] #1611 Filter getPropertyValues() based on the selected tab Signed-off-by: Neha Gokhale --- .../common-properties/form/form-test.js | 12 ++- .../properties-controller-test.js | 98 +++++++++++++++++++ .../json/form-actions-test.json | 51 ++++++++++ .../json/form-editstyle-test.json | 19 ++++ .../json/form-placement-test.json | 14 +++ .../json/form-structure-test.json | 14 +++ .../json/form-structure2-test.json | 14 +++ .../json/form-test-condition.json | 14 +++ .../test_resources/json/form-test.json | 59 +++++++++++ .../src/common-properties/form/Form.js | 4 +- .../properties-controller.js | 44 ++++++++- 11 files changed, 340 insertions(+), 3 deletions(-) diff --git a/canvas_modules/common-canvas/__tests__/common-properties/form/form-test.js b/canvas_modules/common-canvas/__tests__/common-properties/form/form-test.js index f0bb07e328..f6c466cd93 100644 --- a/canvas_modules/common-canvas/__tests__/common-properties/form/form-test.js +++ b/canvas_modules/common-canvas/__tests__/common-properties/form/form-test.js @@ -93,11 +93,21 @@ describe("Correct form should be created", () => { "boolean_param": true } }; + const groupMetadata = { + "groups": [ + { + "name": "settings", + "parameters": [ + "boolean_param" + ] + } + ] + }; let help; let pixelWidth; // Pass in an undefined pixelWidth to simulate it missing from ParamDefs. let conditions; let resources; - const expectedForm = new Form("TestOp", "TestOp", true, help, "small", pixelWidth, [primaryTabs], buttons, data, conditions, resources, "./test.svg"); + const expectedForm = new Form("TestOp", "TestOp", true, help, "small", pixelWidth, [primaryTabs], buttons, data, conditions, groupMetadata, resources, "./test.svg"); const paramSpec = { "current_parameters": { diff --git a/canvas_modules/common-canvas/__tests__/common-properties/properties-controller-test.js b/canvas_modules/common-canvas/__tests__/common-properties/properties-controller-test.js index d691c968ae..3bf8528d6e 100644 --- a/canvas_modules/common-canvas/__tests__/common-properties/properties-controller-test.js +++ b/canvas_modules/common-canvas/__tests__/common-properties/properties-controller-test.js @@ -27,6 +27,8 @@ import structureTableParamDef from "../test_resources/paramDefs/structuretable_p import checkboxsetParamDef from "../test_resources/paramDefs/checkboxset_paramDef.json"; import actionParamDef from "../test_resources/paramDefs/action_paramDef.json"; import numberfieldParamDef from "../test_resources/paramDefs/numberfield_paramDef.json"; +import textfieldParamDef from "../test_resources/paramDefs/textfield_paramDef.json"; +import tabParamDef from "../test_resources/paramDefs/tab_paramDef.json"; import structuretablePropertyValues from "../test_resources/json/structuretable_propertyValues.json"; import ExpressionInfo from "../test_resources/json/expression-function-list.json"; import readonlyTableParamDef from "../test_resources/paramDefs/readonlyTable_paramDef.json"; @@ -590,6 +592,102 @@ describe("Properties Controller property values", () => { const actualFilteredValues = controller.getPropertyValues({ filterHiddenControls: true, filterHiddenDisabled: true }); expect(expectedFilteredValues).to.eql(actualFilteredValues); }); + + it("should get properties in active tab correctly", () => { + let renderedObject = testUtils.flyoutEditorForm(textfieldParamDef); + controller = renderedObject.controller; + let wrapper = renderedObject.wrapper; + + // Open "Conditions" category + const conditionsCategory = wrapper.find("div.properties-category-container").at(1); + const conditionsButton = conditionsCategory.find("button.properties-category-title"); + expect(conditionsButton.text()).to.equal("Conditions"); + conditionsButton.simulate("click"); + + // Get all properties in active tab ("Conditions" tab) + let expectedAllPropertiesInActiveTab = { + string_error: "testing", + string_warning: "testing", + hide: true, + string_hidden: "testing", + disable: true, + string_disabled: "testing", + string_condition_handling: "testing" + }; + let actualAllPropertiesInActiveTab = controller.getPropertyValues({ getActiveTabControls: true }); + expect(expectedAllPropertiesInActiveTab).to.eql(actualAllPropertiesInActiveTab); + + // getActiveTabControls: return all properties under selected tab/category + // filterHiddenDisabled: filter controls having state "hidden" or "disabled" + const expectedFilteredHiddenDisabledPropertiesInActiveTab = { + string_error: "testing", + string_warning: "testing", + hide: true, + disable: true, + string_condition_handling: "testing" + }; + const actualFilteredHiddenDisabledPropertiesInActiveTab = controller.getPropertyValues({ getActiveTabControls: true, filterHiddenDisabled: true }); + expect(expectedFilteredHiddenDisabledPropertiesInActiveTab).to.eql(actualFilteredHiddenDisabledPropertiesInActiveTab); + + // getActiveTabControls: return all properties under selected tab/category + // filterHidden: filter controls having state "hidden" + const expectedFilteredHiddenPropertiesInActiveTab = { + string_error: "testing", + string_warning: "testing", + hide: true, + disable: true, + string_disabled: "testing", + string_condition_handling: "testing" + }; + const actualFilteredHiddenPropertiesInActiveTab = controller.getPropertyValues({ getActiveTabControls: true, filterHidden: true }); + expect(expectedFilteredHiddenPropertiesInActiveTab).to.eql(actualFilteredHiddenPropertiesInActiveTab); + + // getActiveTabControls: return all properties under selected tab/category + // filterDisabled: filter controls having state "disabled" + const expectedFilteredDisabledPropertiesInActiveTab = { + string_error: "testing", + string_warning: "testing", + hide: true, + string_hidden: "testing", + disable: true, + string_condition_handling: "testing" + }; + const actualFilteredDisabledPropertiesInActiveTab = controller.getPropertyValues({ getActiveTabControls: true, filterDisabled: true }); + expect(expectedFilteredDisabledPropertiesInActiveTab).to.eql(actualFilteredDisabledPropertiesInActiveTab); + + + // Verify getActiveTabControls: true returns all properties in nested subtabs as well + renderedObject = testUtils.flyoutEditorForm(tabParamDef); + controller = renderedObject.controller; + wrapper = renderedObject.wrapper; + + // Get all properties in active tab ("Tab Test" tab) + expectedAllPropertiesInActiveTab = { + hide: false, + disable: false, + fromValue: 2, + toValue: 1, + fields: [ + "Age", + "Drug" + ], + fruit: "apple", + other: "lemon", + readonly_double_subtabs: "If multiple subtabs are defined in a tearsheet, additional padding is required to avoid overlay.", + fromValue_summary: 2, + toValue_summary: 1, + fields_summary: [ + "Age", + "Drug" + ], + fruit_summary: "apple", + other_summary: "lemon", + openTearsheet: undefined + }; + actualAllPropertiesInActiveTab = controller.getPropertyValues({ getActiveTabControls: true }); + expect(expectedAllPropertiesInActiveTab).to.eql(actualAllPropertiesInActiveTab); + + }); }); describe("Properties Controller states", () => { diff --git a/canvas_modules/common-canvas/__tests__/test_resources/json/form-actions-test.json b/canvas_modules/common-canvas/__tests__/test_resources/json/form-actions-test.json index 277bce0ec6..12c5da53d6 100644 --- a/canvas_modules/common-canvas/__tests__/test_resources/json/form-actions-test.json +++ b/canvas_modules/common-canvas/__tests__/test_resources/json/form-actions-test.json @@ -459,6 +459,57 @@ } }, "conditions": [], + "groupMetadata":{ + "groups":[ + { + "name":"action-tests", + "type":"panels", + "label":{ + "default":"Actions" + }, + "subGroups":[ + { + "name":"increment-action-panel", + "actions":[ + "increment", + "decrement" + ], + "type":"actionPanel" + }, + { + "name":"number-control", + "parameters":[ + "number" + ], + "type":"controls" + } + ] + }, + { + "name":"summary-panel", + "type":"summaryPanel", + "label":{ + "default":"Summary Panel Actions" + }, + "subGroups":[ + { + "name":"dm-action-panel", + "actions":[ + "dm-update" + ], + "type":"actionPanel" + }, + { + "name":"summary-controls", + "parameters":[ + "fields" + ], + "type":"controls" + } + ] + } + ] + }, "resources": { "increment": "Increment", "decrement": "Decrement", diff --git a/canvas_modules/common-canvas/__tests__/test_resources/json/form-editstyle-test.json b/canvas_modules/common-canvas/__tests__/test_resources/json/form-editstyle-test.json index 24ca1158fa..3a03050c05 100644 --- a/canvas_modules/common-canvas/__tests__/test_resources/json/form-editstyle-test.json +++ b/canvas_modules/common-canvas/__tests__/test_resources/json/form-editstyle-test.json @@ -476,6 +476,25 @@ } } ], + "groupMetadata": { + "groups": [ + { + "name": "basic-settings", + "type": "panels", + "label": { + "default": "Settings" + }, + "subGroups": [ + { + "parameters": [ + "renamed_fields" + ], + "type": "columnSelection" + } + ] + } + ] + }, "resources": { "rename.label": "Rename Columns", "RenameFieldEntry.field": "Input name", diff --git a/canvas_modules/common-canvas/__tests__/test_resources/json/form-placement-test.json b/canvas_modules/common-canvas/__tests__/test_resources/json/form-placement-test.json index 93521ff0ae..48b35a3068 100644 --- a/canvas_modules/common-canvas/__tests__/test_resources/json/form-placement-test.json +++ b/canvas_modules/common-canvas/__tests__/test_resources/json/form-placement-test.json @@ -303,6 +303,20 @@ ] } }, + "groupMetadata": { + "groups": [ + { + "name": "settings", + "parameters": [ + "cols" + ], + "type": "columnSelection", + "label": { + "default": "Settings" + } + } + ] + }, "resources": { "select.label": "Select Columns", "mode.label": "Mode", diff --git a/canvas_modules/common-canvas/__tests__/test_resources/json/form-structure-test.json b/canvas_modules/common-canvas/__tests__/test_resources/json/form-structure-test.json index f5db0de237..8908e3a9e8 100644 --- a/canvas_modules/common-canvas/__tests__/test_resources/json/form-structure-test.json +++ b/canvas_modules/common-canvas/__tests__/test_resources/json/form-structure-test.json @@ -398,6 +398,20 @@ } } ], + "groupMetadata": { + "groups": [ + { + "name": "basic-settings", + "parameters": [ + "renamed_fields" + ], + "type": "columnSelection", + "label": { + "default": "Settings" + } + } + ] + }, "resources": { "rename.label": "Rename Columns", "field.label": "Input name", diff --git a/canvas_modules/common-canvas/__tests__/test_resources/json/form-structure2-test.json b/canvas_modules/common-canvas/__tests__/test_resources/json/form-structure2-test.json index f682f00ee3..0539fa2246 100644 --- a/canvas_modules/common-canvas/__tests__/test_resources/json/form-structure2-test.json +++ b/canvas_modules/common-canvas/__tests__/test_resources/json/form-structure2-test.json @@ -398,6 +398,20 @@ ] } }, + "groupMetadata": { + "groups": [ + { + "name": "basic-settings", + "parameters": [ + "keys" + ], + "type": "columnSelection", + "label": { + "default": "Settings" + } + } + ] + }, "resources": { "sort.label": "Sort", "sort.desc": "Sorts the data", diff --git a/canvas_modules/common-canvas/__tests__/test_resources/json/form-test-condition.json b/canvas_modules/common-canvas/__tests__/test_resources/json/form-test-condition.json index 5560459bb7..645c564330 100644 --- a/canvas_modules/common-canvas/__tests__/test_resources/json/form-test-condition.json +++ b/canvas_modules/common-canvas/__tests__/test_resources/json/form-test-condition.json @@ -188,6 +188,20 @@ } } ], + "groupMetadata": { + "groups": [ + { + "name": "basic-settings", + "parameters": [ + "int_param", + "exp_param" + ], + "label": { + "default": "Settings" + } + } + ] + }, "resources": { "exp_param_not_empty": "Expression cannot be empty: Resource" } diff --git a/canvas_modules/common-canvas/__tests__/test_resources/json/form-test.json b/canvas_modules/common-canvas/__tests__/test_resources/json/form-test.json index 116e46d5b8..603d957150 100644 --- a/canvas_modules/common-canvas/__tests__/test_resources/json/form-test.json +++ b/canvas_modules/common-canvas/__tests__/test_resources/json/form-test.json @@ -449,6 +449,65 @@ } ], "data": {}, + "groupMetadata":{ + "groups":[ + { + "name":"fields-settings", + "type":"panels", + "label":{ + "default":"Field Settings label: default", + "resource_key":"column-settings.label" + }, + "subGroups":[ + { + "name":"field-allocation", + "parameters":[ + "target", + "inputs" + ], + "type":"columnSelection" + } + ] + }, + { + "name":"settings", + "parameters":[ + "enum_param" + ], + "label":{ + "default":"Parameter Settings label: default" + }, + "subGroups":[ + { + "name":"enum-settings", + "type":"panelSelector", + "dependsOn":"enum_param", + "subGroups":[ + { + "name":"Include", + "parameters":[ + "int_param" + ] + }, + { + "name":"Discard", + "parameters":[ + "double_param" + ] + } + ] + }, + { + "name":"boolean-settings", + "parameters":[ + "boolean_param", + "str_param" + ] + } + ] + } + ] + }, "resources": { "target.label": "Target label: resource", "target.desc": "Target field description: resource", diff --git a/canvas_modules/common-canvas/src/common-properties/form/Form.js b/canvas_modules/common-canvas/src/common-properties/form/Form.js index 826d1746f2..97c1cf2167 100644 --- a/canvas_modules/common-canvas/src/common-properties/form/Form.js +++ b/canvas_modules/common-canvas/src/common-properties/form/Form.js @@ -24,7 +24,7 @@ import { Size } from "../constants/form-constants"; import { CONTAINER_TYPE } from "../constants/constants"; export default class Form { - constructor(componentId, label, labelEditable, help, editorSize, pixelWidth, uiItems, buttons, data, conditions, resources, icon, heading) { + constructor(componentId, label, labelEditable, help, editorSize, pixelWidth, uiItems, buttons, data, conditions, groupMetadata, resources, icon, heading) { this.componentId = componentId; this.label = label; this.labelEditable = labelEditable; @@ -35,6 +35,7 @@ export default class Form { this.buttons = buttons; this.data = data; this.conditions = conditions; + this.groupMetadata = groupMetadata; this.resources = resources; this.icon = icon; this.heading = heading; @@ -77,6 +78,7 @@ export default class Form { _defaultButtons(), data, translateMessages(conditions, l10nProvider), + propDef.groupMetadata, resources, propDef.icon, l10nProvider.l10nResource(propDef.heading) diff --git a/canvas_modules/common-canvas/src/common-properties/properties-controller.js b/canvas_modules/common-canvas/src/common-properties/properties-controller.js index 8b0190d4af..02507f7d4b 100644 --- a/canvas_modules/common-canvas/src/common-properties/properties-controller.js +++ b/canvas_modules/common-canvas/src/common-properties/properties-controller.js @@ -227,6 +227,42 @@ export default class PropertiesController { return this.appData; } + getActiveTabPropertyValues() { + const activeTab = this.propertiesStore.getActiveTab(); + const allPropertyValues = this.propertiesStore.getPropertyValues(); + const activeTabPropertyValues = {}; + let activeTabPropertyIds = []; + + for (const group of this.form.groupMetadata.groups) { + if (group.name === activeTab) { + activeTabPropertyIds = this.getGroupProperties(group); + break; + } + } + + activeTabPropertyIds.forEach((propertyId) => { + activeTabPropertyValues[propertyId] = allPropertyValues[propertyId]; + }); + + return activeTabPropertyValues; + } + + // Recursively get all properties under given uiGroup + getGroupProperties(uiGroup) { + const parameters = typeof uiGroup.parameterNames() !== "undefined" ? uiGroup.parameterNames() : []; + const actions = typeof uiGroup.actionIds() !== "undefined" ? uiGroup.actionIds() : []; + let groupProperties = [...parameters, ...actions]; + + if (has(uiGroup, "subGroups") && uiGroup.subGroups) { + for (const subGrp of uiGroup.subGroups) { + const subGroupProperties = this.getGroupProperties(subGrp); + groupProperties = groupProperties.concat(subGroupProperties); + } + } + + return groupProperties; + } + _parseUiConditions() { this.visibleDefinitions = { controls: {}, refs: {} }; this.enabledDefinitions = { controls: {}, refs: {} }; @@ -1166,9 +1202,15 @@ export default class PropertiesController { * filterHidden: true - filter out values from controls having state "hidden" * filterDisabled: true - filter out values from controls having state "disabled" * filterHiddenControls: true - filter out values from controls having type "hidden" + * getActiveTabControls: true - return all properties under selected tab/category */ getPropertyValues(options) { - const propertyValues = this.propertiesStore.getPropertyValues(); + // All property values + let propertyValues = this.propertiesStore.getPropertyValues(); + + if (options && options.getActiveTabControls) { + propertyValues = this.getActiveTabPropertyValues(); + } let returnValues = propertyValues; if (options && (options.filterHiddenDisabled || options.filterHidden || options.filterDisabled || options.filterHiddenControls || options.valueFilters)) { const filteredValues = {};