Skip to content

Commit

Permalink
Remove button - method in table component
Browse files Browse the repository at this point in the history
The button method was a bit misleading, because it was providing only a container for a button. It now uses the with_action method, which is provided by the ViewComponent slot.
  • Loading branch information
kulturbande committed Aug 29, 2024
1 parent c169870 commit ead16f1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 21 deletions.
13 changes: 3 additions & 10 deletions app/components/alchemy/admin/resource/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Table < ViewComponent::Base
Cell.new(css_classes, &block)
end

renders_many :actions, ->(name, tooltip, &block) do
renders_many :actions, ->(name, tooltip = nil, &block) do
Action.new(name, tooltip, &block)
end

Expand Down Expand Up @@ -114,24 +114,17 @@ def icon_column(icon = nil, style: nil)
end
end

def button(name = nil, tooltip: nil, &block)
with_action name, tooltip, &block
end

def delete_button(tooltip: Alchemy.t("Delete"), message: Alchemy.t("Are you sure?"))
with_action(:destroy, tooltip) do |row|
helpers.delete_button(resource_path(row, search_filter_params), {message: message})
end
end

def edit_button(tooltip: Alchemy.t("Edit"), title: Alchemy.t("Edit"), size: resource_window_size)
def edit_button(tooltip: Alchemy.t("Edit"), size: resource_window_size)
with_action(:edit, tooltip) do |row|
helpers.link_to_dialog render_icon(:edit),
edit_resource_path(row, search_filter_params),
{
title: title,
size: size
},
{size: size},
class: "icon_button"
end
end
Expand Down
10 changes: 5 additions & 5 deletions app/views/alchemy/admin/attachments/_files_list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<% end %>
<% table.column :created_at, sortable: true %>
<% table.button(:show, tooltip: Alchemy.t('Attachment Preview')) do |attachment| %>
<% table.with_action(:show, Alchemy.t('Attachment Preview')) do |attachment| %>
<%= link_to_dialog(
render_icon(:information),
alchemy.admin_attachment_path(attachment),
Expand All @@ -46,21 +46,21 @@
class: "icon_button"
) %>
<% end %>
<% table.button(:download) do |attachment| %>
<% table.with_action(:download) do |attachment| %>
<sl-tooltip content="<%= Alchemy.t("download_file", filename: attachment.file_name) %>">
<%= link_to render_icon(:download),
alchemy.download_admin_attachment_path(attachment),
target: "_blank",
class: "icon_button" %>
</sl-tooltip>
<% end %>
<% table.button(:edit, tooltip: Alchemy.t(:replace_file)) do |attachment| %>
<% table.with_action(:edit, Alchemy.t(:replace_file)) do |attachment| %>
<%= render 'alchemy/admin/attachments/replace_button',
redirect_url: alchemy.admin_attachments_path,
object: attachment,
file_attribute: 'file' %>
<% end %>
<% table.button(:destroy, tooltip: Alchemy.t(:delete_file)) do |attachment| %>
<% table.with_action(:destroy, Alchemy.t(:delete_file)) do |attachment| %>
<%= link_to_confirm_dialog render_icon(:minus),
Alchemy.t(:confirm_to_delete_file),
alchemy.admin_attachment_path(
Expand All @@ -71,7 +71,7 @@
),
class: "icon_button" %>
<% end %>
<% table.button(:edit, tooltip: Alchemy.t(:rename_file)) do |attachment| %>
<% table.with_action(:edit, Alchemy.t(:rename_file)) do |attachment| %>
<%= link_to_dialog render_icon(:edit),
alchemy.edit_admin_attachment_path(attachment, q: search_filter_params[:q], page: params[:page]),
{
Expand Down
6 changes: 3 additions & 3 deletions app/views/alchemy/admin/pages/_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<% end %>
<% end %>
<% table.button :info, tooltip: Alchemy.t(:page_infos) do |page| %>
<% table.with_action :info, Alchemy.t(:page_infos) do |page| %>
<%= link_to_dialog(
render_icon('info-circle'),
alchemy.info_admin_page_path(page),
Expand All @@ -64,7 +64,7 @@
class: "icon_button"
) %>
<% end %>
<% table.button :configure, tooltip: Alchemy.t(:edit_page_properties) do |page| %>
<% table.with_action :configure, Alchemy.t(:edit_page_properties) do |page| %>
<%= link_to_dialog(
render_icon(:cog),
alchemy.configure_admin_page_path(page),
Expand All @@ -75,7 +75,7 @@
class: "icon_button"
) -%>
<% end %>
<% table.button :copy, tooltip: Alchemy.t(:copy_page) do |page| %>
<% table.with_action :copy, Alchemy.t(:copy_page) do |page| %>
<%= link_to(
render_icon(:copy),
alchemy.insert_admin_clipboard_path(
Expand Down
2 changes: 1 addition & 1 deletion app/views/alchemy/admin/tags/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<% table.column :taggings_count, sortable: true, class_name: "count" %>
<% table.delete_button tooltip: Alchemy.t(:delete_tag), message: Alchemy.t(:do_you_really_want_to_delete_this_tag?) %>
<% table.edit_button tooltip: Alchemy.t(:edit_tag), title: Alchemy.t(:edit_tag) %>
<% table.edit_button tooltip: Alchemy.t(:edit_tag) %>
<% end %>
<%= paginate @tags, theme: 'alchemy' %>
Expand Down
4 changes: 2 additions & 2 deletions spec/components/alchemy/admin/resource/table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@
end
end

context "buttons" do
context "actions" do
let(:name) { nil }
let(:tooltip) { nil }

subject(:render) do
with_controller_class(Admin::EventsController) do
render_inline(component) do |table|
table.column(:name)
table.button(name, tooltip: tooltip) { |row| "Foo" }
table.with_action(name, tooltip) { |row| "Foo" }
end
end
end
Expand Down

0 comments on commit ead16f1

Please sign in to comment.