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 all commits
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
5 changes: 3 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,5 @@
<%# hover:z-[21] removed from tr class to solve flickering actions component on row controls and z-20 changed to z-21%>

<%= 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 +20,7 @@
</div>
</td>
<% end %>
<% if Avo.configuration.resource_controls_on_the_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 @@ -41,7 +42,7 @@
<td class="text-center">—</td>
<% end %>
<% end %>
<% if Avo.configuration.resource_controls_on_the_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
4 changes: 2 additions & 2 deletions app/views/avo/partials/_table_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<% end %>
</th>
<% end %>
<% if Avo.configuration.resource_controls_on_the_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 @@ -100,7 +100,7 @@
<% end %>
<% end %>
<% end %>
<% if Avo.configuration.resource_controls_on_the_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_calculated
@controls_placement_calculated ||= controls_placement || Avo.configuration.resource_controls_placement
end

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

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

private

def resource_controls_render_on_both_sides?
controls_placement_calculated == :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
2 changes: 2 additions & 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 Expand Up @@ -78,6 +79,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