pub struct ListWidget { /* private fields */ }Expand description
A dashboard widget that lists rows under a title, as a Filament custom widget with its own
view: the rows of WordPress’s “Activity” or “Recently Published” box. Pass it to
Ignite::list_widget. The panel renders it with its partials.widgets.list view (a theme
can replace it), escaping every label, value and link.
ListWidget::make("Recently Published")
.rows_from(posts.data.clone(), ListQuery { page: 1, per_page: 5, search: None,
sort: Some(("published_at".into(), Direction::Desc)),
filter: ListFilter::new().where_eq("status", "publish") },
|row| ListWidgetRow::make(row["title"].as_str().unwrap_or_default())
.value(row["published_at"].as_str().unwrap_or_default())
.url(format!("/admin/posts/{}/edit", row["id"])))
.empty_state("No posts published yet.")Implementations§
Source§impl ListWidget
impl ListWidget
Sourcepub fn rows<F>(self, rows: F) -> Selfwhere
F: for<'a> Fn(&'a Database, &'a ActingUser) -> RuntimeFuture<'a, Vec<ListWidgetRow>> + Send + Sync + 'static,
pub fn rows<F>(self, rows: F) -> Selfwhere
F: for<'a> Fn(&'a Database, &'a ActingUser) -> RuntimeFuture<'a, Vec<ListWidgetRow>> + Send + Sync + 'static,
The rows, computed for the signed-in user on each dashboard request. Write it as
|db, user| Box::pin(async move { ... }).
Sourcepub fn rows_from<M>(
self,
data: Arc<dyn RuntimeData>,
query: ListQuery,
map: M,
) -> Self
pub fn rows_from<M>( self, data: Arc<dyn RuntimeData>, query: ListQuery, map: M, ) -> Self
The rows from a RuntimeData: its list_for for the
signed-in user with query (its page, sort and filter), each row turned into a
ListWidgetRow by map. A runtime resource’s data is its data field.
Sourcepub fn empty_state(self, text: impl Into<String>) -> Self
pub fn empty_state(self, text: impl Into<String>) -> Self
The text shown when there are no rows. The default is DEFAULT_EMPTY_STATE.
Sourcepub fn can_view(
self,
rule: impl Fn(&ActingUser) -> bool + Send + Sync + 'static,
) -> Self
pub fn can_view( self, rule: impl Fn(&ActingUser) -> bool + Send + Sync + 'static, ) -> Self
Who sees the widget, as Filament’s canView(). The default is every user.
Sourcepub fn get_empty_state(&self) -> &str
pub fn get_empty_state(&self) -> &str
The text shown without rows.
Sourcepub fn is_visible_to(&self, user: &ActingUser) -> bool
pub fn is_visible_to(&self, user: &ActingUser) -> bool
Whether user sees the widget.
Sourcepub async fn load(
&self,
db: &Database,
user: &ActingUser,
) -> Result<Vec<ListWidgetRow>, Error>
pub async fn load( &self, db: &Database, user: &ActingUser, ) -> Result<Vec<ListWidgetRow>, Error>
The rows for user. None when the widget sets none.
Trait Implementations§
Source§impl Clone for ListWidget
impl Clone for ListWidget
Auto Trait Implementations§
impl !RefUnwindSafe for ListWidget
impl !UnwindSafe for ListWidget
impl Forget for ListWidget
impl Freeze for ListWidget
impl Move for ListWidget
impl Send for ListWidget
impl Sync for ListWidget
impl Unpin for ListWidget
impl UnsafeUnpin for ListWidget
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