Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Update database roles page to improve ui

Joshen Lim3e05a320e71d
diff --git a/studio/components/interfaces/Database/Roles/RoleRow.tsx b/studio/components/interfaces/Database/Roles/RoleRow.tsx
new file mode 100644
index 00000000000..f1b65d052c7
--- /dev/null
+++ b/studio/components/interfaces/Database/Roles/RoleRow.tsx
@@ -0,0 +1,114 @@
+import { FC } from 'react'
+import { PostgresRole } from '@supabase/postgres-meta'
+import { IconChevronUp, IconCheck, IconX, Collapsible } from 'ui'
+
+interface Props {
+ role: PostgresRole
+ isExpanded: boolean
+ onClick: () => void
+}
+
+const RoleRow: FC<Props> = ({ role, isExpanded, onClick }) => {
+ return (
+ <Collapsible
+ open={isExpanded}
+ onOpenChange={onClick}
+ className={[
+ 'bg-scale-100 dark:bg-scale-300',
+ 'hover:bg-scale-200 dark:hover:bg-scale-500',
+ 'data-open:bg-scale-200 dark:data-open:bg-scale-500',
+ 'border-scale-300 dark:border-scale-500 hover:border-scale-500',
+ 'dark:hover:border-scale-700 data-open:border-scale-700',
+ 'data-open:pb-px col-span-12 mx-auto',
+ '-space-y-px overflow-hidden',
+ 'border border-b-0 last:border-b shadow transition hover:z-50',
+ 'first:rounded-tl first:rounded-tr',
+ 'last:rounded-bl last:rounded-br',
+ ].join(' ')}
+ >
+ <Collapsible.Trigger asChild>
+ <button
+ type="button"
+ className="group flex w-full items-center justify-between rounded py-3 px-6 text-scale-1200"
+ >
+ <div className="flex items-start space-x-3">
+ <IconChevronUp
+ className="text-scale-800 transition data-open-parent:rotate-0 data-closed-parent:rotate-180"
+ strokeWidth={2}
+ width={14}
+ />
+ <div className="space-x-2 flex items-center">
+ <p className="text-left text-sm">{role.name}</p>
+ <p className="text-left text-sm text-scale-1000">(ID: {role.id})</p>
+ </div>
+ </div>
+ <p
+ className={`text-sm ${
+ role.active_connections > 0 ? 'text-scale-1100' : 'text-scale-1000'
+ }`}
+ >
+ {role.active_connections} connections
+ </p>
+ </button>
+ </Collapsible.Trigger>
+ <Collapsible.Content>
+ <div className="group border-t border-scale-500 bg-scale-100 py-6 px-6 text-scale-1200 dark:bg-scale-300">
+ <div className="mx-auto py-4 px-6 space-y-2">
+ <div className="flex items-center space-x-2">
+ {role.is_superuser ? (
+ <IconCheck className="text-brand-900" strokeWidth={2} />
+ ) : (
+ <IconX className="text-scale-1000" strokeWidth={2} />
+ )}
+ <p className="text-sm">User is a Superuser</p>
+ </div>
+ <div className="flex items-center space-x-2">
+ {role.can_login ? (
+ <IconCheck className="text-brand-900" strokeWidth={2} />
+ ) : (
+ <IconX className="text-scale-1000" strokeWidth={2} />
+ )}
+ <p className="text-sm">User can login</p>
+ </div>
+ <div className="flex items-center space-x-2">
+ {role.can_create_role ? (
+ <IconCheck className="text-brand-900" strokeWidth={2} />
+ ) : (
+ <IconX className="text-scale-1000" strokeWidth={2} />
+ )}
+ <p className="text-sm">User can create roles</p>
+ </div>
+ <div className="flex items-center space-x-2">
+ {role.can_create_db ? (
+ <IconCheck className="text-brand-900" strokeWidth={2} />
+ ) : (
+ <IconX className="text-scale-1000" strokeWidth={2} />
+ )}
+ <p className="text-sm">User can create databases</p>
+ </div>
+ <div className="flex items-center space-x-2">
+ {role.is_replication_role ? (
+ <IconCheck className="text-brand-900" strokeWidth={2} />
+ ) : (
+ <IconX className="text-scale-1000" strokeWidth={2} />
+ )}
+ <p className="text-sm">
+ User can initiate streaming replication and put the system in and out of backup mode
+ </p>
+ </div>
+ <div className="flex items-center space-x-2">
+ {role.can_bypass_rls ? (
+ <IconCheck className="text-brand-900" strokeWidth={2} />
+ ) : (
+ <IconX className="text-scale-1000" strokeWidth={2} />
+ )}
+ <p className="text-sm">User bypasses every row level security policy</p>
+ </div>
+ </div>
+ </div>
+ </Collapsible.Content>
+ </Collapsible>
+ )
+}
+
+export default RoleRow
diff --git a/studio/components/interfaces/Database/Roles/RolesList.tsx b/studio/components/interfaces/Database/Roles/RolesList.tsx
index fc46dc7b30c..9fd1ba80944 100644
--- a/studio/components/interfaces/Database/Roles/RolesList.tsx
+++ b/studio/components/interfaces/Database/Roles/RolesList.tsx
@@ -1,10 +1,12 @@
-import { FC } from 'react'
+import { FC, useState } from 'react'
import { observer } from 'mobx-react-lite'
-import { IconChevronRight } from 'ui'
+import * as Tooltip from '@radix-ui/react-tooltip'
import { useStore } from 'hooks'
import SparkBar from 'components/ui/SparkBar'
-import Table from 'components/to-be-cleaned/Table'
+import { FormHeader } from 'components/ui/Forms'
+import { PostgresRole } from '@supabase/postgres-meta'
+import RoleRow from './RoleRow'
interface Props {
onSelectRole: (role: any) => void
@@ -13,43 +15,77 @@ interface Props {
const RolesList: FC<Props> = ({ onSelectRole = () => {} }) => {
const { meta } = useStore()
const roles = meta.roles.list()
+ const [expandedRoleId, setExpandedRoleId] = useState<number>()
+
+ const connectionLimit = Math.max(...roles.map((role: PostgresRole) => role.connection_limit))
+ const totalActiveConnections = roles
+ .map((role: PostgresRole) => role.active_connections)
+ .reduce((a, b) => a + b, 0)
+ const rolesWithActiveConnections = roles
+ .filter((role: PostgresRole) => role.active_connections > 0)
+ .sort((a, b) => b.active_connections - a.active_connections)
return (
- <>
- <Table
- head={[
- <Table.th key="name">Name</Table.th>,
- <Table.th key="system-id">System ID</Table.th>,
- <Table.th key="connections">Connections</Table.th>,
- <Table.th key="blank"></Table.th>,
- ]}
- body={roles.map((x, i) => (
- <Table.tr key={x.id} onClick={() => onSelectRole(x)}>
- <Table.td style={{ width: '25%' }}>
- <p>{x.name}</p>
- </Table.td>
- <Table.td style={{ width: '25%' }}>
- <p>{x.id}</p>
- </Table.td>
- <Table.td className="w-full">
- <div className="flex items-center space-x-3">
- <p>
- {x.active_connections}/{x.connection_limit} connections
- </p>
+ <div>
+ <div className="flex items-center justify-between">
+ <FormHeader
+ title="Database Roles"
+ description="Manage access control to your database through users, groups, and permissions"
+ />
+ <div className="mb-6">
+ <Tooltip.Root delayDuration={0}>
+ <Tooltip.Trigger>
+ <div className="w-42">
<SparkBar
- max={x.connection_limit}
- value={x.active_connections}
- barClass={'bg-green-800'}
+ type="horizontal"
+ max={connectionLimit}
+ value={totalActiveConnections}
+ barClass={
+ totalActiveConnections > 0.9 * connectionLimit
+ ? 'bg-red-800'
+ : totalActiveConnections > 0.75 * connectionLimit
+ ? 'bg-amber-900'
+ : 'bg-green-800'
+ }
+ labelTop={`${totalActiveConnections}/${connectionLimit}`}
+ labelBottom="Active connections"
/>
</div>
- </Table.td>
- <Table.td style={{ maxWidth: '64px' }} className="w-min">
- <IconChevronRight className="text-scale-1100" size="small" />
- </Table.td>
- </Table.tr>
+ </Tooltip.Trigger>
+ <Tooltip.Content align="start" side="bottom">
+ <Tooltip.Arrow className="radix-tooltip-arrow" />
+ <div
+ className={[
+ 'rounded bg-scale-100 py-1 px-2 leading-none shadow',
+ 'border border-scale-200 space-y-1',
+ ].join(' ')}
+ >
+ <p className="text-xs text-scale-1100 pr-2">Connection breakdown:</p>
+ {rolesWithActiveConnections.map((role: PostgresRole) => (
+ <div key={role.id} className="text-xs text-scale-1200">
+ {role.name}: {role.active_connections}
+ </div>
+ ))}
+ </div>
+ </Tooltip.Content>
+ </Tooltip.Root>
+ </div>
+ </div>
+
+ <div>
+ {roles.map((role: PostgresRole, i: number) => (
+ <RoleRow
+ key={role.id}
+ role={role}
+ isExpanded={expandedRoleId === role.id}
+ onClick={() => {
+ if (expandedRoleId === role.id) setExpandedRoleId(undefined)
+ else setExpandedRoleId(role.id)
+ }}
+ />
))}
- />
- </>
+ </div>
+ </div>
)
}
diff --git a/studio/pages/project/[ref]/database/roles.tsx b/studio/pages/project/[ref]/database/roles.tsx
index 1cd86534d1c..9057f0cfa8e 100644
--- a/studio/pages/project/[ref]/database/roles.tsx
+++ b/studio/pages/project/[ref]/database/roles.tsx
@@ -10,7 +10,7 @@ const DatabaseRoles: NextPageWithLayout = () => {
const [selectedRole, setSelectedRole] = useState<any>()
return (
- <div className="p-4">
+ <div className="1xl:px-28 mx-auto flex flex-col px-5 pt-6 pb-14 lg:px-16 xl:px-24 2xl:px-32">
{isUndefined(selectedRole) ? (
<RolesList onSelectRole={setSelectedRole} />
) : (