Skip to content

Commit

Permalink
refactor show/hide seaech field
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianthedev committed Mar 21, 2023
1 parent a080578 commit 28d85ba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/components/avo/views/resource_index_component.html.erb
Expand Up @@ -31,7 +31,7 @@
<% end %>
<% c.body do %>
<div class="flex flex-col xs:flex-row xs:justify-between space-y-2 xs:space-y-0 py-4 <%= 'hidden' if @resource.search_query.nil? && @filters.empty? && available_view_types.count <= 1 %>">
<% unless hide_search_input %>
<% if show_search_input %>
<div class="flex items-center px-4 w-64">
<%= render partial: 'avo/partials/resource_search', locals: {resource: @resource.route_key, via_reflection: via_reflection} %>
</div>
Expand Down
17 changes: 11 additions & 6 deletions app/components/avo/views/resource_index_component.rb
Expand Up @@ -124,14 +124,19 @@ def description
@resource.resource_description
end

def hide_search_input
def show_search_input
return false unless authorized_to_search?
return false unless @resource.search_query.present?
return false if field&.hide_search_input

true
end

def authorized_to_search?
# Hide the search if the authorization prevents it
if @resource.authorization.has_action_method?("search")
return true unless @resource.authorization.authorize_action("search", raise_exception: false)
end
return true unless @resource.search_query.present?
return true unless @resource.authorization.has_action_method?("search")

field&.hide_search_input || false
@resource.authorization.authorize_action("search", raise_exception: false)
end

private
Expand Down

0 comments on commit 28d85ba

Please sign in to comment.