From ce5599926af8cf2d69d3abbff0cb212b4af04473 Mon Sep 17 00:00:00 2001 From: Samuel Degueldre Date: Tue, 3 Aug 2021 09:05:03 +0000 Subject: [PATCH] [REF] web, website: remove legacy DebugManager and use new DebugMenu Previously, the debug manager was rewritten with the new webclient architecture, however, because the frontend did not have access to the new infrastructure (env and services), the old debug manager was kept and used only in the frontend. Since odoo/odoo#72675 the new env and services are now available, this commit simply uses the new debug manager in the frontend and removes the legacy code. closes odoo/odoo#74609 Signed-off-by: Aaron Bohy (aab) --- addons/web/__manifest__.py | 3 - .../static/src/core/debug/debug_context.js | 6 +- .../static/src/core/debug/debug_menu_items.js | 85 -------- .../core/debug/profiling/profiling_item.js | 9 +- .../static/src/core/errors/error_handlers.js | 16 +- .../legacy/frontend/debug_manager/debug.xml | 69 ------- .../frontend/debug_manager/debug_manager.js | 194 ------------------ .../frontend/debug_manager/debug_manager.scss | 13 -- .../src/legacy/legacy_rpc_error_handler.js | 36 +--- .../web/static/src/webclient/debug_items.js | 88 ++++++++ .../tests/core/debug/debug_manager_tests.js | 2 +- .../tests/legacy/tools/debug_manager_tests.js | 175 ---------------- addons/website/__manifest__.py | 2 +- .../static/src/js/menu/debug_manager.js | 21 -- .../website/static/src/js/menu/debug_menu.js | 20 ++ 15 files changed, 139 insertions(+), 600 deletions(-) delete mode 100644 addons/web/static/src/legacy/frontend/debug_manager/debug.xml delete mode 100644 addons/web/static/src/legacy/frontend/debug_manager/debug_manager.js delete mode 100644 addons/web/static/src/legacy/frontend/debug_manager/debug_manager.scss create mode 100644 addons/web/static/src/webclient/debug_items.js delete mode 100644 addons/web/static/tests/legacy/tools/debug_manager_tests.js delete mode 100644 addons/website/static/src/js/menu/debug_manager.js create mode 100644 addons/website/static/src/js/menu/debug_menu.js diff --git a/addons/web/__manifest__.py b/addons/web/__manifest__.py index c23f3ba1947..0ecd9765bf7 100644 --- a/addons/web/__manifest__.py +++ b/addons/web/__manifest__.py @@ -203,9 +203,6 @@ This module provides the core of the Odoo Web Client. 'web/static/src/env.js', 'web/static/src/core/utils/transitions.scss', # included early because used by other files 'web/static/src/core/**/*', - # TODO: split debug files correctly when converting frontend debug - # manager so we don't need action-service and stuff - ('remove', 'web/static/src/core/debug/**/*'), 'web/static/src/public/error_notifications.js', 'web/static/src/legacy/scss/base_frontend.scss', diff --git a/addons/web/static/src/core/debug/debug_context.js b/addons/web/static/src/core/debug/debug_context.js index d1c102cc46c..a77ba98ac2a 100644 --- a/addons/web/static/src/core/debug/debug_context.js +++ b/addons/web/static/src/core/debug/debug_context.js @@ -61,8 +61,12 @@ class DebugContext { } const debugContextSymbol = Symbol("debugContext"); +export function createDebugContext(env, { categories = [] } = {}) { + return { [debugContextSymbol]: new DebugContext(env, categories) }; +} + export function useOwnDebugContext({ categories = [] } = {}) { - useSubEnv({ [debugContextSymbol]: new DebugContext(useEnv(), categories) }); + useSubEnv(createDebugContext(useEnv(), { categories })); } export function useCurrentDebugContext() { diff --git a/addons/web/static/src/core/debug/debug_menu_items.js b/addons/web/static/src/core/debug/debug_menu_items.js index c9d0ed93939..6ef2c887d35 100644 --- a/addons/web/static/src/core/debug/debug_menu_items.js +++ b/addons/web/static/src/core/debug/debug_menu_items.js @@ -4,85 +4,6 @@ import { browser } from "../browser/browser"; import { routeToUrl } from "../browser/router_service"; import { registry } from "../registry"; -// @legacy -import dialogs from "web.view_dialogs"; -import { ComponentAdapter } from "web.OwlCompatibility"; - -// Backend Debug Manager Items -function runJSTestsItem({ env }) { - const runTestsURL = browser.location.origin + "/web/tests?mod=*"; - return { - type: "item", - description: env._t("Run JS Tests"), - href: runTestsURL, - callback: () => { - browser.open(runTestsURL); - }, - sequence: 10, - }; -} - -function runJSTestsMobileItem({ env }) { - const runTestsMobileURL = browser.location.origin + "/web/tests/mobile?mod=*"; - return { - type: "item", - description: env._t("Run JS Mobile Tests"), - href: runTestsMobileURL, - callback: () => { - browser.open(runTestsMobileURL); - }, - sequence: 20, - }; -} - -export function openViewItem({ env }) { - async function onSelected(records) { - const views = await env.services.orm.searchRead( - "ir.ui.view", - [["id", "=", records[0].id]], - ["name", "model", "type"], - { limit: 1 } - ); - const view = views[0]; - view.type = view.type === "tree" ? "list" : view.type; // ignore tree view - env.services.action.doAction({ - type: "ir.actions.act_window", - name: view.name, - res_model: view.model, - views: [[view.id, view.type]], - }); - } - - return { - type: "item", - description: env._t("Open View"), - callback: () => { - const adapterParent = new ComponentAdapter(null, { Component: owl.Component }); - const selectCreateDialog = new dialogs.SelectCreateDialog(adapterParent, { - res_model: "ir.ui.view", - title: env._t("Select a view"), - disable_multiple_selection: true, - domain: [ - ["type", "!=", "qweb"], - ["type", "!=", "search"], - ], - on_selected: onSelected, - }); - - selectCreateDialog.open(); - }, - sequence: 40, - }; -} - -// Global Debug Manager Items -function globalSeparator() { - return { - type: "separator", - sequence: 400, - }; -} - function activateAssetsDebugging({ env }) { return { type: "item", @@ -155,12 +76,6 @@ function leaveDebugMode({ env }) { registry .category("debug") .category("default") - // Backend - .add("runJSTestsItem", runJSTestsItem) - .add("runJSTestsMobileItem", runJSTestsMobileItem) - .add("openViewItem", openViewItem) - // Global - .add("globalSeparator", globalSeparator) .add("activateAssetsDebugging", activateAssetsDebugging) .add("regenerateAssets", regenerateAssets) .add("becomeSuperuser", becomeSuperuser) diff --git a/addons/web/static/src/core/debug/profiling/profiling_item.js b/addons/web/static/src/core/debug/profiling/profiling_item.js index 949bde29eea..b56f85d9c45 100644 --- a/addons/web/static/src/core/debug/profiling/profiling_item.js +++ b/addons/web/static/src/core/debug/profiling/profiling_item.js @@ -8,7 +8,6 @@ const { Component } = owl; export class ProfilingItem extends Component { setup() { this.profiling = useService("profiling"); - this.actionService = useService("action"); useBus(this.props.bus, "UPDATE", this.render); } @@ -16,7 +15,13 @@ export class ProfilingItem extends Component { this.profiling.setParam(param, ev.target.value); } openProfiles() { - this.actionService.doAction("base.action_menu_ir_profile"); + if (this.env.services.action) { + // using doAction in the backend to preserve breadcrumbs and stuff + this.env.services.action.doAction("base.action_menu_ir_profile"); + } else { + // No action service means we are in the frontend. + window.location = "/web/#action=base.action_menu_ir_profile"; + } } } ProfilingItem.components = { DropdownItem }; diff --git a/addons/web/static/src/core/errors/error_handlers.js b/addons/web/static/src/core/errors/error_handlers.js index b761d8eff74..f0d63de995c 100644 --- a/addons/web/static/src/core/errors/error_handlers.js +++ b/addons/web/static/src/core/errors/error_handlers.js @@ -18,6 +18,7 @@ import { UncaughtClientError, UncaughtCorsError, UncaughtPromiseError } from "./ const errorHandlerRegistry = registry.category("error_handlers"); const errorDialogRegistry = registry.category("error_dialogs"); +const errorNotificationRegistry = registry.category("error_notifications"); // ----------------------------------------------------------------------------- // CORS errors @@ -71,7 +72,7 @@ errorHandlerRegistry.add("clientErrorHandler", clientErrorHandler, { sequence: 9 * @param {Error} originalError * @returns {boolean} */ -function rpcErrorHandler(env, error, originalError) { +export function rpcErrorHandler(env, error, originalError) { if (!(error instanceof UncaughtPromiseError)) { return false; } @@ -85,9 +86,16 @@ function rpcErrorHandler(env, error, originalError) { // error is here a RPCError error.unhandledRejectionEvent.preventDefault(); const exceptionName = originalError.exceptionName; - let ErrorComponent = null; - if (exceptionName && errorDialogRegistry.contains(exceptionName)) { - ErrorComponent = errorDialogRegistry.get(exceptionName); + let ErrorComponent = originalError.Component; + if (!ErrorComponent && exceptionName) { + if (errorNotificationRegistry.contains(exceptionName)) { + const notif = errorNotificationRegistry.get(exceptionName); + env.services.notification.add(notif.message || originalError.data.message, notif); + return true; + } + if (errorDialogRegistry.contains(exceptionName)) { + ErrorComponent = errorDialogRegistry.get(exceptionName); + } } env.services.dialog.add(ErrorComponent || RPCErrorDialog, { diff --git a/addons/web/static/src/legacy/frontend/debug_manager/debug.xml b/addons/web/static/src/legacy/frontend/debug_manager/debug.xml deleted file mode 100644 index 4e50a483608..00000000000 --- a/addons/web/static/src/legacy/frontend/debug_manager/debug.xml +++ /dev/null @@ -1,69 +0,0 @@ - - - - - - - - Activate Assets Debugging - Activate Tests Assets Debugging - Regenerate Assets Bundles - Become Superuser - Leave the Developer Tools -