-
-
Notifications
You must be signed in to change notification settings - Fork 270
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
Avo with ActiveModel #3680
Comments
Apologies for the harsh language. I will keep an eye on the ticket, but will be giving ActiveAdmin another try in the mean time. |
Hey @rkh. Thanks for looking into Avo.
We are open to add support to more edge-cases. We did in the past for many developers. If you send in a better description of your particular case we would know better how to support it. A reproduction repository is the best way.
I'm actually curious about how you tried to use the Array driver.
|
I do apologize for the outburst, that was absolutely not appropriate. Avo looks much more modern than the other popular alternatives. And from a maintenance point with the pitch of us not having to put too much work into an admin UI, I do actually quite like that there's a paid option. Though that also makes me hesitant to contribute to the code base itself. I will look into a repository to reproduce things. I've been trying to use it in two ways:
Example display names: {
"de": {
"self": { "long": "Vila", "short": "Vila" },
"admin1": { "long": "Encamp", "short": "Encamp" }
},
"en": {
"self": { "long": "Vila", "short": "Vila" },
"admin1": { "long": "Encamp", "short": "Encamp" }
}
} What I triedLocationHere's a "normal" resource (shortened the file): class Avo::Resources::Location < Avo::BaseResource
self.title = -> {
name = record.display_names.dig("en", "self", "long") || record.geoname_name
name
}
def fields
field :id, as: :id, link_to_resource: true, sortable: true
field :type, as: :text, sortable: true
field :name, only_on: [:index], &self.title
# TODO broken:
# field :country, as: :belongs_to
# Alternative:
field :country_code, as: :text, sortable: true, format_using: -> {
next unless value and country = ISO3166::Country[value]
[country.emoji_flag, value, "(#{country.translation("en")})"].join(' ')
}
# TODO broken:
# field :timezone, as: :belongs_to
# Alternative also broken:
# field(:timezone, as: :array) { [value] }
field(:timezone, as: :string) { value.iana }
# FIXME: broken
field :display_names, as: :array do
Avo::Resources::DisplayName.generate(tz.display_names)
end
# ... more fields here ...
end
end Timezone# This does not work as it *sometimes* overrides ::Timezone
class Avo::Resources::Timezone < Avo::Resources::ArrayResource
self.record_selector = false
# only load ids for performance reasons
def records = ::Timezone.all.map {{ id: _1.id }}
def fields
tz = ::Timezone.find(record.id)
field :id, as: :id
# Note: sortable has no effect
%i[iana bcp47 base_utc_offset meta_zone].each do |attribute|
field(attribute, as: :text, sortable: true) { tz.public_send(attribute) }
end
field :display_names, as: :array do
# this does not work, because loading DisplayName gives an error
Avo::Resources::DisplayName.generate(tz.display_names)
end
end
end Display names# Does not work at all, as it fails to define a constant named `::Display name`
class Avo::Resources::DisplayName < Avo::Resources::ArrayResource
def self.generate(value)
value.display_names.flat_map do |language, display_names|
display_names.flat_map do |type, formats|
formats.flat_map do |style, name|
{
id: "#{value.id}/#{language}/#{type}/#{style}",
language:, type:, style:, name:
}
end
end
end
end
def records
# empty array does not work, will still trigger a db request
[{ id: nil }]
end
def fields
field :id, as: :id
field :language, as: :text
field :type, as: :text
field :name: as: :text
end
end |
All good @rkh. Let us have a look next week and see how we can improve some things. |
Hi @rkh, Two of the issues that you mentioned have already been resolved and released in Regarding the performance concerns and the sortable notes, we'll update the documentation to clarify that the array resource currently does not support sorting, and performance on large datasets might be suboptimal. Caching is one of the possibles solutions. I noticed your comment about looking into a reproduction repository. If you could provide a minimal reproduction repository along with clear steps to replicate each of the remaining issues you're encountering, that would be great. Thank you! |
Thanks. I'll give it another go, probably next week, and see how well things work. Then, I'll decide if a repro repo is worth your time and mine and whether we'll move forward with Avo. Very happy with how responsive you've been! |
Was evaluating Avo with plans to get a paid license, initial attempt seemed good, but ran into issues with using it for models that aren't backed by ActiveRecord.
I thought Array Resources would be the way to go, but they aren't.
id
field in the hash and then usingwhere
on a class it defined itself, that doesn't implement it?Display name
class for a resource calledDisplayName
Are there any plans to support models not backed by the database?
Is there any documentation on how to avoid Avo defining classes outside the
Avo
namespace?The text was updated successfully, but these errors were encountered: