[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) <aab@odoo.com>
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -421,7 +421,7 @@
|
||||
</button>
|
||||
<button type="button"
|
||||
class="btn btn-secondary o_add_condition"
|
||||
t-on-click="_addDefaultCondition"
|
||||
t-on-click="_addNewCondition"
|
||||
>
|
||||
<i class="fa fa-plus-circle"/>
|
||||
<t>Add a condition</t>
|
||||
|
||||
@@ -70,6 +70,48 @@ odoo.define('web.filter_menu_generator_tests', function (require) {
|
||||
cfi.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('custom OR filter presets new condition from preceding', async function (assert) {
|
||||
assert.expect(4);
|
||||
|
||||
const searchModel = new ActionModel();
|
||||
const cfi = await createComponent(CustomFilterItem, {
|
||||
props: {
|
||||
fields: this.fields,
|
||||
},
|
||||
env: { searchModel },
|
||||
});
|
||||
|
||||
// Open custom filter form
|
||||
await cpHelpers.toggleAddCustomFilter(cfi);
|
||||
|
||||
// Retrieve second selectable values for field and operator dropdowns
|
||||
const fieldSecondValue = cfi.el.querySelector('.o_generator_menu_field option:nth-of-type(2)').value;
|
||||
const operatorSecondValue = cfi.el.querySelector('.o_generator_menu_operator option:nth-of-type(2)').value;
|
||||
|
||||
// Check if they really exist…
|
||||
assert.ok(!!fieldSecondValue);
|
||||
assert.ok(!!operatorSecondValue);
|
||||
|
||||
// Add first filter condition
|
||||
await testUtils.fields.editSelect(cfi.el.querySelector('.o_generator_menu_field'), fieldSecondValue);
|
||||
await testUtils.fields.editSelect(cfi.el.querySelector('.o_generator_menu_operator'), operatorSecondValue);
|
||||
|
||||
// Add a second conditon on the filter being created
|
||||
await cpHelpers.addCondition(cfi);
|
||||
|
||||
// Check the defaults for field and operator dropdowns
|
||||
assert.strictEqual(
|
||||
cfi.el.querySelector('.o_filter_condition:nth-of-type(2) .o_generator_menu_field').value,
|
||||
fieldSecondValue
|
||||
);
|
||||
assert.strictEqual(
|
||||
cfi.el.querySelector('.o_filter_condition:nth-of-type(2) .o_generator_menu_operator').value,
|
||||
operatorSecondValue
|
||||
);
|
||||
|
||||
cfi.destroy();
|
||||
});
|
||||
|
||||
QUnit.test('selection field: default and updated value', async function (assert) {
|
||||
assert.expect(4);
|
||||
|
||||
|
||||
@@ -143,6 +143,7 @@ odoo.define('web.test_utils', async function (require) {
|
||||
toggleFilterMenu: testUtilsControlPanel.toggleFilterMenu,
|
||||
toggleAddCustomFilter: testUtilsControlPanel.toggleAddCustomFilter,
|
||||
applyFilter: testUtilsControlPanel.applyFilter,
|
||||
addCondition: testUtilsControlPanel.addCondition,
|
||||
// GroupByMenu interactions
|
||||
toggleGroupByMenu: testUtilsControlPanel.toggleGroupByMenu,
|
||||
toggleAddCustomGroup: testUtilsControlPanel.toggleAddCustomGroup,
|
||||
|
||||
@@ -104,6 +104,14 @@ odoo.define('web.test_utils_control_panel', function (require) {
|
||||
await click(getNode(el).querySelector(`div.o_add_filter_menu > button.o_apply_filter`));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {EventTarget} el
|
||||
* @returns {Promise}
|
||||
*/
|
||||
async function addCondition(el) {
|
||||
await click(getNode(el).querySelector(`div.o_add_filter_menu > button.o_add_condition`));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {EventTarget} el
|
||||
* @returns {Promise}
|
||||
@@ -319,6 +327,7 @@ odoo.define('web.test_utils_control_panel', function (require) {
|
||||
toggleFilterMenu,
|
||||
toggleAddCustomFilter,
|
||||
applyFilter,
|
||||
addCondition,
|
||||
// GroupByMenu interactions
|
||||
toggleGroupByMenu,
|
||||
toggleAddCustomGroup,
|
||||
|
||||
Reference in New Issue
Block a user