Skip to content

Commit

Permalink
Merge branch 'main' into fix/resource_fails_to_show_when_title_is_num…
Browse files Browse the repository at this point in the history
…eric
  • Loading branch information
Paul-Bob authored Sep 3, 2024
2 parents c76c223 + c060eb3 commit b18f1c6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
16 changes: 16 additions & 0 deletions app/components/avo/index/resource_table_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def encrypted_query
end

Avo::Services::EncryptionService.encrypt(message: @query, purpose: :select_all, serializer: Marshal)
rescue
disable_select_all
end

def selected_page_label
Expand Down Expand Up @@ -86,4 +88,18 @@ def generate_table_row_components

[header_fields, table_row_components]
end

private

def disable_select_all
if Rails.env.development?
Avo.error_manager.add({
url: "https://docs.avohq.io/3.0/select-all.html#serialization-known-issues",
target: "_blank",
message: "An error occurred while serializing the query object. The Select All feature has been disabled because it depends on successful query serialization. For more details and troubleshooting steps, click here."
})
end

:select_all_disabled
end
end
11 changes: 8 additions & 3 deletions lib/avo/concerns/model_class_constantized.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ module ModelClassConstantized
class_methods do
# Cast the model class to a constantized version and memoize it like that
def model_class=(value)
@model_class = case value
@model_class = value
end

# Cast the model class to a constantized version
def constantized_model_class
@constantized_model_class ||= case @model_class
when Class
value
@model_class
when String, Symbol
value.to_s.safe_constantize
@model_class.to_s.safe_constantize
else
raise ArgumentError.new "Failed to find a proper model class for #{self}"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/avo/resources/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def get_model_by_name(model_name)
# where we figure out the model class from the record
def model_class(record_class: nil)
# get the model class off of the static property
return @model_class if @model_class.present?
return constantized_model_class if @model_class.present?

# get the model class off of the record for STI models
return record_class if record_class.present?
Expand Down
7 changes: 7 additions & 0 deletions spec/dummy/app/models/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ class Post < ApplicationRecord

validates :name, presence: true

# Trigger TypeError: no _dump_data is defined for class Proc when serializing query
# Test it by applying a status filter
# Only for rails > 7.1
# normalizes :status, with: ->(status) {
# status
# }

has_one_attached :cover_photo
has_one_attached :audio
has_many_attached :attachments
Expand Down

0 comments on commit b18f1c6

Please sign in to comment.