Skip to content
Merged
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
4 changes: 2 additions & 2 deletions app/components/avo/index/table_row_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<%# 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,
id: "#{self.class.to_s.underscore}_#{@resource.record.to_param}",
id: "#{self.class.to_s.underscore}_#{@resource.record_param}",
class: class_names("group bg-white hover:bg-gray-50 z-21 border-b", {"cursor-pointer": click_row_to_view_record}),
data: {
index: @index,
component_name: self.class.to_s.underscore,
resource_name: @resource.class.to_s,
record_id: @resource.record.id,
record_id: @resource.record_param,
**(click_row_to_view_record ? {
visit_path: helpers.resource_show_path(resource: @resource, parent_resource: @parent_resource, parent_record: @parent_record, parent_or_child_resource:),
action: "click->table-row#visitRecord keydown.enter->table-row#visitRecord keydown.space->table-row#visitRecord"
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/avo/actions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,15 @@ def get_messages
end

def decrypted_index_query
@decrypted_index_query ||= if (encrypted_query = action_params[:fields]&.dig(:avo_index_query)).present?
@decrypted_index_query ||= if encrypted_query.present? && encrypted_query != "select_all_disabled"
Avo::Services::EncryptionService.decrypt(message: encrypted_query, purpose: :select_all, serializer: Marshal)
end
end

def encrypted_query
@encrypted_query ||= action_params[:fields]&.dig(:avo_index_query)
end

def flash_messages
get_messages.each do |message|
flash[message[:type]] = message[:body]
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/avo/base_application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def set_related_resource
end

def set_record
id = if @resource.model_class.primary_key.is_a?(Array) && params.respond_to?(:extract_value)
id = if @resource.model_class.try(:primary_key).is_a?(Array) && params.respond_to?(:extract_value)
params.extract_value(:id)
else
params[:id]
Expand Down
11 changes: 10 additions & 1 deletion lib/avo/resources/array_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,17 @@ def fetch_records(array_of_records = nil)
array_of_records = records_from_field_or_record || array_of_records
end

@fetched_records ||= if is_array_of_active_records?(array_of_records)
@fetched_records ||= if array_of_records.empty?
array_of_records
elsif is_array_of_active_records?(array_of_records)
@@model_class = array_of_records.first.class
@@model_class.where(id: array_of_records.map(&:id))
elsif is_active_record_relation?(array_of_records)
@@model_class = array_of_records.try(:model)
array_of_records
elsif is_array_of_store_model?(array_of_records)
@@model_class = array_of_records.first.class
return(array_of_records)
else
# Dynamically create a class with accessors for all unique keys from the records
keys = array_of_records.flat_map(&:keys).uniq
Expand Down Expand Up @@ -99,6 +104,10 @@ def is_active_record_relation?(array_of_records = records)
@is_active_record_relation ||= array_of_records.is_a?(ActiveRecord::Relation)
end

def is_array_of_store_model?(array_of_records = records)
@is_array_of_store_model ||= defined?(StoreModel::Model) && array_of_records.all? { |element| element.is_a?(StoreModel::Model) }
end

def resource_type_array? = true

def sort_by_param = nil
Expand Down
2 changes: 1 addition & 1 deletion spec/system/avo/has_many_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def destroy
expect(page).to have_css('div[data-field-id="patrons"] div[data-target="tag-component"]', text: user.name)

# Find user name on has many field
within("tr[data-record-id='#{user.id}']") do
within("tr[data-record-id='#{user.to_param}']") do
expect(page).to have_text(user.first_name)
expect(page).to have_text(user.last_name)
end
Expand Down
Loading