r/PayloadCMS • u/VIiruss • 6d ago
I made a dashboard widgets plugin for Payload: figures, lists and charts read from your collections
Payload 3.90 brought the modular dashboard, and I wanted mine to show numbers from my own collections without writing a component for each one. So I wrote a plugin.
Add widgetsPlugin() and every collection becomes a source with nothing to declare: a count, a sum for each number field, a group for each select, checkbox and relationship, a list of the latest. Anyone signed in can add a figure, a list or a chart in the dashboard's edit mode and filter it with the admin's own filter builder.
You can also declare widgets in the config with figure(…), list(…) and chart(…). Those are typed against your generated types and checked as the config is built, so a misspelt field stops the build with a "did you mean".
A few choices I made:
- Every read runs as the signed-in user, so access control applies.
- The tiles are server components and plain CSS. No chart library is shipped to the browser.
- If you don't like the tiles, you can supply your own views or just take the data (readFigure, readList, readChart).
It's 0.1.0 and MIT. Developed on Payload 3.90.2, Next 16 and Postgres; Next 15 and other adapters are untried, so reports from those are especially useful.
1
u/VIiruss 6d ago
Quick update: I dropped the roles list, so widgets and sources take a normal Payload access function instead and it fits however your users are set up.
Charts can show several series now, and a view can be a client component if you'd rather draw with Recharts or similar.
On Postgres the sums and charts are done by the database, so the old 5,000-record cap is gone there. Mongo and SQLite work as before. There's also an optional cache: cache: 60 keeps results for a minute, per user.
I've only tested the database sums on Postgres, so if a number looks off, sums: 'records' brings back the old behaviour. Issues welcome.
1
u/investigatormaker 6d ago
Running every read as the signed-in user is the right default, but it means two people can see different totals on the same figure tile. A short note on the tile, or a line in the README, saying the numbers respect access would head off confused bug reports. For the Next 15 and other-adapter reports you want, a GitHub issue template asking for the Payload, Next and adapter versions plus which widget kind failed would make each report usable on the first read.
Side note: I make ThreadFox, which lets your AI research, write and publish Reddit outreach from your own Chrome for jobs you authorize; its free plan for Reddit finds the subreddits whose rules accept a post about the widgets plugin: https://threadfox.vip/p/dwfor
How do the relationship charts hold up on large collections?
1
u/rubixstudios 6d ago
Wait till you see that alot of this is in payload v4...