From b241f7e50616073e342150756d46f435151bb391 Mon Sep 17 00:00:00 2001 From: Mathieu Duckerts-Antoine Date: Wed, 5 Jan 2022 09:34:11 +0000 Subject: [PATCH] [FIX] web: visual separation of search items Since the refactoring of the views aeb8e49972f871b0c9b07c507987ee77cf5e8abbd, the filters and date filters, the groupbys and date groupbys are now always separated visually even if no separator/group tag has been set in the search arch. We restablish the previous behavior that only seperates them when a separator/group is set. closes odoo/odoo#82418 X-original-commit: e281bd0850e935ce0d97226366114da4f5406c4d Signed-off-by: Samuel Degueldre --- .../static/src/search/search_arch_parser.js | 16 ++++- .../static/tests/search/search_model_tests.js | 60 +++++++++++++++++++ 2 files changed, 73 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/search/search_arch_parser.js b/addons/web/static/src/search/search_arch_parser.js index 4414da11c8a..4556c9283ff 100644 --- a/addons/web/static/src/search/search_arch_parser.js +++ b/addons/web/static/src/search/search_arch_parser.js @@ -25,6 +25,16 @@ const getContextGroubBy = (context) => { } }; +function reduceType(type) { + if (type === "dateFilter") { + return "filter"; + } + if (type === "dateGroupBy") { + return "groupBy"; + } + return type; +} + export class SearchArchParser extends XMLParser { constructor(searchViewDescription, searchDefaults = {}, searchPanelDefaults = {}) { super(); @@ -86,7 +96,7 @@ export class SearchArchParser extends XMLParser { pushGroup(tag = null) { if (this.currentGroup.length) { - if (this.currentTag && ["groupBy", "dateGroupBy"].includes(this.currentTag)) { + if (this.currentTag === "groupBy") { this.pregroupOfGroupBys.push(...this.currentGroup); } else { this.preSearchItems.push(this.currentGroup); @@ -189,8 +199,8 @@ export class SearchArchParser extends XMLParser { preSearchItem.context = context; } } - if (preSearchItem.type !== this.currentTag) { - this.pushGroup(preSearchItem.type); + if (reduceType(preSearchItem.type) !== this.currentTag) { + this.pushGroup(reduceType(preSearchItem.type)); } if (preSearchItem.type === "filter") { if (node.hasAttribute("date")) { diff --git a/addons/web/static/tests/search/search_model_tests.js b/addons/web/static/tests/search/search_model_tests.js index abe76fb90a8..92333c830b4 100644 --- a/addons/web/static/tests/search/search_model_tests.js +++ b/addons/web/static/tests/search/search_model_tests.js @@ -530,6 +530,66 @@ QUnit.module("Search", (hooks) => { ]); }); + QUnit.test("parsing a filter and a dateFilter", async function (assert) { + assert.expect(1); + const model = await makeSearchModel({ + serverData, + searchViewArch: ` + + + + + `, + }); + const groupNumbers = model.getSearchItems(() => true).map((i) => i.groupNumber); + assert.deepEqual(groupNumbers, [1, 1]); + }); + + QUnit.test("parsing a groupBy and a dateGroupBy", async function (assert) { + assert.expect(1); + const model = await makeSearchModel({ + serverData, + searchViewArch: ` + + + + + `, + }); + const groupNumbers = model.getSearchItems(() => true).map((i) => i.groupNumber); + assert.deepEqual(groupNumbers, [1, 1]); + }); + + QUnit.test("parsing a filter and a groupBy", async function (assert) { + assert.expect(1); + const model = await makeSearchModel({ + serverData, + searchViewArch: ` + + + + + `, + }); + const groupNumbers = model.getSearchItems(() => true).map((i) => i.groupNumber); + assert.deepEqual(groupNumbers, [1, 2]); + }); + + QUnit.test("parsing a groupBy and a filter", async function (assert) { + assert.expect(1); + const model = await makeSearchModel({ + serverData, + searchViewArch: ` + + + + + `, + }); + const groupNumbers = model.getSearchItems(() => true).map((i) => i.groupNumber); + assert.deepEqual(groupNumbers, [2, 1]); + }); + QUnit.test("process search default group by", async function (assert) { assert.expect(1); const model = await makeSearchModel({