CreateRolePanel() — supabase Function Reference
Architecture documentation for the CreateRolePanel() function in CreateRolePanel.tsx from the supabase codebase.
Entity Profile
Relationship Graph
Source Code
apps/studio/components/interfaces/Database/Roles/CreateRolePanel.tsx lines 47–189
export const CreateRolePanel = ({ visible, onClose }: CreateRolePanelProps) => {
const formId = 'create-new-role'
const { data: project } = useSelectedProjectQuery()
const form = useForm<z.infer<typeof FormSchema>>({
resolver: zodResolver(FormSchema),
})
const { mutate: createDatabaseRole, isPending: isCreating } = useDatabaseRoleCreateMutation({
onSuccess: (_, vars) => {
toast.success(`Successfully created new role: ${vars.payload.name}`)
handleClose()
},
})
const onSubmit: SubmitHandler<z.infer<typeof FormSchema>> = async (values) => {
if (!project) return console.error('Project is required')
createDatabaseRole({
projectRef: project.ref,
connectionString: project.connectionString,
payload: values,
})
}
const handleClose = () => {
onClose()
form.reset(initialValues)
}
return (
<SidePanel
size="large"
visible={visible}
header="Create a new role"
className="mr-0 transform transition-all duration-300 ease-in-out"
loading={false}
onCancel={handleClose}
customFooter={
<div className="flex w-full justify-end space-x-3 border-t border-default px-3 py-4">
<FormActions
form={formId}
isSubmitting={isCreating}
hasChanges={form.formState.isDirty}
handleReset={handleClose}
/>
</div>
}
>
<Form_Shadcn_ {...form}>
<form
id={formId}
className="grid gap-6 w-full px-8 py-8"
onSubmit={form.handleSubmit(onSubmit)}
>
<FormField_Shadcn_
control={form.control}
name="name"
render={({ field }) => (
<FormItem_Shadcn_ className="grid gap-2 md:grid md:grid-cols-12 space-y-0">
<FormLabel_Shadcn_ className="flex flex-col space-y-2 col-span-4 text-sm justify-center text-foreground-light">
Name
</FormLabel_Shadcn_>
<FormControl_Shadcn_ className="col-span-8">
<Input_Shadcn_ {...field} className="w-full" />
</FormControl_Shadcn_>
<FormMessage_Shadcn_ className="col-start-5 col-span-8" />
</FormItem_Shadcn_>
)}
/>
<div className="grid gap-2 mt-4 md:grid md:grid-cols-12">
<div className="col-span-4">
<FormLabel_Shadcn_ className="flex flex-col space-y-2 col-span-4 text-sm justify-center text-foreground-light">
Role privileges
</FormLabel_Shadcn_>
</div>
<div className="col-span-8 grid gap-4">
{(Object.keys(ROLE_PERMISSIONS) as (keyof typeof ROLE_PERMISSIONS)[])
.filter((permissionKey) => ROLE_PERMISSIONS[permissionKey].grant_by_dashboard)
.map((permissionKey) => {
const permission = ROLE_PERMISSIONS[permissionKey]
return (
<FormField_Shadcn_
key={permissionKey}
control={form.control}
name={permissionKey}
render={({ field }) => (
<FormItem_Shadcn_ className="grid gap-2 md:grid md:grid-cols-12 space-y-0">
<FormControl_Shadcn_ className="col-span-8 flex items-center gap-4">
<div className="w-full text-sm">
<Switch checked={field.value} onCheckedChange={field.onChange} />
<FormLabel_Shadcn_>{permission.description}</FormLabel_Shadcn_>
</div>
</FormControl_Shadcn_>
<FormMessage_Shadcn_ className="col-start-5 col-span-8" />
</FormItem_Shadcn_>
)}
/>
)
})}
<SidePanel.Separator />
<div className="grid gap-4">
<p className="text-sm">These privileges cannot be granted via the Dashboard:</p>
{(Object.keys(ROLE_PERMISSIONS) as (keyof typeof ROLE_PERMISSIONS)[])
.filter((permissionKey) => !ROLE_PERMISSIONS[permissionKey].grant_by_dashboard)
.map((permissionKey) => {
const permission = ROLE_PERMISSIONS[permissionKey]
return (
<FormField_Shadcn_
key={permissionKey}
control={form.control}
name={permissionKey}
render={({ field }) => (
<FormItem_Shadcn_ className="space-y-0 opacity-70">
<FormControl_Shadcn_ className="flex items-center gap-4">
<div className="w-full text-sm">
<Switch
checked={field.value}
onCheckedChange={field.onChange}
disabled
aria-readonly
/>
<FormLabel_Shadcn_>{permission.description}</FormLabel_Shadcn_>
</div>
</FormControl_Shadcn_>
<FormMessage_Shadcn_ className="col-start-5 col-span-8" />
</FormItem_Shadcn_>
)}
/>
)
})}
</div>
</div>
</div>
</form>
</Form_Shadcn_>
</SidePanel>
)
}
Domain
Subdomains
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free