Skip to content

Commit

Permalink
Rename label to header in table column method
Browse files Browse the repository at this point in the history
The variable is representing the header text of the column and is way easier to understand than the name label.
  • Loading branch information
kulturbande committed Aug 29, 2024
1 parent ead16f1 commit 026ed13
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions app/components/alchemy/admin/resource/header.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ class Header < ViewComponent::Base
erb_template <<~ERB
<th class="<%= @css_classes %>">
<% if @sortable %>
<%= sort_link @query, @name, @label, default_order: @default_order %>
<%= sort_link @query, @name, @text, default_order: @default_order %>
<% else %>
<%= @label %>
<%= @text %>
<% end %>
</th>
ERB

def initialize(name, query, css_classes: "", label: nil, type: :string, sortable: false)
def initialize(name, query, css_classes: "", text: nil, type: :string, sortable: false)
@name = name
@query = query
@text = text || name
Expand Down
8 changes: 4 additions & 4 deletions app/components/alchemy/admin/resource/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,19 @@ def initialize(collection, query: nil, nothing_found_label: Alchemy.t("Nothing f
@icon = icon
end

def column(name, label: nil, sortable: false, type: nil, class_name: nil, &block)
label ||= resource_handler.model.human_attribute_name(name)
def column(name, header: nil, sortable: false, type: nil, class_name: nil, &block)
header ||= resource_handler.model.human_attribute_name(name)
type ||= resource_handler.model.columns_hash[name.to_s]&.type
attribute = resource_handler.attributes.find { |item| item[:name] == name.to_s } || {name: name, type: type}
block ||= lambda { |item| render_attribute(item, attribute) }

css_classes = [name, type, class_name].compact.join(" ")
with_header(name, @query, css_classes: css_classes, label: label, type: type, sortable: sortable)
with_header(name, @query, css_classes: css_classes, text: header, type: type, sortable: sortable)
with_cell(css_classes, &block)
end

def icon_column(icon = nil, style: nil)
column(:icon, label: "") do |resource|
column(:icon, header: "") do |resource|
render_icon(icon || yield(resource), size: "xl", style: style)
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/views/alchemy/admin/pages/_table.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%= render Alchemy::Admin::Resource::Table.new(@pages, query: @query, search_filter_params: search_filter_params) do |table| %>
<% table.column :icon, label: "" do |page| %>
<% table.column :icon, header: "" do |page| %>
<% if can?(:edit_content, page) %>
<% if page.locked? %>
<sl-tooltip class="like-hint-tooltip" content="<%= Alchemy.t("This page is locked", name: page.locker_name) %>" placement="bottom-start">
Expand All @@ -22,7 +22,7 @@
title: Alchemy.t(:edit_page),
) { content_tag(:span, page.name) } -%>
<% end %>
<% table.column :url_path, label: Alchemy::Page.human_attribute_name(:urlname) %>
<% table.column :url_path, header: Alchemy::Page.human_attribute_name(:urlname) %>
<% table.column :page_type do |page| %>
<%= Alchemy.t(page.page_layout, scope: "page_layout_names", default: page.page_layout.to_s.humanize) %>
<% end %>
Expand Down
8 changes: 4 additions & 4 deletions spec/components/alchemy/admin/resource/header_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
RSpec.describe Alchemy::Admin::Resource::Header, type: :component do
let(:name) { :name }
let(:query) { nil }
let(:label) { nil }
let(:text) { nil }
let(:type) { :string }
let(:sortable) { false }
let(:css_classes) { "foo bar" }

let(:component) { described_class.new(name, query, label: label, type: type, sortable: sortable, css_classes: css_classes) }
let(:component) { described_class.new(name, query, text: text, type: type, sortable: sortable, css_classes: css_classes) }

subject(:render) do
with_controller_class(Admin::EventsController) do
Expand All @@ -29,8 +29,8 @@
expect(page).to have_selector("th.bar")
end

context "with label" do
let(:label) { "Foo" }
context "with text" do
let(:text) { "Foo" }

it "should render header" do
render
Expand Down
6 changes: 3 additions & 3 deletions spec/components/alchemy/admin/resource/table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@
end
end

context "columns with custom label" do
context "columns with custom header" do
subject(:render) do
with_controller_class(Admin::EventsController) do
render_inline(component) do |component|
component.column(:name, label: "Awesome Name")
component.column(:name, header: "Awesome Name")
end
end
end

it "renders a table header with custom label" do
it "renders a table header with custom header" do
render
expect(page).to have_selector("table th", text: "Awesome Name")
end
Expand Down

0 comments on commit 026ed13

Please sign in to comment.