Search docs

Jump to any table example

Discord—

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.json

Editor 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 resourceExport 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 resourceEdit Invoices: Not available for this resourceDelete 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 resourceDelete Subscription: Not available for this resourceExport 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 resourceExport API keys: Not available for this resource
Audit logWho changed what, and when
Create Audit log: Not available for this resourceEdit Audit log: Not available for this resourceDelete Audit log: Not available for this resource

10 of 34 permissions, 3 inherited

All changes saved

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.

src/components/permissions-matrix/permissions.ts
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.

src/components/permissions-matrix/permission-checkbox.tsx
<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.

src/components/permissions-matrix/permissions.ts
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.

src/components/permissions-matrix/permissions.ts
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.

src/components/permissions-matrix/permissions.ts
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}`)