Skip to content

Infolists ​

infolist() describes a record's view page: which values it shows and how, in the same sections, grids, tabs and splits as forms. Each value is shown by an entry: a status as a colored badge, a code with a copy button, a related record as a link, a number computed on the server, or a component of your own.

Without infolist(), the view page shows the form read-only: the panel makes an infolist from it (see The default view page). Declared, the infolist replaces the form on the view page; everything around it stays: the header and its actions, slots, relation managers and the history.

BuilderAnswersExample
fields()what data exists, who may read or write it (server)Field::column(Code).required()
table()how a field shows in the listTextColumn::make("code")
form()how a field is editedSelectInput::make("grade")
infolist()how a field (or a computed value) shows on the view pageTextEntry::make("grade").badge()

Quick start ​

rust
fn infolist() -> Infolist {
    Infolist::new().columns(2).schema(components![
        Section::make("Order").schema(components![
            TextEntry::make("number").copyable(),
            TextEntry::make("status").badge().color("paid", "success").color("refunded", "danger"),
            TextEntry::make("placed_at"),
            RelationEntry::make("customer_id"),
        ]),
        ComputedEntry::make("total").number(2),
        CustomEntry::make("route", "acme/map"),
    ])
}

The demo's categories show their slug with its prefix, the number of their posts, and their color drawn by an extension:

rs
/// The view page: the slug with its prefix, the number of posts (computed),
/// and the color drawn by the demo's `demo/swatch` entry.
fn infolist() -> Infolist {
    Infolist::new().width(FormWidth::Full).schema(components![
        Split::make()
            .main(components![
                TextEntry::make("name").copyable(),
                TextEntry::make("slug").prefix("/categories/"),
                ComputedEntry::make("posts_count").label("Posts").number(0),
                TextEntry::make("layout").options(vec![("posts", "Its posts"), ("link", "A link")]),
                TextEntry::make("link_url").label("Link").url().shown_when(when("layout").eq("link")),
                // Its posts under it, as the relation's section lists them.
                RepeatableEntry::make("posts")
                    .label("Its posts")
                    .relationship()
                    .limit(10)
                    .schema(components![TextEntry::make("title"), BooleanEntry::make("published")])
                    .shown_when(when("layout").eq("posts")),
                // The highlights (a virtual field), drawn by the demo's entry script.
                CustomEntry::make("highlights", "demo/highlights").shown_when(when("layout").eq("posts")),
            ])
            .aside(components![
                Section::make("Display").compact().schema(components![CustomEntry::make("color", "demo/swatch"),])
            ])
    ])
}

/// Counted through the posts resource: its scope and policy apply, so a
/// user only counts the posts they may list (a failure shows "not available").
fn computed() -> Vec<Computed<category::Entity>> {
    vec![Computed::make("posts_count", |ctx, category: &category::Model| {
        Box::pin(async move {
            let query = ListQuery {
                parent: Some(("category_id".to_owned(), category.id.to_string())),
                per_page: Some(1),
                ..Default::default()
            };
            Ok(json!(ctx.records("posts", &query).await?.meta.total))
        })
    })]
}

Entries are presentation only. An entry for a field the user may not read is left out of the page (a section left empty disappears with it); entries never write and grant nothing.

Entries ​

An entry names a field of the resource, except ComputedEntry, which names a computed value. Every entry takes label, help, column_span and shown_when.

EntryForOptions
TextEntrytext, numbers, dates, JSON listsbadge() with color(value, color), copyable(), limit(chars), url(), number(decimals), list(), multiline(), password(), prefix(), suffix(), options([(value, label)]), date_format(pattern)
RelationEntrybelongs_to fieldsnone
BooleanEntryboolean columnslabels(yes, no), color(true, color)
KeyValueEntrykey/value fieldsnone
MediaEntrymedia fieldssize(pixels), preview(false) (images do not open the image viewer); gallery() is deprecated: images open in the viewer by default
RichTextEntryrich text fieldsoutline()
ComputedEntrya computed valuethe display options of TextEntry
CustomEntryany field, computed value or virtual fieldprops(json)
RepeatableEntrya JSON field holding rows (repeaters), or with relationship() a has-many relation's recordsschema(components![…]): the entries of each row; relationship(), limit(n)
  • Dates and times follow the field's kind: dates in the user's language, instants in their time zone. date_format("d MMMM yyyy") on the entry of a date field, or the panel's pattern, writes them as a date format says (not on computed values, row keys or panel pages' data, which have no declared kind).
  • Colors are primary, info, success, warning, danger and gray (the default), as in tables.
  • url() links only http and https values; anything else (a javascript: text a user typed) is shown as text. Links open in a new tab.
  • limit(chars) cuts the text and shows the whole of it as a tooltip.
  • RelationEntry shows the related record's title, linked to its page when the user may list that resource. A related record the user may not view shows as #key, without a link.

Rows ​

RepeatableEntry shows each row of a JSON list with its own entries, which name keys of the row: TextEntry, BooleanEntry, KeyValueEntry, MediaEntry (a row's files), RichTextEntry (a row's document), CustomEntry, and a nested RepeatableEntry (three deep at most).

rust
RepeatableEntry::make("faq").schema(components![
    TextEntry::make("question"),
    BooleanEntry::make("pinned").labels("Pinned", "Not pinned"),
])

With relationship(), the rows are the records of the has-many relation of the entry's name, read as its section reads them (the child's scope, view policy and read rules, the relation's filters), sorted by the order column of the form's repeater when the child's lists may sort by it (sortable()), else in the list's order. Each row's entries name fields of the child (checked at boot with the child's fields; those the user may not read are left out). At most limit(n) rows (100 by default and at most), then a link to the relation's section. A user who may not list the child, or may not read the fields a filtered relation filters on, does not see the entry. Conditions in its rows read the row and, with when_root, the record. The demo's categories show their posts this way:

rs
// Its posts under it, as the relation's section lists them.
RepeatableEntry::make("posts")
    .label("Its posts")
    .relationship()
    .limit(10)
    .schema(components![TextEntry::make("title"), BooleanEntry::make("published")])
    .shown_when(when("layout").eq("posts")),

A category's view page: its posts listed under it, each with its title and whether it is publishedA RustCMS demo application: relationship rows on a view page.

Conditions ​

shown_when works as in forms (see Showing inputs under conditions), evaluated on the stored values. A condition names another entry of the infolist, or a field of the form (compared with its kind); a section's condition applies to everything in it.

On the default view page (no infolist()), conditions read fields as the edit form does: the value the form would hold (a write-only toggle is false, a field not sent is empty), and null for a field the form hides under its own conditions, so the page shows what the edit form shows.

rust
KeyValueEntry::make("attributes").shown_when(when("published").is_true())

On a view page, hiding is presentation, not protection: every value the user may read comes with the record anyway. Protect data with field rules, not conditions.

The default view page ​

A resource without infolist() gets one made from its form, once at boot, in the form's sections, grids, tabs and splits. Each input becomes the entry that shows its value:

InputEntry
TextInput, Textarea, NumberInputTextEntry (line breaks kept; a password input masked; prefix and suffix kept)
SelectInput with options, CheckboxListTextEntry with the option labels (a list for CheckboxList)
SelectInput of a belongs_to fieldRelationEntry: the related record's title, a link when the user may list that resource
Toggle, Checkbox on a boolean columnBooleanEntry (yes or no)
DatePicker, DateTimePickerTextEntry: the date in the user's language
KeyValue, FileUpload (media), RichEditorKeyValueEntry, MediaEntry, RichTextEntry
Repeater (JSON)RepeatableEntry, each row's inputs as entries
Repeater with relationship()RepeatableEntry of the relation's records, each row's inputs as entries
CustomInputTextEntry (a form widget draws no view; declare a CustomEntry for one)
VirtualInputa CustomEntry of its widget, drawn by the field's view (nothing without one)
Hidden, BelongsToManySelect, secretsnothing (links show in their relation sections; an encrypted field shows nothing, not even whether it is set)

An input whose entry does not fit its field (a Toggle on a number column) is shown as text. Labels, column spans and conditions come from the inputs; help texts do not. Fields the user may not read are left out, as everywhere. To show a value differently, declare an infolist(): it replaces this one as a whole.

Computed values ​

A computed value is not a column: the server computes it from the record each time the view page opens, then a ComputedEntry of the same name shows it.

rust
fn computed() -> Vec<Computed<order::Entity>> {
    vec![
        Computed::make("total", |ctx, order: &order::Model| {
            Box::pin(async move { Ok(json!(order_service::total(&ctx.db, order.id).await?)) })
        }),
        Computed::make("margin", |ctx, order: &order::Model| {
            Box::pin(async move { Ok(json!(finance::margin(&ctx.db, order.id).await?)) })
        })
        .readable(|ctx| ctx.can("orders.finance"))
        .timeout(Duration::from_secs(15)),
    ]
}
  • The closure gets the typed model; annotate it (order: &order::Model) when you read its fields.
  • Values run only for a user who may view the record, after the policy allowed it, and only when its view page opens: never for lists, exports or the result of a write. They are never stored.
  • The page loads them alongside the record (one request for all of them), so a slow value does not delay the rest of the page.
  • A failure stays in its entry. An error, a value over 64 KiB, or one that takes longer than its time limit shows "Not available"; the other entries are unaffected, and the server logs a warning naming the value. The limit is 5 seconds unless .timeout(…) says otherwise (at most 30).
  • Restrict what an aggregate discloses. A total or a count can reveal more than the fields it reads. .readable(…) hides the value, and skips computing it, for users who may not see it. To count related records as the user sees them, go through ctx.records(…): their scope and policy apply (the demo counts a category's posts that way).
  • Keep them light: one query, not one per related row. Each user may open 60 view pages with computed values a minute and compute 2 at once, and 8 pages compute at once across users; beyond that the values show "Not available" until the next load.
  • The time limit stops a value at its next .await. Work that blocks a thread (CPU loops, blocking I/O) keeps it busy past the limit, and work moved to spawn_blocking keeps running after the page gave up waiting, outside the limits on pages computing at once. Keep computed values to short queries; compute anything heavy in a job and show the stored result.

Custom entries ​

CustomEntry::make(field, "vendor/name") draws the value with a component your extension registers. With the React SDK (ui 3):

tsx
/** A category's color on its view page (`CustomEntry::make("color", "demo/swatch")`). */
function Swatch(props: EntryProps<string | null>) {
  // A stored value reaches CSS only once checked: a hex color, nothing else.
  if (!props.value || !/^#[0-9a-f]{6}$/i.test(props.value)) {
    return <span className="demo-swatch-none">{props.t("No color")}</span>;
  }
  return (
    <span className="demo-swatch">
      <span className="demo-swatch-chip" style={{ backgroundColor: props.value }} aria-hidden="true" />
      <code>{props.value}</code>
    </span>
  );
}

registerEntry("demo/swatch", Swatch);

The component gets the value, the record's readable fields, the entry's props and the usual t and locale. Until the script is loaded, or if it fails, the value is shown as text; a virtual field without a registered entry is drawn by its field's view instead. A script without the SDK registers with window.rustcms.registerEntry(name, view) (see custom fields).

Panel pages ​

A panel page can show its data with entries, without a script: PageView::Infolist names the entries, data() gives the values by entry name.

rust
fn view() -> PageView {
    PageView::Infolist(|| {
        Infolist::new().schema(components![Section::make("Totals").schema(components![
            TextEntry::make("courses").number(0),
            BooleanEntry::make("healthy").labels("Healthy", "Degraded"),
        ])])
    })
}

async fn data(_ctx: &Ctx) -> AppResult<Value> {
    Ok(json!({"courses": 3, "healthy": true}))
}

Panel pages use TextEntry, BooleanEntry, KeyValueEntry and CustomEntry (the others need a record), and conditions with filled() only (the values have no declared kind). React pages draw the same entries with the SDK's Infolist component.

Boot checks ​

The application refuses to start when an entry names no field (or, for a ComputedEntry, no computed value; a CustomEntry may also name a virtual field); an entry does not fit its field (a RelationEntry on a field without belongs_to, a BooleanEntry on text); an option does not fit the entry (badge on a boolean, number on text, color on text without badge, date_format on another entry than TextEntry, or on a field that is not a date); the field is encrypted; an entry appears twice; a custom entry's name is not vendor/name or its props exceed 4 KiB; a condition breaks the rules of forms; an infolist holds an input or a form holds an entry; a computed value has a field's name, is declared twice, or has a time limit over 30 seconds.

RustCMS 0.17.0 · source cfb82fa33fab · MIT OR Apache-2.0