summaryrefslogtreecommitdiff
path: root/addons/google_drive/static/src
diff options
context:
space:
mode:
authorPriyanka Kakadiya <pka@odoo.com>2020-08-26 07:38:43 +0000
committerJulien Mougenot <jum@odoo.com>2020-10-06 11:12:20 +0000
commit44055fd0f0de4f4a64635bd384c6004eb67c8374 (patch)
tree7d4739adaa83d3e16515ff72ed81af766246f62a /addons/google_drive/static/src
parent6916a386db4cad398c6faa02d745103617a1e512 (diff)
[FIX] web: hide action button when no action
Before this commit: the action menu registry items were rendered regardless of their inner state. The problem is that these item components can choose not to render themselves, leading to a blank dropdown menu if no other item was present. To fix this, the "getProps" function of the registry has been altered to act as validation: the item will not be rendered if the return value is falsy. The function has also been made asynchronous to allow RPC calls. This solution is still flawed and hides a bad design choice which is to register components and not items or item getters; this API is too complex for its use case(s) and adds pointless depth to the DOM. The shape of the registry should be simplified in an improvement in master. closes odoo/odoo#59254 Task: 2325587 X-original-commit: 45c7d881a5d130f6b3222749c8c87b6c6b45e910 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com> Co-authored-by: Julien Mougenot <jum@odoo.com> Co-authored-by: Mohammed Shekha <msh@odoo.com>
Diffstat (limited to 'addons/google_drive/static/src')
-rw-r--r--addons/google_drive/static/src/js/gdrive.js71
-rw-r--r--addons/google_drive/static/src/xml/gdrive.xml2
2 files changed, 38 insertions, 35 deletions
diff --git a/addons/google_drive/static/src/js/gdrive.js b/addons/google_drive/static/src/js/gdrive.js
index 03d8e798229..d6090aa9d37 100644
--- a/addons/google_drive/static/src/js/gdrive.js
+++ b/addons/google_drive/static/src/js/gdrive.js
@@ -5,6 +5,36 @@ odoo.define('google_drive.ActionMenus', function (require) {
const DropdownMenuItem = require('web.DropdownMenuItem');
/**
+ * Fetches the google drive action menu item props. To do so this function
+ * is given its parent props and env, as well as the RPC function bound to
+ * the parent context.
+ * Note that we use the bound RPC to benefit from its added behaviour (see
+ * web/component_extension).
+ * @param {Object} props
+ * @param {number[]} props.activeIds
+ * @param {Object} props.context
+ * @param {Object} env
+ * @param {Object} env.action The current action
+ * @param {Object} env.view The current view
+ * @param {Function} rpc Bound to the ActionMenus context
+ * @returns {Object | boolean} item props or false
+ */
+ async function googleDrivePropsGetter(props, env, rpc) {
+ const [activeId] = props.activeIds;
+ const { context } = props;
+ if (env.view.type !== "form" || !activeId) {
+ return false;
+ }
+ const items = await rpc({
+ args: [env.action.res_model, activeId],
+ context,
+ method: 'get_google_drive_config',
+ model: 'google.drive.config',
+ });
+ return Boolean(items.length) && { activeId, context, items };
+ }
+
+ /**
* Google drive menu
*
* This component is actually a set of list items used to enrich the ActionMenus's
@@ -15,32 +45,6 @@ odoo.define('google_drive.ActionMenus', function (require) {
*/
class GoogleDriveMenu extends DropdownMenuItem {
- async willStart() {
- if (this.env.view.type === "form" && this.props.activeIds[0]) {
- this.gdriveItems = await this._getGoogleDocItems();
- } else {
- this.gdriveItems = [];
- }
- }
-
- //---------------------------------------------------------------------
- // Private
- //---------------------------------------------------------------------
-
- /**
- * @private
- * @returns {Promise<Object[]>}
- */
- async _getGoogleDocItems() {
- const items = await this.rpc({
- args: [this.env.action.res_model, this.props.activeIds[0]],
- context: this.props.context,
- method: 'get_google_drive_config',
- model: 'google.drive.config',
- });
- return items;
- }
-
//---------------------------------------------------------------------
// Handlers
//---------------------------------------------------------------------
@@ -51,7 +55,7 @@ odoo.define('google_drive.ActionMenus', function (require) {
* @returns {Promise}
*/
async _onGoogleDocItemClick(itemId) {
- const resID = this.props.activeIds[0];
+ const resID = this.props.activeId;
const domain = [['id', '=', itemId]];
const fields = ['google_drive_resource_id', 'google_drive_client_id'];
const configs = await this.rpc({
@@ -71,19 +75,18 @@ odoo.define('google_drive.ActionMenus', function (require) {
}
}
GoogleDriveMenu.props = {
- activeIds: Array,
+ activeId: Number,
context: Object,
+ items: {
+ type: Array,
+ element: Object,
+ },
};
GoogleDriveMenu.template = 'GoogleDriveMenu';
ActionMenus.registry.add('google-drive-menu', {
Component: GoogleDriveMenu,
- getProps(parentProps) {
- return {
- activeIds: parentProps.activeIds,
- context: parentProps.context,
- };
- },
+ getProps: googleDrivePropsGetter,
});
return GoogleDriveMenu;
diff --git a/addons/google_drive/static/src/xml/gdrive.xml b/addons/google_drive/static/src/xml/gdrive.xml
index 48ce57494c9..d12b3459516 100644
--- a/addons/google_drive/static/src/xml/gdrive.xml
+++ b/addons/google_drive/static/src/xml/gdrive.xml
@@ -2,7 +2,7 @@
<t t-name="GoogleDriveMenu" owl="1">
<li>
<ul class="o_embed_menu">
- <li t-foreach="gdriveItems" t-as="gdriveItem" t-key="gdriveItem.id"
+ <li t-foreach="props.items" t-as="gdriveItem" t-key="gdriveItem.id"
role="menuitem"
class="o_menu_item oe_share_gdoc_item dropdown-item"
>