Skip to content

Commit

Permalink
change the attr name and set the selector on the row
Browse files Browse the repository at this point in the history
  • Loading branch information
bsatarnejad committed Dec 10, 2024
1 parent 2c34853 commit d00aea4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 14 additions & 4 deletions app/components/work_package_relations_tab/index_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/work_package_children_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/work_package_relations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d00aea4

Please sign in to comment.