From c70e4100502051752dcc3e2730757b2e87ba7254 Mon Sep 17 00:00:00 2001 From: "Thomas Lefebvre (thle)" Date: Mon, 2 Jan 2023 07:03:37 +0000 Subject: [PATCH] [FIX] web: correct type of defaultPage prop Steps to reproduce: - go to "Link Tracker" app; - go to "Campaigns" tab (UTMs); - create a new campaign; - leave and return in this record. Issue: A traceback appears. Error message: `Invalid props for component 'Notebook': 'defaultPage' is not a string` Cause: The `defaultPage` prop must be a string. When the record is new, it will be `undefined`, so it will pass props validation because this prop is optional. But when we try to calculate it and it does not return a value, the `defaultPage` is null. The variable is therefore declared but it is empty (and therefore not a string). `null` value does not pass the props validation test. The problem appears in the "Campaigns" tab because there is a notebook without content. Solution: Test if it is possible to have a value. If not, set the `defaultPage` prop to be `undefined`. opw-3109327 closes odoo/odoo#109533 X-original-commit: 402b1a822c3983af33aa1d3a3c7e93d8836c60d8 Signed-off-by: Dardenne Florent (dafl) --- .../static/src/views/form/form_controller.js | 4 +- .../tests/views/form/form_view_tests.js | 37 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/views/form/form_controller.js b/addons/web/static/src/views/form/form_controller.js index 41a1d43b75a..d467b75741f 100644 --- a/addons/web/static/src/views/form/form_controller.js +++ b/addons/web/static/src/views/form/form_controller.js @@ -187,7 +187,9 @@ export class FormController extends Component { this.fieldsToTranslate = useState(fieldsToTranslate || {}); const activeNotebookPages = { ...state.activeNotebookPages }; this.onNotebookPageChange = (notebookId, page) => { - activeNotebookPages[notebookId] = page; + if (page) { + activeNotebookPages[notebookId] = page; + } }; useSetupView({ diff --git a/addons/web/static/tests/views/form/form_view_tests.js b/addons/web/static/tests/views/form/form_view_tests.js index 9329c3a031d..0414cbe1ac1 100644 --- a/addons/web/static/tests/views/form/form_view_tests.js +++ b/addons/web/static/tests/views/form/form_view_tests.js @@ -12976,4 +12976,41 @@ QUnit.module("Views", (hooks) => { assert.strictEqual(target.querySelector(".o_form_nosheet").innerHTML, "
"); assert.verifySteps(["warn", "warn", "warn", "warn"]); }); + + QUnit.test("reload form view with an empty notebook", async function (assert) { + assert.expect(1); + + serverData.views = { + "partner,false,form": ` +
+ + + + +
`, + "partner,false,list": '', + "partner,false,search": "", + }; + + serverData.actions = { + 1: { + id: 1, + name: "Partner", + res_model: "partner", + type: "ir.actions.act_window", + views: [ + [false, "list"], + [false, "form"], + ], + }, + }; + + const target = getFixture(); + const webClient = await createWebClient({ serverData }); + await doAction(webClient, 1); + await click(target.querySelector(".o_data_row .o_data_cell")); + await click(target.querySelector(".o_back_button")); + await click(target.querySelector(".o_data_row .o_data_cell")); + assert.containsOnce(target, ".o_form_view"); + }); });