Skip to content

Commit

Permalink
✨ Controls placement on resource level
Browse files Browse the repository at this point in the history
  • Loading branch information
RocKhalil committed Oct 9, 2024
1 parent 034b0b4 commit 391b054
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions app/components/avo/index/table_row_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<%# 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}),
data: {
Expand All @@ -19,7 +23,7 @@
</div>
</td>
<% end %>
<% if Avo.configuration.resource_controls_on_the_left? %>
<% if resource_controls_placement == :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 @@ -41,7 +45,7 @@
<td class="text-center"></td>
<% end %>
<% end %>
<% if Avo.configuration.resource_controls_on_the_right? %>
<% if resource_controls_placement == :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: 3 additions & 2 deletions app/views/avo/partials/_table_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# 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 @@ -26,7 +27,7 @@
<% end %>
</th>
<% end %>
<% if Avo.configuration.resource_controls_on_the_left? %>
<% if resource_controls_placement == :left %>
<th class="max-w-24" data-control="resource-controls-th">
<!-- Item controls cell -->
</th>
Expand Down Expand Up @@ -100,7 +101,7 @@
<% end %>
<% end %>
<% end %>
<% if Avo.configuration.resource_controls_on_the_right? %>
<% if resource_controls_placement == :right %>
<th class="w-px max-w-24" data-control="resource-controls-th">
<!-- Item controls cell -->
</th>
Expand Down
1 change: 1 addition & 0 deletions lib/avo/resources/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def current_user
class_attribute :components, default: {}
class_attribute :default_sort_column, default: :created_at
class_attribute :default_sort_direction, default: :desc
class_attribute :controls_placement, default: nil

# EXTRACT:
class_attribute :ordering
Expand Down

0 comments on commit 391b054

Please sign in to comment.