Move stats graph partial to a component

Note we're naming it "chart" in order to avoid possible conflicts with
the "graph" view when we move it to a component.
This commit is contained in:
Javi Martín
2024-04-24 01:45:48 +02:00
parent b04ac817f6
commit 1edf0d937d
5 changed files with 29 additions and 18 deletions

View File

@@ -0,0 +1,27 @@
class Admin::Stats::ChartComponent < ApplicationComponent
attr_reader :name, :event, :count
def initialize(name:, event:, count:)
@name = name
@event = event
@count = count
end
private
def chart_tag(opt = {})
opt[:data] ||= {}
opt[:data][:graph] = admin_api_stats_path(chart_data(opt))
tag.div(**opt)
end
def chart_data(opt = {})
data = nil
if opt[:id].present?
data = { opt[:id] => true }
elsif opt[:event].present?
data = { event: opt[:event] }
end
data
end
end