From 4dc211dff82a60784aab4d3ba6407da3c53d9883 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Mon, 23 Oct 2023 07:14:17 +0000 Subject: [PATCH] [FIX] web: display filters directly in search bar In views with a searchbar, we want the filters to be displayed directly when they are activated, without waiting for the view to be reloaded. This is to provide a direct feedback to the user. Before this commit, this didn't work in grouped kanban view with progressbar. The regression has been introduced by [1] which moves the progressbar logic out of the model. With [1], the rendering of the KanbanController waits for the progressbar data to be loaded in onWillUpdateProps, thus delaying the rendering coming from the WithSearch when a filter is toggled. This commit applies the same logic as for the model: we do not wait for the loading promise in onWillUpdateProps. That way, the rendering coming from WithSearch is synchronous, but a reload is initiated and another rendering will be scheduled by the Controller itself when the data will be loaded. This commit also adds a test for the model case, as it appears that this wasn't tested. [1] 58ca40b03215ef4c6c575267494dc8bccc30a033 closes odoo/odoo#139967 X-original-commit: 47cf6e326f5a795984bac2138b169503c3dd099c Signed-off-by: Mathieu Duckerts-Antoine (dam) --- .../src/views/kanban/progress_bar_hook.js | 2 +- .../tests/views/kanban/kanban_view_tests.js | 87 ++++++++++++++++++- 2 files changed, 86 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/views/kanban/progress_bar_hook.js b/addons/web/static/src/views/kanban/progress_bar_hook.js index b4ffb2ddd0e..a6d155cc876 100644 --- a/addons/web/static/src/views/kanban/progress_bar_hook.js +++ b/addons/web/static/src/views/kanban/progress_bar_hook.js @@ -338,7 +338,7 @@ export function useProgressBar(progressAttributes, model, aggregateFields, activ return progressBarState.loadProgressBar(component.props); }); onWillUpdateProps((nextProps) => { - return progressBarState.loadProgressBar(nextProps); + progressBarState.loadProgressBar(nextProps); }); return reactive(progressBarState); diff --git a/addons/web/static/tests/views/kanban/kanban_view_tests.js b/addons/web/static/tests/views/kanban/kanban_view_tests.js index 095e71a9dae..3dcb56a9022 100644 --- a/addons/web/static/tests/views/kanban/kanban_view_tests.js +++ b/addons/web/static/tests/views/kanban/kanban_view_tests.js @@ -26,6 +26,7 @@ import { pagerNext, toggleSearchBarMenu, validateSearch, + toggleMenuItem, } from "@web/../tests/search/helpers"; import { makeView, setupViewRegistries } from "@web/../tests/views/helpers"; import { createWebClient, doAction } from "@web/../tests/webclient/helpers"; @@ -10904,7 +10905,7 @@ QUnit.module("Views", (hooks) => { QUnit.test( "keyboard navigation on kanban when the focus is on a link that " + - "has an action and the kanban has no oe_kanban_global_... class", + "has an action and the kanban has no oe_kanban_global_... class", async (assert) => { await makeView({ type: "kanban", @@ -13534,7 +13535,7 @@ QUnit.module("Views", (hooks) => { MyField.template = xml``; registry.category("fields").add("my_field", { component: MyField }); - serverData.models.partner.onchanges = { product_id: () => {} }; + serverData.models.partner.onchanges = { product_id: () => { } }; await makeView({ type: "kanban", @@ -13883,6 +13884,88 @@ QUnit.module("Views", (hooks) => { } ); + + QUnit.test("searchbar filters are displayed directly", async (assert) => { + let def; + await makeView({ + type: "kanban", + resModel: "partner", + serverData, + arch: ` + + + + +
+
+
+
`, + searchViewArch: ` + + + `, + async mockRPC(route, args) { + if (args.method === "web_search_read") { + await def; + } + }, + }); + + assert.deepEqual(getFacetTexts(target), []); + + // toggle a filter, and slow down the web_search_read rpc + def = makeDeferred(); + await toggleSearchBarMenu(target); + await toggleMenuItem(target, "Some Filter"); + assert.deepEqual(getFacetTexts(target), ["Some Filter"]); + + def.resolve(); + await nextTick(); + assert.deepEqual(getFacetTexts(target), ["Some Filter"]); + }); + + QUnit.test("searchbar filters are displayed directly (with progressbar)", async (assert) => { + let def; + await makeView({ + type: "kanban", + resModel: "partner", + serverData, + arch: ` + + + + + +
+
+
+
`, + groupBy: ["int_field"], + searchViewArch: ` + + + `, + async mockRPC(route, args) { + if (args.method === "read_progress_bar") { + await def; + } + }, + }); + + assert.deepEqual(getFacetTexts(target), []); + + // toggle a filter, and slow down the read_progress_bar rpc + def = makeDeferred(); + await toggleSearchBarMenu(target); + await toggleMenuItem(target, "Some Filter"); + + assert.deepEqual(getFacetTexts(target), ["Some Filter"]); + + def.resolve(); + await nextTick(); + assert.deepEqual(getFacetTexts(target), ["Some Filter"]); + }); + QUnit.test("group by properties and drag and drop", async (assert) => { assert.expect(10);