Skip to content

Commit

Permalink
♻️ Refactor to concern + add both sides
Browse files Browse the repository at this point in the history
  • Loading branch information
RocKhalil committed Oct 10, 2024
1 parent 391b054 commit 12083c9
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 16 deletions.
7 changes: 2 additions & 5 deletions app/components/avo/index/table_row_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<%# hover:z-[21] removed from tr class to solve flickering actions component on row controls and z-20 changed to z-21%>
<%
resource_controls_placement = @resource.controls_placement || Avo.configuration.resource_controls_placement
%>

<%= content_tag :tr,
class: class_names("bg-white hover:bg-gray-50 hover:shadow-row z-21 border-b", {"cursor-pointer": click_row_to_view_record}),
Expand All @@ -23,7 +20,7 @@
</div>
</td>
<% end %>
<% if resource_controls_placement == :left %>
<% if @resource.resource_controls_render_on_the_left? %>
<td class="text-right whitespace-nowrap w-px" data-control="resource-controls">
<div class="flex items-center justify-end flex-grow-0 h-full">
<%= render resource_controls_component %>
Expand All @@ -45,7 +42,7 @@
<td class="text-center"></td>
<% end %>
<% end %>
<% if resource_controls_placement == :right %>
<% if @resource.resource_controls_render_on_the_right? %>
<td class="text-right whitespace-nowrap px-3" data-control="resource-controls">
<div class="flex items-center justify-end flex-grow-0 h-full">
<%= render resource_controls_component %>
Expand Down
5 changes: 2 additions & 3 deletions app/views/avo/partials/_table_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Currently there isn't a way to summarize records on associations.
# We'd love to support this feature so please send in a PR.
should_summarize = @parent_record.blank?
resource_controls_placement = @resource.controls_placement || Avo.configuration.resource_controls_placement
%>

<thead
Expand All @@ -27,7 +26,7 @@
<% end %>
</th>
<% end %>
<% if resource_controls_placement == :left %>
<% if @resource.resource_controls_render_on_the_left? %>
<th class="max-w-24" data-control="resource-controls-th">
<!-- Item controls cell -->
</th>
Expand Down Expand Up @@ -101,7 +100,7 @@
<% end %>
<% end %>
<% end %>
<% if resource_controls_placement == :right %>
<% if @resource.resource_controls_render_on_the_right? %>
<th class="w-px max-w-24" data-control="resource-controls-th">
<!-- Item controls cell -->
</th>
Expand Down
27 changes: 27 additions & 0 deletions lib/avo/concerns/controls_placement.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

module Avo
module Concerns
module ControlsPlacement
extend ActiveSupport::Concern

def controls_placement
resource.controls_placement || Avo.configuration.resource_controls_placement
end

def resource_controls_render_on_the_right?
controls_placement == :right || resource_controls_render_on_both_sides?
end

def resource_controls_render_on_the_left?
controls_placement == :left || resource_controls_render_on_both_sides?
end

private

def resource_controls_render_on_both_sides?
controls_placement == :both
end
end
end
end
10 changes: 2 additions & 8 deletions lib/avo/configuration/resource_configuration.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Avo
class Configuration
module ResourceConfiguration
Expand All @@ -8,14 +10,6 @@ def resource_controls_placement=(val)
def resource_controls_placement
@resource_controls_placement_instance || :right
end

def resource_controls_on_the_left?
resource_controls_placement == :left
end

def resource_controls_on_the_right?
resource_controls_placement == :right
end
end
end
end
1 change: 1 addition & 0 deletions lib/avo/resources/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Base
include Avo::Concerns::HasHelpers
include Avo::Concerns::Hydration
include Avo::Concerns::Pagination
include Avo::Concerns::ControlsPlacement

# Avo::Current methods
delegate :context, to: Avo::Current
Expand Down

0 comments on commit 12083c9

Please sign in to comment.