From 2736d832bd88ec5bf1b82be13068ab15420c08d6 Mon Sep 17 00:00:00 2001 From: Pierre Paridans Date: Mon, 12 Sep 2022 08:25:42 +0000 Subject: [PATCH] [FIX] web: Layout's display props could be dynamic Before this commit, if the Layout's `display` props is a dynamic value coming from the parent Component (ie. a getter on the component that controls which parts of the ControlPanel should be displayed), this value isn't applied after the first initialization. This commit fixes it by extracting the `display` logic applied in the constructor to a getter (moving from initialization only to once called). Part-of: odoo/odoo#99483 --- addons/web/static/src/search/layout.js | 22 +++++---- addons/web/static/tests/views/layout_tests.js | 46 ++++++++++++++++++- 2 files changed, 59 insertions(+), 9 deletions(-) diff --git a/addons/web/static/src/search/layout.js b/addons/web/static/src/search/layout.js index 1ce75ab42b9..9b0aa309162 100644 --- a/addons/web/static/src/search/layout.js +++ b/addons/web/static/src/search/layout.js @@ -15,14 +15,6 @@ export function extractLayoutComponents(params) { export class Layout extends Component { setup() { this.components = extractLayoutComponents(this.env.config); - const display = this.props.display; - if (display.controlPanel && this.env.inDialog) { - display.controlPanel = Object.assign({}, display.controlPanel, { - "top-left": false, - "bottom-left-buttons": false, - }); - } - this.display = display; } get controlPanelSlots() { const slots = { ...this.props.slots }; @@ -31,6 +23,20 @@ export class Layout extends Component { delete slots.default; return slots; } + get display() { + const { controlPanel } = this.props.display; + if (!controlPanel || !this.env.inDialog) { + return this.props.display; + } + return { + ...this.props.display, + controlPanel: { + ...controlPanel, + "top-left": false, + "bottom-left-buttons": false, + }, + }; + } } Layout.template = "web.Layout"; diff --git a/addons/web/static/tests/views/layout_tests.js b/addons/web/static/tests/views/layout_tests.js index 3578b21279c..08859cca677 100644 --- a/addons/web/static/tests/views/layout_tests.js +++ b/addons/web/static/tests/views/layout_tests.js @@ -1,6 +1,6 @@ /** @odoo-module **/ -import { getFixture, mount } from "@web/../tests/helpers/utils"; +import { getFixture, mount, nextTick } from "@web/../tests/helpers/utils"; import { makeWithSearch, setupControlPanelServiceRegistry } from "@web/../tests/search/helpers"; import { dialogService } from "@web/core/dialog/dialog_service"; import { registry } from "@web/core/registry"; @@ -255,4 +255,48 @@ QUnit.module("Views", (hooks) => { assert.notOk(target.querySelector(".o_toy_banner").closest(".o_content")); assert.ok(target.querySelector(".o_toy_content").closest(".o_content")); }); + + QUnit.test("Simple rendering: with dynamically displayed search", async (assert) => { + let displayControlPanelTopRight = true; + class ToyComponent extends Component { + get display() { + return { + ...this.props.display, + controlPanel: { + ...this.props.display.controlPanel, + "top-right": displayControlPanelTopRight, + }, + }; + } + } + ToyComponent.template = xml` + + +