Skip to main content

ActionDef

Struct ActionDef 

Source
pub struct ActionDef<R: Resource> { /* private fields */ }
Expand description

What an Action declares besides its name, input and body: where its button renders, how it reads on each record, and which records it runs on. Every setting has a default, so ActionDef::new alone is a button on each row, page header and the bulk bar, labelled after the action’s NAME, that runs on every record the policy allows.

let def = ActionDef::<PostResource>::new()
    .places(Places::ROW.with(Places::DETAIL))
    .icon(tablo_ui::icons::CHECK)
    .color(Color::Success)
    .can_run(|_cx, post: &Post| post.status != "published")
    .disabled_reason(|_cx, _post| Some("Already published".into()));

Implementations§

Source§

impl<R: Resource> ActionDef<R>

Source

pub fn new() -> Self

Every default: a gray button on each row, page header and the bulk bar, labelled after the action’s NAME, running without confirmation on every record the policy allows.

Source

pub fn places(self, places: Places) -> Self

Where the button renders. Defaults to Places::ALL: each row, the detail and edit pages’ headers, and the bulk bar.

It decides where the button shows, not who may run it: the record route serves an action placed on any of Places::RECORD, and the bulk route one placed on Places::BULK; any other POST answers 404. A place no page renders shows the button nowhere: Places::EDIT on a resource without a form, or Places::DETAIL on one that turns its view page off (ResourcePage::View).

Source

pub fn confirm(self) -> Self

Asks first, through a confirmation dialog sharing the delete dialog’s mechanism and destructive wording.

An action with input confirms in its input dialog, or on its input page, instead, which say the action cannot be undone and whose submit renders destructive. An unconfirmed POST that would write answers 400. Both dialogs need JavaScript: without it their buttons do nothing.

Source

pub fn confirmation(self, question: impl Into<Text>) -> Self

Asks first, as confirm does, with question in place of the message tablo-confirm-run, “Run this action?”. An action with input confirms in its input dialog instead, which its label titles.

Source

pub fn icon(self, icon: IconData) -> Self

The icon before the button’s label, in every place. Defaults to none.

Source

pub fn color(self, color: Color) -> Self

The colour the button is tinted in, as Delete’s is in Color::Danger. Defaults to Color::Gray, the untinted button.

It changes how the button looks, not what it asks: confirm asks first.

Source

pub fn label(self, label: impl Into<Text>) -> Self

The button text. Defaults to the message action-{NAME} of the panel’s catalogs, else NAME in sentence case: "publish" reads “Publish”, and "send-invite" reads “Send invite”.

The bulk bar, the input dialogs and the messages read it; a record’s button reads label_for when one is declared.

Source

pub fn label_for( self, label: impl Fn(&Cx, &R::Model) -> Text + Send + Sync + 'static, ) -> Self

The text of the button on one record: its row’s, or its record page’s. Defaults to the label.

Declare it when the record’s state changes what the action reads: “Deactivate” on an active employee, “Activate” on one that is not.

Source

pub fn icon_for( self, icon: impl Fn(&Cx, &R::Model) -> Option<IconData> + Send + Sync + 'static, ) -> Self

The icon of the button on one record, in its row and on its record page. Defaults to the icon.

Source

pub fn tooltip(self, tooltip: impl Into<Text>) -> Self

The hint a row’s button shows on hover, for an action whose label says too little. Defaults to none.

A button refused on its record shows its disabled_reason instead.

Source

pub fn can_run( self, check: impl Fn(&Cx, &R::Model) -> bool + Send + Sync + 'static, ) -> Self

Whether the action itself runs on a record, wherever it is mounted: a published post refuses “publish”. Defaults to every record.

It is one half of Ability::Run, which the resource allows only when both this and its policy do: can answers the two together. Who may run the action belongs in the policy, which each panel mounts its own; a rule written here holds on every panel and cannot be lifted by one. Asking can for this action’s own Run from here would ask this closure again.

Source

pub fn disabled_reason( self, reason: impl Fn(&Cx, &R::Model) -> Option<Text> + Send + Sync + 'static, ) -> Self

Why the button shows disabled on a record can_run refuses, rather than hidden: “Already published” for a published post. Defaults to none, which hides it.

It is asked only of a record the policy lets the user view and run the action on, so the reason speaks to the record’s state and never tells a user what the policy refuses them. The route refuses a disabled record as it refuses one can_run hides.

Source

pub fn success( self, message: impl Fn(usize) -> Text + Send + Sync + 'static, ) -> Self

The success notification after a commit that ran on count records. Defaults to the label and the record count: "Publish: 3 records". A bulk run the action refused on some records appends their count out of the selection: "Publish: 3 records (2 of 5 skipped)".

Trait Implementations§

Source§

impl<R: Resource> Debug for ActionDef<R>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<R: Resource> Default for ActionDef<R>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<R> !RefUnwindSafe for ActionDef<R>

§

impl<R> !UnwindSafe for ActionDef<R>

§

impl<R> Freeze for ActionDef<R>

§

impl<R> Send for ActionDef<R>

§

impl<R> Sync for ActionDef<R>

§

impl<R> Unpin for ActionDef<R>

§

impl<R> UnsafeUnpin for ActionDef<R>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more