From cd8686f5f81aa0e2905a1452081db6e898bc0610 Mon Sep 17 00:00:00 2001 From: Bruno Boi Date: Wed, 2 Sep 2020 07:49:17 +0000 Subject: [PATCH] [IMP] web: default custom OR filter to previous When one constucts a custom filter in the search view and clicks on the "ADD A CONDITION" button, the new condition dropdowns always start with the top of the lists. This commit will instead default a new condition to the same field and operator as the previous one. Presetting the dropdowns used in the previous condition is a better guess for what a user tries to filter than starting the dropdowns each time at the top of their lists. closes odoo/odoo#56918 Taskid: 2222545 Signed-off-by: Aaron Bohy (aab) --- .../js/control_panel/custom_filter_item.js | 25 ++++++----- addons/web/static/src/xml/base.xml | 2 +- .../control_panel/custom_filter_item_tests.js | 42 +++++++++++++++++++ addons/web/static/tests/helpers/test_utils.js | 1 + .../tests/helpers/test_utils_control_panel.js | 9 ++++ 5 files changed, 67 insertions(+), 12 deletions(-) diff --git a/addons/web/static/src/js/control_panel/custom_filter_item.js b/addons/web/static/src/js/control_panel/custom_filter_item.js index 98080f6a418..b2d15746bb8 100644 --- a/addons/web/static/src/js/control_panel/custom_filter_item.js +++ b/addons/web/static/src/js/control_panel/custom_filter_item.js @@ -61,8 +61,8 @@ odoo.define('web.CustomFilterItem', function (require) { this.OPERATORS = FIELD_OPERATORS; this.FIELD_TYPES = FIELD_TYPES; - // Add default empty condition - this._addDefaultCondition(); + // Add first condition + this._addNewCondition(); } //--------------------------------------------------------------------- @@ -70,17 +70,20 @@ odoo.define('web.CustomFilterItem', function (require) { //--------------------------------------------------------------------- /** - * Populate the conditions list with a default condition having as properties: - * - the first available field - * - the first available operator + * Populate the conditions list with a new condition having as properties: + * - the last condition or the first available field + * - the last condition or the first available operator * - a null or empty array value * @private */ - _addDefaultCondition() { - const condition = { - field: 0, - operator: 0, - }; + _addNewCondition() { + const lastCondition = [...this.state.conditions].pop(); + const condition = lastCondition + ? Object.assign({}, lastCondition) + : { + field: 0, + operator: 0, + }; this._setDefaultValue(condition); this.state.conditions.push(condition); } @@ -185,7 +188,7 @@ odoo.define('web.CustomFilterItem', function (require) { // Reset state this.state.open = false; this.state.conditions = []; - this._addDefaultCondition(); + this._addNewCondition(); } /** diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml index 25426728326..25099d03fa8 100644 --- a/addons/web/static/src/xml/base.xml +++ b/addons/web/static/src/xml/base.xml @@ -421,7 +421,7 @@