From a8172fa67af66850f547ee2f58e712516594079f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= <ged@odoo.com>
Date: Mon, 1 Nov 2021 09:00:58 +0000
Subject: [PATCH] [IMP] developer: add section on user menu registry (js)

closes odoo/documentation#1246

Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
---
 .../reference/javascript/registries.rst       | 39 ++++++++++++++++++-
 .../reference/javascript/services.rst         |  2 +-
 2 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/content/developer/reference/javascript/registries.rst b/content/developer/reference/javascript/registries.rst
index 9232e6e4b..7d0536131 100644
--- a/content/developer/reference/javascript/registries.rst
+++ b/content/developer/reference/javascript/registries.rst
@@ -120,6 +120,8 @@ Reference List
      - all services that should be activated
    * - :ref:`systray <registries/systray>`
      - components displayed in the systray zone in the navbar
+   * - :ref:`user_menuitems <registries/usermenu>`
+     - menu items displayed in the user menu (top right of navbar)
 
 .. _registries/main_components:
 
@@ -216,4 +218,39 @@ The systray registry is an ordered registry (with the `sequence` number):
 
 The sequence number defaults to 50. If given, this number will be used
 to order the items. The lowest sequence is on the right and the highest sequence
-is on the left in the systray menu.
\ No newline at end of file
+is on the left in the systray menu.
+
+.. _registries/usermenu:
+
+Usermenu registry
+-----------------
+
+The user menu registry (category: `user_menuitems`) contains all menu items that
+are shown when opening the user menu (the navbar element with the user name, on
+the top right).
+
+User menu items are defined by a function taking the :ref:`env <javascript/environment>`
+and returning a plain object, containing the following information:
+
+* `description` : the menu item text,
+* `href` : (optional) if given (and truthy), the item text is put in a `a` tag with given attribute href,
+* `callback` : callback to call when the item is selected,
+* `hide`: (optional) indicates if the item should be hidden (default: `false`),
+* `sequence`: (optional) determines the rank of the item among the other dropwdown items (default: 100).
+
+The user menu calls all the functions defining items every time it is opened.
+
+Example:
+
+.. code-block:: js
+
+    import { registry } from "@web/core/registry";
+
+    registry.category("user_menuitems").add("my item", (env) => {
+        return {
+            description: env._t("Technical Settings"),
+            callback: () => { env.services.action_manager.doAction(3); };
+            hide: (Math.random() < 0.5),
+        };
+    }
+
diff --git a/content/developer/reference/javascript/services.rst b/content/developer/reference/javascript/services.rst
index d51953b3d..fc12da362 100644
--- a/content/developer/reference/javascript/services.rst
+++ b/content/developer/reference/javascript/services.rst
@@ -405,7 +405,7 @@ The `notification` service allows to display notifications on the screen.
 API
 ~~~
 
-.. js:function:: add(message, options?)
+.. js:function:: add(message[, options])
   
     :param string message: the notification message to display
     :param object options: the options of the notification