<%# locals: (collection:) -%> <% resource_class = collection.resource_class resources = collection.records.to_a record_actions = collection.actions.collection_record_actions search_object = collection.search_object fields = collection.fields pager = collection.pager collection_actions = @collection.actions.collection_actions.permitted_for(current_policy) table_rounding = search_object.scope_definitions.present? ? :bottom : :all -%> <%= render_component :table_toolbar, resource_class:, search_object:, actions: collection_actions %> <% if search_object.scope_definitions.present? %> <% name = name.to_s current_scope = resource_query_params[:scope] %> <%= render_component :block, rounded: :top do %> <% end %> <% end %> <%= render_component :block, id: "resource-table-container", scroll: :x, rounded: table_rounding, data: { controller:"scroll-preserver", action: "scroll->scroll-preserver#scrolled" } do %> <% unless resources.any? %> <%# empty card %>
<%= render_component :empty_card, message: "No #{resource_name_plural(resource_class).downcase} match your query" do if current_policy.create? render_component :button, label: "Create #{resource_name(resource_class)}", to: resource_url_for(resource_class, action: :new), color: :primary end end %>
<% else %> <%# table %> <%= render_component :table, rows: resources do |table| %> <% table.with_actions do |resource| %> <% record_actions.permitted_for(policy(resource)).values.each do |action| %> <%= table_action_button resource, action %> <% end %> <% end %> <% fields.each do |name, field| %> <% table.column(name:, label: field.label, search_object: search_object) do |resource| %> <%= field.render self, resource %> <% end %> <% end %> <% end %> <%# pagination %> <% if pager.present? %> <%= render_component :pagination, pager: pager %> <% end %> <% end %> <% end %>