From 3fa6af39c97fd5d5f9081d358d44bf4ee1995a97 Mon Sep 17 00:00:00 2001 From: Benoit Socias Date: Wed, 22 Nov 2023 10:13:03 +0100 Subject: [PATCH] [FIX] web_editor, website: fix ignoring unapplied device invisibility Upon drop, the fix in [1] did consider invisible the blocks that were visible within the current preview mode (mobile/desktop). Because of this `onTargetHide` was be called instead of `onTargetShow`. This commit changes that behavior so that the correct method remains called according to the actual visibility, but the `DeviceVisibility`'s `onTargetShow` is adapted to only add the override if it matches the current preview mode. No steps to reproduce for this first change, but third-party options could have been impacted by it. This commit also adds that condition on the cleanup that was added in [2] to keep the `dataset.invisible` state consistent upon toggling the preview mode. Steps to reproduce this second issue: - Drop a Columns snippet. - Make a column visible only on mobile. - Make another column visible only on desktop. - Toggle preview mode several times. => `dataset.invisible` was set to `1` on all columns having device-dependent visibility. [1]: https://github.com/odoo/odoo/commit/acfca25e48ac9bc227234de860fe8128f0312ed4 [2]: https://github.com/odoo/odoo/commit/174e9fe0d8665d1a81c90a6f7bf5cc9e3361f161 task-3538535 closes odoo/odoo#143640 closes odoo/odoo#143875 Signed-off-by: Arthur Detroux (ard) Signed-off-by: Benoit Socias (bso) --- .../static/src/js/editor/snippets.editor.js | 12 +++++++----- .../website/static/src/js/editor/snippets.options.js | 7 +++++-- 2 files changed, 12 insertions(+), 7 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 e7a25e62566..455a5ab58ef 100644 --- a/addons/web_editor/static/src/js/editor/snippets.editor.js +++ b/addons/web_editor/static/src/js/editor/snippets.editor.js @@ -896,10 +896,6 @@ var SnippetEditor = Widget.extend({ if (isMobilePreview === isMobileHidden) { // Preview mode and hidden type are the same. show = false; - } else { - // Preview mode is not related to hidden type. - delete this.$target[0].dataset.invisible; - return false; } } } @@ -4473,9 +4469,15 @@ var SnippetsMenu = Widget.extend({ gridUtils._reloadLazyImages(gridItemEl); } + const isMobilePreview = weUtils.isMobileView(this.$body[0]); for (const invisibleOverrideEl of this.getEditableArea().find('.o_snippet_mobile_invisible, .o_snippet_desktop_invisible')) { + const isMobileHidden = invisibleOverrideEl.classList.contains("o_snippet_mobile_invisible"); invisibleOverrideEl.classList.remove('o_snippet_override_invisible'); - invisibleOverrideEl.dataset.invisible = '1'; + if (isMobilePreview === isMobileHidden) { + invisibleOverrideEl.dataset.invisible = '1'; + } else { + delete invisibleOverrideEl.dataset.invisible; + } } // This is async but using the main editor mutex, currently locked. diff --git a/addons/website/static/src/js/editor/snippets.options.js b/addons/website/static/src/js/editor/snippets.options.js index 5d2398729c8..bb907e6f42b 100644 --- a/addons/website/static/src/js/editor/snippets.options.js +++ b/addons/website/static/src/js/editor/snippets.options.js @@ -2596,8 +2596,11 @@ options.registry.DeviceVisibility = options.Class.extend({ * @override */ async onTargetShow() { - if (this.$target[0].classList.contains('o_snippet_mobile_invisible') - || this.$target[0].classList.contains('o_snippet_desktop_invisible')) { + const isMobilePreview = weUtils.isMobileView(this.$target[0]); + const isMobileHidden = this.$target[0].classList.contains("o_snippet_mobile_invisible"); + if ((this.$target[0].classList.contains('o_snippet_mobile_invisible') + || this.$target[0].classList.contains('o_snippet_desktop_invisible') + ) && isMobilePreview === isMobileHidden) { this.$target[0].classList.add('o_snippet_override_invisible'); } },