From 4b21d735f920eee06b7171a2fdcb773704883cd9 Mon Sep 17 00:00:00 2001 From: Damien Bouvy Date: Tue, 2 May 2023 11:23:03 +0000 Subject: [PATCH] [IMP] web: cp responsiveness - Avoid isSmall in template and use bootstrap display classes for better responsiveness - Re-order items to preserve order between size transitions as much as possible - Change several breakpoints: - Viewswitcher collaspses faster (lg instead of sm) - Create 'always' buttons collapse in dropdown faste (lg instead of sm) Make the searchabr appear/disappear based on sizing for better responsiveness. Hide the searhbar by default once we go under the LG breakpoint, so that it does not cause re-flows when a user selects a record's checkbox in list view. 'always buttons' that are meant to always be included in the control panel are collapsed into a dropdown attached to the 'new' button when the size drops below a specific breakpoint. This commit ensure these breakpoints are correctly mirrored between the JS code and the XML template, and also make sure the 'btn-group' class is removed when there is no button to display in the dropdown (otherwise the 'new' button is styled as-if some buton is supposed to be next to it). Part-of: odoo/odoo#116641 --- .../src/search/control_panel/control_panel.js | 10 +-- .../search/control_panel/control_panel.xml | 87 +++++++++---------- .../src/search/search_bar/search_bar.js | 14 ++- .../src/search/search_bar/search_bar.xml | 4 +- 4 files changed, 60 insertions(+), 55 deletions(-) diff --git a/addons/web/static/src/search/control_panel/control_panel.js b/addons/web/static/src/search/control_panel/control_panel.js index 8d9e26ca18b..a316254b0bc 100644 --- a/addons/web/static/src/search/control_panel/control_panel.js +++ b/addons/web/static/src/search/control_panel/control_panel.js @@ -74,15 +74,15 @@ export class ControlPanel extends Component { this.mainButtons = useRef("mainButtons"); useEffect(() => { - if (!this.env.isSmall) { - return; - } // on small screen, clean-up the dropdown elements - const dropdownButtons = this.mainButtons.el.querySelectorAll(".dropdown-menu button"); + const dropdownButtons = this.mainButtons.el.querySelectorAll(".o_control_panel_collapsed_create.dropdown-menu button"); if (!dropdownButtons.length) { this.mainButtons.el - .querySelectorAll(".dropdown-menu, .dropdown-toggle") + .querySelectorAll(".o_control_panel_collapsed_create.dropdown-menu, .o_control_panel_collapsed_create.dropdown-toggle") .forEach((el) => el.classList.add("d-none")); + this.mainButtons.el + .querySelectorAll(".o_control_panel_collapsed_create.btn-group") + .forEach((el) => el.classList.remove("btn-group")); return; } for (const button of dropdownButtons) { diff --git a/addons/web/static/src/search/control_panel/control_panel.xml b/addons/web/static/src/search/control_panel/control_panel.xml index 1d8a10416dd..312e54780f9 100644 --- a/addons/web/static/src/search/control_panel/control_panel.xml +++ b/addons/web/static/src/search/control_panel/control_panel.xml @@ -3,26 +3,24 @@
-
-
-
- -
- - - -
-
- +
+
+
+
+ + + +
+
- +
@@ -36,41 +34,36 @@
-
+
-
- - @@ -120,7 +113,7 @@
-
+
diff --git a/addons/web/static/src/search/search_bar/search_bar.js b/addons/web/static/src/search/search_bar/search_bar.js index f5d5fae2ca6..3e61f330912 100644 --- a/addons/web/static/src/search/search_bar/search_bar.js +++ b/addons/web/static/src/search/search_bar/search_bar.js @@ -9,6 +9,9 @@ import { DomainSelectorDialog } from "@web/core/domain_selector_dialog/domain_se import { fuzzyTest } from "@web/core/utils/search"; import { _t } from "@web/core/l10n/translation"; import { SearchBarMenu } from "../search_bar_menu/search_bar_menu"; +import { useDebounced } from "@web/core/utils/timing"; +import { browser } from "@web/core/browser/browser"; +import { SIZES } from "@web/core/ui/ui_service"; import { Component, @@ -31,13 +34,14 @@ export class SearchBar extends Component { this.fields = this.env.searchModel.searchViewFields; this.searchItemsFields = this.env.searchModel.getSearchItems((f) => f.type === "field"); this.root = useRef("root"); + this.ui = useService("ui"); // core state this.state = useState({ expanded: [], focusedIndex: 0, query: "", - showSearchBar: !this.env.isSmall, + showSearchBar: this.ui.size > SIZES.SM, }); // derived state @@ -60,6 +64,10 @@ export class SearchBar extends Component { useExternalListener(window, "click", this.onWindowClick); useExternalListener(window, "keydown", this.onWindowKeydown); + + this.onResize = useDebounced(this.onResize, 200); + onMounted(() => browser.addEventListener("resize", this.onResize)); + onWillUnmount(() => browser.removeEventListener("resize", this.onResize)); } /** @@ -435,6 +443,10 @@ export class SearchBar extends Component { this.inputRef.el.focus(); } + onResize() { + this.state.showSearchBar = this.ui.size > SIZES.SM; + } + /** * @param {KeyboardEvent} ev */ diff --git a/addons/web/static/src/search/search_bar/search_bar.xml b/addons/web/static/src/search/search_bar/search_bar.xml index 2e8fa11aea7..8bed86d6193 100644 --- a/addons/web/static/src/search/search_bar/search_bar.xml +++ b/addons/web/static/src/search/search_bar/search_bar.xml @@ -97,8 +97,8 @@
- -