Discreet Information API
Per-option reference for discreet_information. For task-oriented documentation and worked examples, see the Discreet Information guide.
The option is set on the resource class and accepts a single item or an array of items. Each item is a preconfigured symbol or a Hash of the custom item options below:
class Avo::Resources::Post < Avo::BaseResource
self.discreet_information = [
:timestamps,
{
# custom item options listed below
}
]
end- Type: Symbol, Hash, or Array of Symbols/Hashes
- Default:
nil— nothing is rendered
Preconfigured items
-> :id
Displays the record's ID as a key-value pair labeled ID.
self.discreet_information = :id-> :timestamps
Displays an icon next to the record title. Hovering over it reveals the record's created_at and updated_at timestamps in a tooltip.
self.discreet_information = :timestampsIf the record has neither a created_at nor an updated_at value, the item is omitted.
-> :created_at
Displays the record's created_at timestamp as a key-value pair. Omitted when the record has no created_at value.
self.discreet_information = :created_at-> :updated_at
Displays the record's updated_at timestamp as a key-value pair. Omitted when the record has no updated_at value.
self.discreet_information = :updated_atCustom item options
Every option below accepts a static value or a block. Blocks are evaluated in an ExecutionContext with access to record, resource, view, and the rest of the common objects.
-> as
The type of representation for the item.
self.discreet_information = {
as: :badge,
text: "Draft"
}| Value | Behavior |
|---|---|
:text | Plain text, with an optional leading icon (default) |
:icon | An icon only; pair with icon and a title tooltip |
:badge | A badge containing text, with an optional leading icon |
:key_value | A key/value pair |
- Type: Symbol
- Default:
:text
-> text
The text displayed by :text and :badge items.
self.discreet_information = {
as: :badge,
text: -> { record.published_at ? "Published" : "Draft" }
}- Type: String or Proc
- Default:
nil
-> title
The body of the tooltip shown when hovering over the item.
self.discreet_information = {
title: -> { "Product is #{record.published_at ? "published" : "draft"}" }
}You may return HTML, but don't forget to sanitize the output:
self.discreet_information = {
title: -> { sanitize("Product is <strong>#{record.published_at ? "published" : "draft"}</strong>", tags: %w[strong]) }
}- Type: String or Proc
- Default:
nil
-> icon
The icon displayed with the item.
self.discreet_information = {
icon: "tabler/outline/bulb"
}-> url
Turns the item into a link pointing at this URL.
self.discreet_information = {
icon: "tabler/outline/external-link",
url: -> { main_app.post_path record }
}- Type: String or Proc
- Default:
nil— the item is not a link
-> target
The target attribute of the link. Only relevant together with url.
self.discreet_information = {
url: -> { main_app.post_path record },
target: :_blank
}- Type: Symbol or String
- Default:
nil - Values:
:_blank,:_self,:_parent,:_top— forwarded verbatim to the link
-> data
Data attributes attached to the item's wrapper element — the link when url is set, a plain element otherwise.
self.discreet_information = {
url: -> { main_app.post_path record },
data: {turbo_frame: :some_frame}
}- Type: Hash or Proc
- Default:
nil
-> key
The key displayed by a :key_value item.
self.discreet_information = {
as: :key_value,
key: "Status:",
value: -> { record.published_at ? "published" : "draft" }
}- Type: String or Proc
- Default:
nil
-> value
The value displayed by a :key_value item.
self.discreet_information = {
as: :key_value,
key: "Status:",
value: -> { record.published_at ? "published" : "draft" }
}- Type: String or Proc
- Default:
nil
-> visible
Whether the item is rendered.
self.discreet_information = {
as: :badge,
text: "Draft",
visible: -> { record.published_at.nil? }
}- Type: Boolean or Proc
- Default:
true— omitting the option renders the item