From 8a5721bc7d5540e382d2d06fe5b9634911b7859c Mon Sep 17 00:00:00 2001 From: "Michael (mcm)" Date: Mon, 7 Mar 2022 08:15:09 +0000 Subject: [PATCH] [REF] web: remove LegacyComponent Before this commit, components used `el` and `trigger` but this works thanks to LegacyComponent. LegacyComponent has been introduced to ease the transition from owl 1 to owl 2. This commit replaces the uses of `el` by `useRef` and `trigger` by adding callback in props. Without these owl 1 features, components no longer need to extend LegacyComponent. This commit also adapts the tests to use `getFixture` instead of `el`. closes odoo/odoo#85903 Related: odoo/enterprise#25032 Signed-off-by: Samuel Degueldre Co-authored-by: Aaron Bohy Co-authored-by: Simon Genin (ges) Co-authored-by: luvi Co-authored-by: Jorge Pinna Puissant --- .../src/core/commands/command_palette.xml | 4 +- .../src/core/commands/default_providers.js | 9 +- .../static/src/core/datepicker/datepicker.js | 15 +-- .../static/src/core/datepicker/datepicker.xml | 2 +- addons/web/static/src/core/dialog/dialog.js | 5 +- .../web/static/src/core/dropdown/dropdown.js | 4 +- .../static/src/core/dropdown/dropdown_item.js | 5 +- .../static/src/core/effects/rainbow_man.js | 8 +- .../static/src/core/effects/rainbow_man.xml | 2 +- .../static/src/core/file_input/file_input.js | 7 +- .../static/src/core/file_input/file_input.xml | 2 +- addons/web/static/src/core/popover/popover.js | 1 - .../web/static/src/core/popover/popover.xml | 2 - .../src/core/popover/popover_container.js | 11 +- addons/web/static/src/core/tooltip/tooltip.js | 1 + addons/web/static/src/core/utils/hooks.js | 1 + .../static/src/legacy/js/core/owl_dialog.js | 12 +- .../web/static/src/legacy/legacy_component.js | 9 +- .../group_by_menu/custom_group_by_item.js | 5 +- addons/web/static/src/search/layout.js | 5 +- .../src/search/search_bar/search_bar.js | 12 +- .../src/search/search_bar/search_bar.xml | 2 +- .../src/search/search_panel/search_panel.js | 13 +- .../src/search/search_panel/search_panel.xml | 2 +- .../src/search/with_search/with_search.js | 5 +- .../static/src/views/graph/graph_renderer.js | 14 +-- .../static/src/views/graph/graph_renderer.xml | 2 +- .../web/static/src/views/helpers/view_hook.js | 10 +- .../web/static/src/views/onboarding_banner.js | 9 +- .../static/src/views/pivot/pivot_renderer.js | 10 +- .../static/src/views/pivot/pivot_renderer.xml | 12 +- addons/web/static/src/views/view.js | 7 +- addons/web/static/src/views/view.xml | 2 +- .../web/static/src/webclient/navbar/navbar.js | 9 +- .../static/src/webclient/navbar/navbar.xml | 2 +- .../switch_company_menu.js | 5 +- addons/web/static/tests/core/dialog_tests.js | 23 ++-- .../core/effects/effect_service_tests.js | 49 ++++---- .../tests/core/errors/error_service_tests.js | 9 +- .../web/static/tests/core/file_input_tests.js | 36 +++--- .../tests/core/l10n/translation_tests.js | 5 +- .../tests/core/network/rpc_service_tests.js | 7 +- .../core/popover/popover_service_tests.js | 5 +- .../static/tests/core/utils/hooks_tests.js | 32 ++--- .../webclient/actions/client_action_tests.js | 11 +- .../webclient/actions/concurrency_tests.js | 7 +- .../webclient/actions/error_handling_tests.js | 7 +- .../webclient/actions/load_state_tests.js | 9 +- .../webclient/actions/push_state_tests.js | 9 +- .../tests/webclient/actions/target_tests.js | 9 +- addons/web/static/tests/webclient/helpers.js | 3 +- .../mobile_switch_company_menu_tests.js | 118 ++++++++++-------- .../static/tests/webclient/navbar_tests.js | 108 ++++++++-------- .../static/tests/webclient/webclient_tests.js | 11 +- 54 files changed, 338 insertions(+), 346 deletions(-) diff --git a/addons/web/static/src/core/commands/command_palette.xml b/addons/web/static/src/core/commands/command_palette.xml index 9c6eff8a6af..278487c8c2a 100644 --- a/addons/web/static/src/core/commands/command_palette.xml +++ b/addons/web/static/src/core/commands/command_palette.xml @@ -15,8 +15,8 @@
-
- +
+ diff --git a/addons/web/static/src/core/commands/default_providers.js b/addons/web/static/src/core/commands/default_providers.js index e5a80830cb5..3eaeca5dc88 100644 --- a/addons/web/static/src/core/commands/default_providers.js +++ b/addons/web/static/src/core/commands/default_providers.js @@ -7,18 +7,17 @@ import { registry } from "@web/core/registry"; import { capitalize } from "@web/core/utils/strings"; import { getVisibleElements } from "@web/core/utils/ui"; import { DefaultCommandItem } from "./command_palette"; -import { LegacyComponent } from "@web/legacy/legacy_component"; + +const { Component } = owl; const commandSetupRegistry = registry.category("command_setup"); commandSetupRegistry.add("default", { emptyMessage: _lt("No command found"), }); -export class HotkeyCommandItem extends LegacyComponent { +export class HotkeyCommandItem extends Component { setup() { - useHotkey(this.props.hotkey, () => { - this.trigger("execute-command"); - }); + useHotkey(this.props.hotkey, this.props.executeCommand); } getKeysToPress(command) { diff --git a/addons/web/static/src/core/datepicker/datepicker.js b/addons/web/static/src/core/datepicker/datepicker.js index 328deb913fc..7c7b23e6284 100644 --- a/addons/web/static/src/core/datepicker/datepicker.js +++ b/addons/web/static/src/core/datepicker/datepicker.js @@ -3,9 +3,9 @@ import { localization } from "@web/core/l10n/localization"; import { registry } from "@web/core/registry"; import { useAutofocus } from "@web/core/utils/hooks"; -import { LegacyComponent } from "@web/legacy/legacy_component"; const { + Component, onMounted, onWillUpdateProps, onWillUnmount, @@ -49,8 +49,9 @@ const luxonFormatToMomentFormat = (format) => { * stringified since tempusdominus only works with moment objects. * @extends Component */ -export class DatePicker extends LegacyComponent { +export class DatePicker extends Component { setup() { + this.root = useRef("root"); this.inputRef = useRef("input"); this.state = useState({ warning: false }); @@ -68,9 +69,9 @@ export class DatePicker extends LegacyComponent { } onMounted() { - window.$(this.el).on("show.datetimepicker", () => this.inputRef.el.select()); - window.$(this.el).on("hide.datetimepicker", () => this.onDateChange()); - window.$(this.el).on("error.datetimepicker", () => false); // Ignores datepicker errors + window.$(this.root.el).on("show.datetimepicker", () => this.inputRef.el.select()); + window.$(this.root.el).on("hide.datetimepicker", () => this.onDateChange()); + window.$(this.root.el).on("error.datetimepicker", () => false); // Ignores datepicker errors this.bootstrapDateTimePicker(this.props); this.updateInput(); @@ -91,7 +92,7 @@ export class DatePicker extends LegacyComponent { } onWillUnmount() { - window.$(this.el).off(); // Removes all jQuery events + window.$(this.root.el).off(); // Removes all jQuery events this.bootstrapDateTimePicker("destroy"); } @@ -169,7 +170,7 @@ export class DatePicker extends LegacyComponent { } commandOrParams = params; } - window.$(this.el).datetimepicker(commandOrParams); + window.$(this.root.el).datetimepicker(commandOrParams); } //--------------------------------------------------------------------- diff --git a/addons/web/static/src/core/datepicker/datepicker.xml b/addons/web/static/src/core/datepicker/datepicker.xml index c600a1c78a2..e8c9cbb5a43 100644 --- a/addons/web/static/src/core/datepicker/datepicker.xml +++ b/addons/web/static/src/core/datepicker/datepicker.xml @@ -3,7 +3,7 @@ -
+
{ const timeout = browser.setTimeout(() => { - this.el.classList.add("o_reward_fading"); + this.state.isFading = true; }, this.delay); return () => browser.clearTimeout(timeout); }, diff --git a/addons/web/static/src/core/effects/rainbow_man.xml b/addons/web/static/src/core/effects/rainbow_man.xml index 5011597a305..d4e8a6515ed 100644 --- a/addons/web/static/src/core/effects/rainbow_man.xml +++ b/addons/web/static/src/core/effects/rainbow_man.xml @@ -2,7 +2,7 @@ -
+
diff --git a/addons/web/static/src/core/file_input/file_input.js b/addons/web/static/src/core/file_input/file_input.js index d013cfe48ba..70cb4d29489 100644 --- a/addons/web/static/src/core/file_input/file_input.js +++ b/addons/web/static/src/core/file_input/file_input.js @@ -1,9 +1,8 @@ /** @odoo-module **/ import { useService } from "@web/core/utils/hooks"; -import { LegacyComponent } from "@web/legacy/legacy_component"; -const { useRef } = owl; +const { Component, useRef } = owl; /** * Custom file input @@ -23,7 +22,7 @@ const { useRef } = owl; * @param {string} [props.multi_upload=false] Whether the input should allow * to upload multiple files at once. */ -export class FileInput extends LegacyComponent { +export class FileInput extends Component { setup() { this.http = useService("http"); this.fileInputRef = useRef("file-input"); @@ -58,7 +57,7 @@ export class FileInput extends LegacyComponent { if (parsedFileData.error) { throw new Error(parsedFileData.error); } - this.trigger("uploaded", { files: parsedFileData }); + this.props.onUpload(parsedFileData); } /** diff --git a/addons/web/static/src/core/file_input/file_input.xml b/addons/web/static/src/core/file_input/file_input.xml index 63618f016c1..aec7608927d 100644 --- a/addons/web/static/src/core/file_input/file_input.xml +++ b/addons/web/static/src/core/file_input/file_input.xml @@ -2,7 +2,7 @@ - + diff --git a/addons/web/static/src/core/popover/popover.js b/addons/web/static/src/core/popover/popover.js index 54e7be5d0d7..7315374611f 100644 --- a/addons/web/static/src/core/popover/popover.js +++ b/addons/web/static/src/core/popover/popover.js @@ -18,7 +18,6 @@ Popover.defaultProps = { position: "bottom", }; Popover.props = { - close: { type: Function }, popoverClass: { optional: true, type: String, diff --git a/addons/web/static/src/core/popover/popover.xml b/addons/web/static/src/core/popover/popover.xml index d16962d87d3..92e87b434e4 100644 --- a/addons/web/static/src/core/popover/popover.xml +++ b/addons/web/static/src/core/popover/popover.xml @@ -4,8 +4,6 @@