From 57a02f0a146ffefb7ec1ec3be291afc26b112cb5 Mon Sep 17 00:00:00 2001 From: Samuel Degueldre Date: Wed, 1 Dec 2021 10:53:30 +0000 Subject: [PATCH] [REF] web: remove dropdown-item-selected event MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In owl 2, the t-on directive is no longer supported on components. The way to handle events on components is to give them a callback as a prop. This already works in owl 1, so this commit prepares the code for an easier migration in the future by removing the "dropdown-item-selected" event and converting the code that was using it to use the new paradigm. closes odoo/odoo#80684 Related: odoo/enterprise#22722 Signed-off-by: Géry Debongnie --- .../web/static/src/core/debug/debug_menu.xml | 2 +- .../core/debug/profiling/profiling_item.xml | 2 +- .../web/static/src/core/dropdown/dropdown.js | 38 +++++------ .../web/static/src/core/dropdown/dropdown.xml | 5 +- .../static/src/core/dropdown/dropdown_item.js | 55 +++++++++++----- .../src/core/dropdown/dropdown_item.xml | 1 + .../core/dropdown/dropdown_navigation_hook.js | 10 +-- .../js/control_panel/comparison_menu.js | 5 +- .../legacy/js/control_panel/favorite_menu.js | 7 +-- .../legacy/js/control_panel/filter_menu.js | 8 +-- .../legacy/js/control_panel/groupby_menu.js | 9 ++- addons/web/static/src/legacy/xml/pivot.xml | 10 +-- .../search/comparison_menu/comparison_menu.js | 5 +- .../comparison_menu/comparison_menu.xml | 4 +- .../src/search/favorite_menu/favorite_menu.js | 5 +- .../search/favorite_menu/favorite_menu.xml | 6 +- .../src/search/filter_menu/filter_menu.js | 7 ++- .../src/search/filter_menu/filter_menu.xml | 6 +- .../src/search/group_by_menu/group_by_menu.js | 7 ++- .../search/group_by_menu/group_by_menu.xml | 5 +- .../web/static/src/views/graph/graph_view.js | 6 +- .../web/static/src/views/graph/graph_view.xml | 2 +- .../src/views/pivot/pivot_group_by_menu.js | 14 +++-- .../static/src/views/pivot/pivot_renderer.js | 6 +- .../static/src/views/pivot/pivot_renderer.xml | 2 +- .../web/static/src/views/pivot/pivot_view.js | 7 ++- .../web/static/src/views/pivot/pivot_view.xml | 2 +- addons/web/static/src/views/view.xml | 2 +- .../web/static/src/webclient/navbar/navbar.js | 34 ++++------ .../static/src/webclient/navbar/navbar.xml | 33 +++++----- .../src/webclient/user_menu/user_menu.js | 22 +------ .../src/webclient/user_menu/user_menu.xml | 7 ++- .../web/static/tests/core/dropdown_tests.js | 63 ++++++------------- 33 files changed, 180 insertions(+), 217 deletions(-) diff --git a/addons/web/static/src/core/debug/debug_menu.xml b/addons/web/static/src/core/debug/debug_menu.xml index fd69e987256..a65e02ea73d 100644 --- a/addons/web/static/src/core/debug/debug_menu.xml +++ b/addons/web/static/src/core/debug/debug_menu.xml @@ -12,7 +12,7 @@ diff --git a/addons/web/static/src/core/debug/profiling/profiling_item.xml b/addons/web/static/src/core/debug/profiling/profiling_item.xml index 940f18131cc..d8c64358da1 100644 --- a/addons/web/static/src/core/debug/profiling/profiling_item.xml +++ b/addons/web/static/src/core/debug/profiling/profiling_item.xml @@ -2,7 +2,7 @@ - +
diff --git a/addons/web/static/src/core/dropdown/dropdown.js b/addons/web/static/src/core/dropdown/dropdown.js index 27cfd76efea..455006d2e04 100644 --- a/addons/web/static/src/core/dropdown/dropdown.js +++ b/addons/web/static/src/core/dropdown/dropdown.js @@ -3,7 +3,6 @@ import { useBus, useEffect, useService } from "@web/core/utils/hooks"; import { usePosition } from "../position/position_hook"; import { useDropdownNavigation } from "./dropdown_navigation_hook"; -import { ParentClosingMode } from "./dropdown_item"; import { localization } from "../l10n/localization"; const { Component, core, hooks, useState, QWeb } = owl; @@ -17,6 +16,8 @@ const DIRECTION_CARET_CLASS = { right: "dropright", }; +export const DROPDOWN = Symbol("Dropdown"); + /** * @typedef DropdownState * @property {boolean} open @@ -66,8 +67,18 @@ export class Dropdown extends Component { ); // Set up nested dropdowns --------------------------------------------- - this.hasParentDropdown = this.env.inDropdown; - useSubEnv({ inDropdown: true }); + this.parentDropdown = this.env[DROPDOWN]; + useSubEnv({ + [DROPDOWN]: { + close: this.close.bind(this), + closeAllParents: () => { + this.close(); + if (this.parentDropdown) { + this.parentDropdown.closeAllParents(); + } + }, + }, + }); // Set up key navigation ----------------------------------------------- useDropdownNavigation(); @@ -75,7 +86,7 @@ export class Dropdown extends Component { // Set up toggler and positioning -------------------------------------- /** @type {string} **/ let position = - this.props.position || (this.hasParentDropdown ? "right-start" : "bottom-start"); + this.props.position || (this.parentDropdown ? "right-start" : "bottom-start"); let [direction, variant = "middle"] = position.split("-"); if (localization.direction === "rtl") { if (["bottom", "top"].includes(direction)) { @@ -180,25 +191,6 @@ export class Dropdown extends Component { // Handlers // ------------------------------------------------------------------------- - /** - * Checks if should close on dropdown item selection. - * - * @param {CustomEvent} ev - */ - onItemSelected(ev) { - // Handle parent closing request - const { dropdownClosingRequest } = ev.detail; - const closeAll = dropdownClosingRequest.mode === ParentClosingMode.AllParents; - const closeSelf = - dropdownClosingRequest.isFresh && - dropdownClosingRequest.mode === ParentClosingMode.ClosestParent; - if (!this.props.manualOnly && (closeAll || closeSelf)) { - this.close(); - } - // Mark closing request as started - ev.detail.dropdownClosingRequest.isFresh = false; - } - /** * Dropdowns react to each other state changes through this method. * diff --git a/addons/web/static/src/core/dropdown/dropdown.xml b/addons/web/static/src/core/dropdown/dropdown.xml index cfd9e111e44..d0a98d9d2ec 100644 --- a/addons/web/static/src/core/dropdown/dropdown.xml +++ b/addons/web/static/src/core/dropdown/dropdown.xml @@ -4,14 +4,13 @@