Discreet Information
Sometimes you need to have some information available on the record page, but not necesarily front-and-center. This is where the Discreet Information option is handy.
# app/avo/resources/post.rb
class Avo::Resources::Post < Avo::BaseResource
self.discreet_information = [
:timestamps,
{
tooltip: -> { sanitize("Product is <strong>#{record.published_at ? "published" : "draft"}</strong>", tags: %w[strong]) },
icon: -> { "heroicons/outline/#{record.published_at ? "eye" : "eye-slash"}" }
},
{
label: -> { record.published_at ? "🚀" : "😬" },
url: -> { "https://avohq.io" },
url_target: :_blank
}
]
end
Display the id
To save field space, you can use the discreet information area to display the id of the current record.
Set the option to the :id
value and the id will be added next to the title.
# app/avo/resources/post.rb
class Avo::Resources::Post < Avo::BaseResource
self.discreet_information = :id
# fields and other resource configuration
end
You can alternatively use :id_badge
to display the id as a badge.
Display the created_at
and updated_at
timestamps
The reason why we built this feature was that we wanted a place to display the created and updated at timestamps but didn't want to use up a whole field for it. That's why this is the most simple thing to add.
Set the option to the :timestamps
value and a new icon will be added next to the title. When the user hovers over the icon, they will see the record's default timestamps.
# app/avo/resources/post.rb
class Avo::Resources::Post < Avo::BaseResource
self.discreet_information = :timestamps
# fields and other resource configuration
end
If the record doesn't have the created_at
or updated_at
attributes, they will be ommited.
You can alternatively use :timestamps_badge
to display the timestamps as a badge.
Options
You may fully customize the discreet information item by taking control of different options. To do that, you can set it to a Hash
with various keys.
# app/avo/resources/post.rb
class Avo::Resources::Post < Avo::BaseResource
self.discreet_information = {
tooltip: -> { "Product is #{record.published_at ? "published" : "draft"}" },
icon: -> { "heroicons/outline/#{record.published_at ? "eye" : "eye-slash"}" }
url: -> { main_app.post_path record }
}
end
-> tooltip
Use the tooltip
option to set the body of the tooltip.
# app/avo/resources/post.rb
class Avo::Resources::Post < Avo::BaseResource
self.discreet_information = {
tooltip: -> { "Product is #{record.published_at ? "published" : "draft"}" },
}
end
You may return HTML for that tooltip but don't forget to sanitize the output.
# app/avo/resources/post.rb
class Avo::Resources::Post < Avo::BaseResource
self.discreet_information = {
tooltip: -> { sanitize("Product is <strong>#{record.published_at ? "published" : "draft"}</strong>", tags: %w[strong]) },
icon: "heroicons/outline/academic-cap"
}
end
-> url
The url
option will transform the icon into a link.
# app/avo/resources/post.rb
class Avo::Resources::Post < Avo::BaseResource
self.discreet_information = {
tooltip: -> { "Product is #{record.published_at ? "published" : "draft"}" },
icon: "heroicons/outline/academic-cap",
url: -> { main_app. }
}
end
-> as
The as
option specifies the type of representation. Currently, only :badge
is supported, but additional types may be introduced in the future.
# app/avo/resources/post.rb
class Avo::Resources::Post < Avo::BaseResource
self.discreet_information = {
tooltip: -> { "Product is #{record.published_at ? "published" : "draft"}" },
icon: "heroicons/outline/academic-cap",
url: -> { main_app. },
as: :badge
}
end
Display multiple pieces of information
You can use it to display one or more pieces of information.
Information properties
Each piece of information has a fe
Full configuration
# app/avo/resources/post.rb
class Avo::Resources::Post < Avo::BaseResource
self.discreet_information = [
:timestamps,
{
tooltip: -> { sanitize("Product is <strong>#{record.published_at ? "published" : "draft"}</strong>", tags: %w[strong]) },
icon: -> { "heroicons/outline/#{record.published_at ? "eye" : "eye-slash"}" }
},
{
label: -> { record.published_at ? "✅" : "🙄" },
url: -> { "https://avohq.io" },
url_target: :_blank
}
]
# fields and other resource configuration
end