Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Controls placement on resource level #3320

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
%>
Copy link
Contributor

@Paul-Bob Paul-Bob Oct 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's extract this logic to a concern, something like

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

def resource_controls_on_the_right?
  controls_placement == :right
end

def resource_controls_on_the_left?
  controls_placement == :left
end

Then include the concern on the components that uses this logic.

Let's also ensure that the original methods resource_controls_on_the_right? and resource_controls_on_the_left? are deleted if they are no longer used.


<%= 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
Loading