From d00aea4eec26e45e89ad4c2af9dec60636ad28c3 Mon Sep 17 00:00:00 2001 From: Behrokh Satarnejad Date: Tue, 10 Dec 2024 17:25:51 +0100 Subject: [PATCH] change the attr name and set the selector on the row --- .../index_component.html.erb | 3 +-- .../index_component.rb | 18 ++++++++++++++---- .../work_package_children_controller.rb | 2 +- .../work_package_relations_controller.rb | 2 +- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/components/work_package_relations_tab/index_component.html.erb b/app/components/work_package_relations_tab/index_component.html.erb index 742eaca08200..cddd410e56be 100644 --- a/app/components/work_package_relations_tab/index_component.html.erb +++ b/app/components/work_package_relations_tab/index_component.html.erb @@ -55,8 +55,7 @@ <%= flex_layout(mb: 3, data: { "application-target": "dynamic", - controller: "work-packages--relations-tab--scroll", - "work-packages--relations-tab--scroll-target-id-value": @scroll_target_id, + controller: "work-packages--relations-tab--scroll" }) do |flex| if any_relations? key_namespace = "#{I18N_NAMESPACE}.relations" diff --git a/app/components/work_package_relations_tab/index_component.rb b/app/components/work_package_relations_tab/index_component.rb index 91426bf1ed58..4822e594b57b 100644 --- a/app/components/work_package_relations_tab/index_component.rb +++ b/app/components/work_package_relations_tab/index_component.rb @@ -9,16 +9,16 @@ class WorkPackageRelationsTab::IndexComponent < ApplicationComponent include Turbo::FramesHelper include OpTurbo::Streamable - attr_reader :work_package, :relations, :children, :directionally_aware_grouped_relations + attr_reader :work_package, :relations, :children, :directionally_aware_grouped_relations, :scroll_to_id - def initialize(work_package:, relations:, children:, scroll_target_id: nil) + def initialize(work_package:, relations:, children:, scroll_to_id: nil) super() @work_package = work_package @relations = relations @children = children @directionally_aware_grouped_relations = group_relations_by_directional_context - @scroll_target_id = scroll_target_id + @scroll_to_id = scroll_to_id end def self.wrapper_key @@ -62,7 +62,17 @@ def render_relation_group(title:, relation_type:, items:, &_block) end items.each do |item| - border_box.with_row(test_selector: row_test_selector(item)) do + related_work_package_id = if item.is_a?(Relation) + item.from_id == work_package.id ? item.to_id : item.from_id + else + item.id + end + + scroll_active = related_work_package_id.to_s == @scroll_to_id + border_box.with_row( + test_selector: row_test_selector(item), + data: { scroll_active: scroll_active } + ) do yield(item) end end diff --git a/app/controllers/work_package_children_controller.rb b/app/controllers/work_package_children_controller.rb index a302af0fc4e9..17cc55f95483 100644 --- a/app/controllers/work_package_children_controller.rb +++ b/app/controllers/work_package_children_controller.rb @@ -59,7 +59,7 @@ def create work_package: @work_package, relations: @relations, children: @children, - scroll_target_id: target_work_package_id + scroll_to_id: target_work_package_id ) replace_via_turbo_stream(component:) update_flash_message_via_turbo_stream( diff --git a/app/controllers/work_package_relations_controller.rb b/app/controllers/work_package_relations_controller.rb index 6815f7c97e7e..ca2b6bc06b4c 100644 --- a/app/controllers/work_package_relations_controller.rb +++ b/app/controllers/work_package_relations_controller.rb @@ -65,7 +65,7 @@ def create component = WorkPackageRelationsTab::IndexComponent.new(work_package: @work_package, relations: @work_package.relations, children: @work_package.children, - scroll_target_id: target_work_package_id) + scroll_to_id: target_work_package_id) replace_via_turbo_stream(component:) respond_with_turbo_streams else