From 5b75ee47aabd744f6203f0db7bfacde6eff2a6e0 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Mon, 4 Dec 2023 14:36:09 +0100 Subject: [PATCH] [FIX] board: remove Add to my dashboard in form views Since the milk redesign, and the move of the "Add to my dashboard" action from the search view to the CogMenu (next to breadcrumbs), the action was available in all views, especially in form views, which isn't what we want. Adding a form view to the dashboard results in an empty form view (in creation) being displayed in the dashboard. Before milk, the form view naturally didn't allow to add to dashboard as it has no search view. This commit checks the view type to determine if the action must be available or not. Task 3552870 closes odoo/odoo#145534 X-original-commit: d01c75938948bd0e365d7ca1e4f518ce5b563f5c Signed-off-by: Jorge Pinna Puissant (jpp) --- .../static/src/add_to_board/add_to_board.js | 5 ++- .../static/tests/add_to_dashboard_tests.js | 34 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/addons/board/static/src/add_to_board/add_to_board.js b/addons/board/static/src/add_to_board/add_to_board.js index f0bc14ad068..58bfd632c0a 100644 --- a/addons/board/static/src/add_to_board/add_to_board.js +++ b/addons/board/static/src/add_to_board/add_to_board.js @@ -98,7 +98,10 @@ AddToBoard.components = { Dropdown }; export const addToBoardItem = { Component: AddToBoard, groupNumber: 20, - isDisplayed: ({ config }) => config.actionType === "ir.actions.act_window" && config.actionId, + isDisplayed: ({ config }) => { + const { actionType, actionId, viewType } = config; + return actionType === "ir.actions.act_window" && actionId && viewType !== "form"; + }, }; cogMenuRegistry.add("add-to-board", addToBoardItem, { sequence: 10 }); diff --git a/addons/board/static/tests/add_to_dashboard_tests.js b/addons/board/static/tests/add_to_dashboard_tests.js index 51b8348f992..24694be3b40 100644 --- a/addons/board/static/tests/add_to_dashboard_tests.js +++ b/addons/board/static/tests/add_to_dashboard_tests.js @@ -514,4 +514,38 @@ QUnit.module("Board", (hooks) => { await testUtils.fields.editInput(input, "Pipeline"); await triggerEvent(input, null, "keydown", { key: "Enter" }); }); + + QUnit.test("Add to my dashboard is not available in form views", async function (assert) { + serverData.views = { + "partner,false,list": '', + "partner,false,form": '
', + "partner,false,search": "", + }; + + const webClient = await createWebClient({ serverData }); + await doAction(webClient, { + id: 1, + res_model: "partner", + type: "ir.actions.act_window", + context: { fire: "on the bayou" }, + views: [ + [false, "list"], + [false, "form"], + ], + }); + + assert.containsOnce(target, ".o_list_view", "should display the list view"); + + // sanity check + await click(target, ".o_cp_action_menus .dropdown-toggle"); + assert.containsOnce(target, ".o_cp_action_menus .dropdown-menu .o_add_to_board"); + + // open form view + await click(target.querySelector(".o_data_cell")); + assert.containsOnce(target, ".o_form_view"); + + await click(target, ".o_cp_action_menus .dropdown-toggle"); + assert.containsOnce(target, ".o_cp_action_menus .dropdown-menu"); + assert.containsNone(target, ".o_cp_action_menus .dropdown-menu .o_add_to_board"); + }); });