Skip to main content

RecordPage

Trait RecordPage 

Source
pub trait RecordPage<R>:
    Sized
    + Send
    + Sync
    + 'static
where R: Resource,
{ // Required method fn render( cx: &Cx, record: <R as Resource>::Model, ) -> impl Future<Output = Result<impl View, Error>> + Send; // Provided method fn declare() -> RecordPageDef<<R as Resource>::Model> { ... } }
Expand description

A page about one record of the resource R, served at {list}/{key}/{slug} and linked from the record’s navigation: the tab bar its detail page, edit page, record pages and relation tabs share. The panel loads the record and checks the request may open the page; the page renders its body.

use tablo_core::RecordPage;
use topcoat::{
    Result,
    context::Cx,
    view::{View, view},
};

struct OrderHistoryPage; // GET /admin/orders/{key}/order-history

impl RecordPage<OrderResource> for OrderHistoryPage {
    async fn render(cx: &Cx, order: Order) -> Result<impl View> {
        Ok(view! { <p>"Order " (order.number)</p> })
    }
}

A request reaches render only through the checks the detail page makes: sign-in, the request’s tenant, the resource’s query, and Ability::View of the record; then RecordPageDef::access. A trashed record opens too, as it does on its detail page.

A form the page renders posts to an app route, which none of those checks cover: the route loads the record through scoped_query and asks the policy itself.

Required Methods§

Source

fn render( cx: &Cx, record: <R as Resource>::Model, ) -> impl Future<Output = Result<impl View, Error>> + Send

Renders the page’s body under the record’s header, from the record as the resource’s query loads it, with the relations its include_unscoped names and no other.

The record arrives whole: a field a ResourceDef::field_access rule hides from the request is still on it, so a page that shows such a field asks can_view_field first.

Provided Methods§

Source

fn declare() -> RecordPageDef<<R as Resource>::Model>

The page’s slug, label, icon and access. Defaults to RecordPageDef::new: every default.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§