Skip to content

Commit

Permalink
DRY up dynamic component dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
mamhoff committed Jun 14, 2024
1 parent 2d44556 commit 7e8a61a
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,14 @@ def columns
header: :adjustable,
col: { class: 'w-56' },
data: ->(adjustment) {
component_name = adjustment.adjustable&.class&.table_name&.singularize
component_key = ["orders/show/adjustments/index/adjustable", component_name].compact.join("/")
render component(component_key).new(adjustment)
render_thumbnail_with_caption(adjustment, :adjustable)
}
},
{
header: :source,
col: { class: "w-56" },
data: ->(adjustment) {
component_name = adjustment.source&.class&.table_name&.singularize
component_key = ["orders/show/adjustments/index/source", component_name].compact.join("/")
render component(component_key).new(adjustment)
render_thumbnail_with_caption(adjustment, :source)
}
},
{
Expand Down Expand Up @@ -140,4 +136,12 @@ def columns
},
]
end

private

def render_thumbnail_with_caption(adjustment, role)
component_name = adjustment.send(role).class.table_name.singularize if adjustment.send(role)
component_key = ["orders/show/adjustments/index/#{role}", component_name].compact.join("/")
render component(component_key).new(adjustment)
end
end

0 comments on commit 7e8a61a

Please sign in to comment.