Dashboards and widgets¶
A widget is a card computed on the server for a date range. Widgets sit on dashboards, or above a resource’s list.
final class RevenueStat extends VectorWidget
{
public function __construct(private readonly SqlLink $db) {}
public function type(): string { return self::STAT; }
public function cacheSeconds(): int { return 60; }
public function calculate(WidgetRequest $request): WidgetResult
{
// one query for $request->from .. $request->to
return WidgetResult::stat($current, $previous, 'money:EUR');
}
}
Widget types¶
Type |
Shows |
|---|---|
|
One figure, compared with the previous period. |
|
A series over time. |
|
A breakdown into slices, such as orders by status. |
|
A figure against a target. |
|
A few rows, optionally linking to the full list. |
A value’s format is a number, money:EUR, percent or duration.
Shaping a widget¶
Method |
Effect |
|---|---|
|
The ranges offered, as key => label, the first the default; |
|
3, 4, 6 or 12 columns of the grid. |
|
The URL segment (by default the class name without |
|
Who sees it, on top of the dashboard’s or resource’s own visibility. |
|
Above zero, memoizes the result in a bounded per-worker cache, keyed by widget, range and the account it was computed for. |
|
Shares one cached result between all admins, for figures that are the same for everyone. |
Dashboards¶
#[Dashboard]
final class MainDashboard extends VectorDashboard
{
public function widgets(): array { return [RevenueStat::class, OrdersTrend::class]; }
}
A dashboard’s name is its class name without Dashboard, in kebab-case
(MainDashboard is main), unless name() says otherwise. The
dashboard named main — or, without one, the first — is the admin’s
home page; the others appear in the navigation drawer under their own
labels. canView() hides a whole dashboard from a user.
Resource widgets¶
A resource’s widgets() appear above its list. A widget runs its own
query: when the resource’s scope() narrows what a user may see, narrow
the widget’s query the same way, and leave cacheShared() false so one
admin is never shown another’s figures.
See also¶
Resources — badges, the other at-a-glance count.
Customizing the UI — a renderer of your own for a widget type.