From 2aca56f0f089be02ee964bf713876004e90ba32b Mon Sep 17 00:00:00 2001 From: "Francois (fge)" Date: Thu, 27 May 2021 10:55:30 +0200 Subject: [PATCH] [FIX] web: doAction supports controllerState passed in option In legacy, doAction can be passed the `controllerState` key, which contains `searchModel` and `searchPanel`, that an AbstractController can export. This commit re-implements this in the action service. --- .../src/webclient/actions/action_service.js | 8 +++++++ .../webclient/actions/window_action_tests.js | 21 ++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/webclient/actions/action_service.js b/addons/web/static/src/webclient/actions/action_service.js index 9e9dea88eb7..f0697f6b070 100644 --- a/addons/web/static/src/webclient/actions/action_service.js +++ b/addons/web/static/src/webclient/actions/action_service.js @@ -670,6 +670,14 @@ function makeActionManager(env) { if (options.resId) { viewOptions.recordId = options.resId; } + if (options.controllerState) { + if (options.controllerState.searchModel) { + viewOptions.searchModel = options.controllerState.searchModel; + } + if (options.controllerState.searchPanel) { + viewOptions.searchPanel = options.controllerState.searchPanel; + } + } const controller = { jsId: `controller_${++id}`, Component: view, diff --git a/addons/web/static/tests/webclient/actions/window_action_tests.js b/addons/web/static/tests/webclient/actions/window_action_tests.js index 968dd57ebac..797a39bf66f 100644 --- a/addons/web/static/tests/webclient/actions/window_action_tests.js +++ b/addons/web/static/tests/webclient/actions/window_action_tests.js @@ -10,7 +10,6 @@ import FormView from "web.FormView"; import ListController from "web.ListController"; import testUtils from "web.test_utils"; import legacyViewRegistry from "web.view_registry"; -import { clearRegistryWithCleanup } from "../../helpers/mock_env"; import { click, legacyExtraNextTick, nextTick, patchWithCleanup } from "../../helpers/utils"; import { createWebClient, doAction, getActionManagerServerData, loadState } from "./../helpers"; @@ -2275,4 +2274,24 @@ QUnit.module("ActionManager", (hooks) => { "read_group", // read_group at reload after switch view ]); }); + + QUnit.test( + "doAction supports being passed controlletState (searchModel)", + async function (assert) { + assert.expect(1); + const mockRPC = async (route, args) => { + if (route === "/web/dataset/search_read") { + assert.deepEqual(args.domain, [["id", "=", 99]]); + } + }; + + const webClient = await createWebClient({ serverData, mockRPC }); + await doAction(webClient, 1, { + controllerState: { + searchModel: + '{"ControlPanelModelExtension":{"filters":{"1":{"type":"field","description":"Foo","fieldName":"foo","fieldType":"char","groupId":1,"id":1},"2":{"description":"ID is \\"99\\"","domain":"[[\\"id\\",\\"=\\",99]]","type":"filter","groupId":3,"groupNumber":2,"id":2}},"query":[{"groupId":3,"filterId":2}]}}', + }, + }); + } + ); });