Shadcn Permissions Matrix Table
Roles and access management in one grid: resources down the side, actions across the top. Roles inherit from each other, actions that don't apply are greyed out, and View stays on while anything that depends on it is granted.
$ npx shadcn add https://www.shad-table.dev/r/permissions-matrix-table.jsonEditor Ships work: creates projects and deploys them.
Inherits everything Viewer can do. Change those on the Viewer tab.
- Granted
- Inherited
- Required by another action
- Not available
| Resource | View | Create | Edit | Delete | Export | All |
|---|---|---|---|---|---|---|
ProjectsRepositories, settings and domains | ||||||
DeploymentsTrigger, promote and roll back | Edit Deployments: Not available for this resource | Export Deployments: Not available for this resource | ||||
Environment variablesSecrets used at build and run time | Export Environment variables: Not available for this resource | |||||
InvoicesPast and upcoming invoices | Create Invoices: Not available for this resource | Edit Invoices: Not available for this resource | Delete Invoices: Not available for this resource | |||
Payment methodsCards and bank accounts on file | Export Payment methods: Not available for this resource | |||||
SubscriptionPlan, seats and add-ons | Create Subscription: Not available for this resource | Delete Subscription: Not available for this resource | Export Subscription: Not available for this resource | |||
MembersInvite, change roles and remove | ||||||
RolesCustom roles and their permissions | Export Roles: Not available for this resource | |||||
API keysPersonal and team tokens | Edit API keys: Not available for this resource | Export API keys: Not available for this resource | ||||
Audit logWho changed what, and when | Create Audit log: Not available for this resource | Edit Audit log: Not available for this resource | Delete Audit log: Not available for this resource |
10 of 34 permissions, 3 inherited
How it works
1.Only grants are stored; every other state is derived
Each role keeps a set of its own grants, like 'invoices.export'. Whether a checkbox is inherited, required or unavailable is worked out by cellState() on every render. Grant Delete on the Editor tab and Admin shows it as inherited straight away, because nothing was copied that could go stale.
if (!resource.actions.includes(action)) return { kind: 'unavailable' }if (role.locked) return { kind: 'locked', role }const from = inheritedFrom(role, k, grants)if (from) return { kind: 'inherited', from }if (!own.has(k)) return { kind: 'denied' }
2.Inherited means "on, but changed somewhere else"
An inherited grant is checked and disabled, with a muted fill instead of the solid one, so the matrix shows at a glance what this role adds on top of its parent. The tooltip names the role it comes from. Disabled buttons get no pointer events, so the tooltip hangs on a wrapper span.
<Tooltip><TooltipTrigger asChild><span className="inline-flex">{checkbox}</span></TooltipTrigger><TooltipContent>Inherited from {state.from.name}</TooltipContent></Tooltip>
3.Every action needs View
Granting Edit also grants View. While Edit, Create or Delete is on, View is locked with a 'Needed by Edit' tooltip rather than letting the role end up able to edit something it can't see. setCells() applies the same rule to bulk changes.
const needsView = resource.actions.some((a) => a !== 'view' && next.has(key(resource.id, a)),)if (needsView && !viewInherited) next.add(viewKey)
4.Group, column and row checkboxes are tri-state
Resources are subRows of their group, so groups expand and collapse. The checkbox on a group row, a column header or the All column summarizes the cells under it: checked, indeterminate or unchecked. Clicking it only changes the role's own cells; inherited and unavailable ones are counted but never touched.
return {checked: on === 0 ? false : on === states.length ? true : 'indeterminate',enabled: own.length > 0,next: !own.every(isOn),}
5.Unsaved changes are a diff against the last save
The demo keeps the saved grants next to the edited ones. Their difference marks changed cells with a dot, flags role tabs that have edits, and powers Discard and Save. Replace setSaved with your API call.
for (const k of a) if (!b.has(k)) changed.add(`${role.id}:${k}`)for (const k of b) if (!a.has(k)) changed.add(`${role.id}:${k}`)