From 3489a0d28fdbaf607d18b00d144bb00bae2727c3 Mon Sep 17 00:00:00 2001 From: "Xavier Bol (xbo)" Date: Thu, 12 Oct 2023 13:49:36 +0200 Subject: [PATCH] [IMP] hr_org_chart: auto scroll in hierarchy view Before this commit, when the user unfold a node in hierarchy view, he has to scroll to be able to see the child nodes added. This commit adds an auto-scroll when a new row is added to directly show the child nodes added on the view when the user unfolds a node in the hirarchy view. task-3376776 --- .../src/views/hierarchy/hierarchy_renderer.js | 14 +++++++++++++- .../static/src/views/hierarchy/hierarchy_view.scss | 8 ++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/addons/hr_org_chart/static/src/views/hierarchy/hierarchy_renderer.js b/addons/hr_org_chart/static/src/views/hierarchy/hierarchy_renderer.js index ef6253089ea..4cc974b823d 100644 --- a/addons/hr_org_chart/static/src/views/hierarchy/hierarchy_renderer.js +++ b/addons/hr_org_chart/static/src/views/hierarchy/hierarchy_renderer.js @@ -1,9 +1,10 @@ /** @odoo-module */ -import { Component, useRef } from "@odoo/owl"; +import { Component, useRef, onPatched } from "@odoo/owl"; import { _t } from "@web/core/l10n/translation"; import { useService } from "@web/core/utils/hooks"; +import { scrollTo } from "@web/core/utils/scrolling"; import { HierarchyCard } from "./hierarchy_card"; import { useHierarchyNodeDraggable } from "../../hooks/hierarchy_node_draggable"; @@ -61,6 +62,17 @@ export class HierarchyRenderer extends Component { }, }); } + onPatched(this.onPatched); + } + + onPatched() { + const row = this.rendererRef.el.querySelector(":scope .o_hierarchy_row:last-child"); + if (row) { + const scrollable = this.env.isSmall ? document.querySelector(".o_hierarchy_view") : this.rendererRef.el.parentNode; + scrollable.classList.add(".o_hierarchy_auto-scroll"); + scrollTo(row, { scrollable, isAnchor: true }); + scrollable.classList.remove(".o_hierarchy_auto-scroll"); + } } get canDragAndDropRecord() { diff --git a/addons/hr_org_chart/static/src/views/hierarchy/hierarchy_view.scss b/addons/hr_org_chart/static/src/views/hierarchy/hierarchy_view.scss index b3085cb535f..6181b541c25 100644 --- a/addons/hr_org_chart/static/src/views/hierarchy/hierarchy_view.scss +++ b/addons/hr_org_chart/static/src/views/hierarchy/hierarchy_view.scss @@ -1,3 +1,11 @@ .o_control_panel_navigation .o_switch_view .o_hierarchy_icon { // button in view switcher rotate: 90deg; } + +.o_hierarchy_view { // uses for auto-scroll when drag&drop or unfold node + scroll-behavior: smooth; + + .o_content { + scroll-behavior: smooth; + } +}