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
impl BulkAction
Sourcepub fn make(name: impl Into<String>) -> Self
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.
Sourcepub fn label(self, label: impl Into<String>) -> Self
pub fn label(self, label: impl Into<String>) -> Self
The option’s text in the select, as Filament’s label().
Sourcepub fn action<F>(self, handler: F) -> Selfwhere
F: for<'a> Fn(&'a Database, &'a ActingUser, i64, &'a Row) -> RuntimeFuture<'a, ActionResult> + Send + Sync + 'static,
pub fn action<F>(self, handler: F) -> Selfwhere
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 { ... }).
Sourcepub fn visible(
self,
rule: impl Fn(&Row) -> bool + Send + Sync + 'static,
) -> Self
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.
Skips the records for which rule holds, as Filament’s hidden().
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.
Sourcepub fn success_notification_title(self, title: impl Into<String>) -> Self
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.
Sourcepub fn is_runnable(&self) -> bool
pub fn is_runnable(&self) -> bool
Whether the action has a handler. An action without one is not listed and not run.
Sourcepub fn ability(&self) -> ActionAbility
pub fn ability(&self) -> ActionAbility
The ability the action needs.
Sourcepub fn is_visible(&self, record: &Row) -> bool
pub fn is_visible(&self, record: &Row) -> bool
Whether the action may run on record: every visibility rule holds.
Sourcepub fn success_message(&self, count: usize) -> Option<String>
pub fn success_message(&self, count: usize) -> Option<String>
The success message for count records, if set.
Sourcepub async fn run(
&self,
db: &Database,
user: &ActingUser,
id: i64,
record: &Row,
) -> Result<ActionResult, Error>
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
impl Clone for BulkAction
Auto Trait Implementations§
impl !RefUnwindSafe for BulkAction
impl !UnwindSafe for BulkAction
impl Forget for BulkAction
impl Freeze for BulkActionwhere
*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
impl Sync for BulkAction
impl Unpin for BulkAction
impl UnsafeUnpin for BulkActionwhere
*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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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