Skip to main content

BulkAction

Struct BulkAction 

Source
pub struct BulkAction { /* private fields */ }
Expand description

One action on the records the user ticked in a resource’s list, as Filament’s BulkAction::make($name) in toolbarActions(). The list shows a checkbox on each row and a select of the bulk actions above the table, with an Apply button, as WordPress’s “Bulk actions”. See the module documentation of the row actions for the handler.

ⓘ
RuntimeResource::new("posts", "Posts", "Post", PostData)
    .bulk_action(
        BulkAction::make("trash")
            .label("Move to Trash")
            .authorize(ActionAbility::Delete)
            .hidden(|row| row.get("status") == Some(&json!("trash")))
            .action(|db, user, id, record| Box::pin(async move {
                trash(db, id).await?;
                Ok(Ok(()))
            }))
            .success_notification_title("Moved :count posts to the Trash."),
    )

The form posts at {mount}/{slug}/bulk, with the CSRF token, the action’s name (bulk_action) and the ids of the ticked records (ids[]). The panel checks the token and the user’s ability on the resource (authorize: update by default, or delete), then, for each record, that the user’s query finds it, that the resource’s policy allows the ability on it, and that the action is not hidden for it, and runs the handler. A record that fails any of these, or whose handler refuses with Ok(Err(message)), is reported and the others still run, as WordPress’s “N of M updated”.

Implementations§

Source§

impl BulkAction

Source

pub fn make(name: impl Into<String>) -> Self

An action named name, as Filament’s BulkAction::make('trash'). The name is the value the select posts, so it should be a slug. Its label defaults to the name made readable, as RowAction::make’s.

Source

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

The option’s text in the select, as Filament’s label().

Source

pub fn action<F>(self, handler: F) -> Self
where F: for<'a> Fn(&'a Database, &'a ActingUser, i64, &'a Row) -> RuntimeFuture<'a, ActionResult> + Send + Sync + 'static,

The task run for each selected record, as Filament’s action(): the database, the signed-in user, the record’s id and the record, answering Ok(Ok(())) when done, Ok(Err(message)) to refuse that record, or Err(error) for a database error (that record is reported as failed). Write it as |db, user, id, record| Box::pin(async move { ... }).

Source

pub fn visible( self, rule: impl Fn(&Row) -> bool + Send + Sync + 'static, ) -> Self

Runs the action only on the records for which rule holds, as Filament’s visible() with a $record closure. A selected record for which it does not hold is skipped and reported. Several rules must all hold.

Source

pub fn hidden(self, rule: impl Fn(&Row) -> bool + Send + Sync + 'static) -> Self

Skips the records for which rule holds, as Filament’s hidden().

Source

pub fn authorize(self, ability: ActionAbility) -> Self

The ability the action needs on the resource and on each record, as Filament’s authorize('update') or authorize('delete'). The default is ActionAbility::Update.

Source

pub fn success_notification_title(self, title: impl Into<String>) -> Self

The message shown when the action ran on every selected record, as Filament’s successNotificationTitle(). :count is replaced by the number of records, as a Laravel translation’s :count (Filament takes a closure here): “Changed roles for :count users.”. The default is none.

Source

pub fn name(&self) -> &str

The action’s name.

Source

pub fn get_label(&self) -> String

The option’s text: the label, or the name made readable.

Source

pub fn is_runnable(&self) -> bool

Whether the action has a handler. An action without one is not listed and not run.

Source

pub fn ability(&self) -> ActionAbility

The ability the action needs.

Source

pub fn is_visible(&self, record: &Row) -> bool

Whether the action may run on record: every visibility rule holds.

Source

pub fn success_message(&self, count: usize) -> Option<String>

The success message for count records, if set.

Source

pub async fn run( &self, db: &Database, user: &ActingUser, id: i64, record: &Row, ) -> Result<ActionResult, Error>

Runs the handler on the record id. An action without a handler answers Ok(Err(..)).

Trait Implementations§

Source§

impl Clone for BulkAction

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BulkAction

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for BulkAction

§

impl !UnwindSafe for BulkAction

§

impl Forget for BulkAction

§

impl Freeze for BulkAction
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze, *const ArcInner<dyn for<'a> Fn(&'a Database, &'a ActingUser, i64, &'a Map<String, Value>) -> Pin<Box<dyn Future<Output = Result<Result<(), String>, Error>> + Send + 'a>> + Sync + Send> is !null: Freeze, PhantomData<ArcInner<dyn for<'a> Fn(&'a Database, &'a ActingUser, i64, &'a Map<String, Value>) -> Pin<Box<dyn Future<Output = Result<Result<(), String>, Error>> + Send + 'a>> + Sync + Send>>: Freeze, PhantomData<Arc<dyn Fn(&Map<String, Value>) -> bool + Sync + Send>>: Freeze,

§

impl Move for BulkAction

§

impl Send for BulkAction
where RawVecInner: Send, Arc<dyn for<'a> Fn(&'a Database, &'a ActingUser, i64, &'a Map<String, Value>) -> Pin<Box<dyn Future<Output = Result<Result<(), String>, Error>> + Send + 'a>> + Sync + Send>: Send, Arc<dyn Fn(&Map<String, Value>) -> bool + Sync + Send>: Send,

§

impl Sync for BulkAction
where RawVecInner: Sync, Arc<dyn for<'a> Fn(&'a Database, &'a ActingUser, i64, &'a Map<String, Value>) -> Pin<Box<dyn Future<Output = Result<Result<(), String>, Error>> + Send + 'a>> + Sync + Send>: Sync, Arc<dyn Fn(&Map<String, Value>) -> bool + Sync + Send>: Sync,

§

impl Unpin for BulkAction
where *const u8 is !null: Unpin, Arc<dyn for<'a> Fn(&'a Database, &'a ActingUser, i64, &'a Map<String, Value>) -> Pin<Box<dyn Future<Output = Result<Result<(), String>, Error>> + Send + 'a>> + Sync + Send>: Unpin, Arc<dyn Fn(&Map<String, Value>) -> bool + Sync + Send>: Unpin,

§

impl UnsafeUnpin for BulkAction
where *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, *const ArcInner<dyn for<'a> Fn(&'a Database, &'a ActingUser, i64, &'a Map<String, Value>) -> Pin<Box<dyn Future<Output = Result<Result<(), String>, Error>> + Send + 'a>> + Sync + Send> is !null: UnsafeUnpin, PhantomData<ArcInner<dyn for<'a> Fn(&'a Database, &'a ActingUser, i64, &'a Map<String, Value>) -> Pin<Box<dyn Future<Output = Result<Result<(), String>, Error>> + Send + 'a>> + Sync + Send>>: UnsafeUnpin, PhantomData<Arc<dyn Fn(&Map<String, Value>) -> bool + Sync + Send>>: UnsafeUnpin,

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
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

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
Source§

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

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