From ebd73104e68168504c70edfdeb40d54674a0985c Mon Sep 17 00:00:00 2001 From: "Arthur Detroux (ard)" Date: Wed, 14 Sep 2022 07:51:58 +0000 Subject: [PATCH] [IMP] web_editor: hide SnippetEditor when no options are shown Commit [1] moved the switchable views inside a SnippetOption. The implementation of that ended up creating empty page options SnippetEditors displayed on every page. This commit makes sure that if a SnippetEditor doesn't have any options, it is not displayed. [1]: https://github.com/odoo/odoo/commit/69af7dcfeb3ff95c40b00ef0cc7c5c0e4021f9d2 task-2687506 X-original-commit: 39d073ccafddf4b3fbe9ec9f5f11849d77c9bdaa Part-of: odoo/odoo#101687 --- .../static/src/js/editor/snippets.editor.js | 8 +++++++- .../static/src/js/editor/snippets.options.js | 11 ----------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/addons/web_editor/static/src/js/editor/snippets.editor.js b/addons/web_editor/static/src/js/editor/snippets.editor.js index 8ffb992f94e..00d86c6240c 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -705,7 +705,13 @@ var SnippetEditor = Widget.extend({ const proms = Object.values(this.styles).map(opt => { return opt.updateUIVisibility(); }); - return Promise.all(proms); + await Promise.all(proms); + // Hide the snippetEditor if none of its options are visible + // This cannot be done using the visibility of the options' UI + // because some options can be located in the overlay. + const $visibleOptions = this.$optionsSection.find('we-top-button-group, we-customizeblock-option') + .children(':not(.d-none)'); + this.$optionsSection.toggleClass('d-none', !$visibleOptions.length); }, /** * Clones the current snippet. diff --git a/addons/web_editor/static/src/js/editor/snippets.options.js b/addons/web_editor/static/src/js/editor/snippets.options.js index a9075890a9d..8c44e98fb62 100644 --- a/addons/web_editor/static/src/js/editor/snippets.options.js +++ b/addons/web_editor/static/src/js/editor/snippets.options.js @@ -5133,17 +5133,6 @@ registry.SnippetMove = SnippetOptionWidget.extend({ return this._super(...arguments); }, - /** - * @override - */ - onFocus: function () { - // TODO improve this: hack to hide options section if snippet move is - // the only one. - const $allOptions = this.$el.parent(); - if ($allOptions.find('we-customizeblock-option').length <= 1) { - $allOptions.addClass('d-none'); - } - }, //-------------------------------------------------------------------------- // Options