Skip to main content

HeaderAction

Trait HeaderAction 

Source
pub trait HeaderAction: 'static {
    type Input: FormInput;

    const NAME: &'static str;

    // Required method
    fn run(
        cx: &Cx,
        input: Self::Input,
        ex: &mut dyn Executor,
    ) -> impl Future<Output = Result<Outcome, WriteError<Self::Input>>> + Send;

    // Provided methods
    fn declare() -> HeaderActionDef { ... }
    fn validate_input(
        _cx: &Cx,
        _input: &Self::Input,
    ) -> FieldErrors<Self::Input> { ... }
    fn submits(submits: Submits<Self::Input>) -> Submits<Self::Input> { ... }
}
Expand description

A mutation that acts on no record, run from a button in a page’s header: “import posts”, “clear the cache”, “recompute the totals”.

A resource declares one with ResourceDef::header_action, and its list page renders the button; a Page declares one with PageDef::header_action, and renders the buttons with header_action_buttons:

struct RecountTags;

impl HeaderAction for RecountTags {
    type Input = ();
    const NAME: &'static str = "recount-tags";

    async fn run(
        _cx: &Cx,
        _: (),
        _ex: &mut dyn Executor,
    ) -> Result<tablo_core::Outcome, tablo_core::WriteError<()>> {
        // Recount through `ex`, the framework's transaction.
        Ok(tablo_core::Outcome::done())
    }
}

The framework owns everything around run, as it does for a record’s Action:

No record is loaded, so nothing scopes run to the request’s tenant: an action over a tenant’s records reads them through scoped_query.

An action that asks for an Input asks for it as a record’s action does, in a dialog or a page titled with its label, and runs on its submit.

Required Associated Constants§

Source

const NAME: &'static str

The action’s URL segment, distinct among the actions of its resource or page.

A name that is not a single path segment does not compile, as for Action::NAME.

Required Associated Types§

Source

type Input: FormInput

What the action asks for before it runs: () for nothing, or an FormInput struct.

Required Methods§

Source

fn run( cx: &Cx, input: Self::Input, ex: &mut dyn Executor, ) -> impl Future<Output = Result<Outcome, WriteError<Self::Input>>> + Send

Perform the action with the parsed input, through the framework’s transaction ex, and say what the response does once it commits: Outcome::done for the HeaderActionDef::success notification, landing back on the list or page.

Refuses the input with WriteError::Refused, or declines with WriteError::declined, as Action::run does.

Provided Methods§

Source

fn declare() -> HeaderActionDef

How the button reads, whether it asks first, and who it runs for beyond the policy or the page’s access. Defaults to HeaderActionDef::new: a gray button labelled after NAME.

The resource or page builds it once, when it adds the action, so it takes no request: HeaderActionDef::can_run receives cx.

Source

fn validate_input(_cx: &Cx, _input: &Self::Input) -> FieldErrors<Self::Input>

Refuse an input run should not receive. Each error names a field of the input, picked off its Keys, and renders under its control, as Action::validate_input does. Defaults to none.

Source

fn submits(submits: Submits<Self::Input>) -> Submits<Self::Input>

The input dialog’s buttons beside the action’s own, each running the action with one checkbox of the input checked, as Action::submits’ do. Defaults to none.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§