mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
## Context This is largely just a mechanical change here: Opting to use lucide icons with the `Icon` suffix across all icon imports within `studio` - so that it’s clearer which components are icons + reduces the possibility of name collision with our own components - e.g <User /> vs <UserIcon /> Also added a eslint rule for this: <img width="1069" height="167" alt="image" src="https://github.com/user-attachments/assets/7f36f443-5ca2-4bf6-8d22-86e774513bfc" /> And updated `AGENTS.md` as such: ``` Icons come from `lucide-react`, always imported with the `Icon` suffix (`import { CheckIcon, Trash2Icon } from 'lucide-react'`) — never the bare names (`Check`) or `Check as CheckIcon` aliases (lint-enforced). ```
126 lines
4.7 KiB
TypeScript
126 lines
4.7 KiB
TypeScript
import { CheckIcon, DatabaseIcon, UserCheckIcon, UserXIcon } from 'lucide-react'
|
|
import { Separator, ToggleGroup, ToggleGroupItem } from 'ui'
|
|
|
|
import { UserImpersonationSelector } from './UserImpersonationSelector'
|
|
import { useRoleImpersonationSelection } from './useRoleImpersonationSelection'
|
|
import {
|
|
useRoleImpersonationStateSnapshot,
|
|
type RoleImpersonationController,
|
|
} from '@/state/role-impersonation-state'
|
|
|
|
export interface RoleImpersonationSelectorProps {
|
|
header?: string
|
|
serviceRoleLabel?: string
|
|
disallowAuthenticatedOption?: boolean
|
|
title?: string
|
|
}
|
|
|
|
/**
|
|
* Tightly coupled with the global role impersonation store.
|
|
* Use RoleImpersonationSelectorInterface to control the logic externally.
|
|
*/
|
|
export const RoleImpersonationSelector = (props: RoleImpersonationSelectorProps) => {
|
|
const state = useRoleImpersonationStateSnapshot() as unknown as RoleImpersonationController
|
|
|
|
return <RoleImpersonationSelectorInterface {...props} state={state} />
|
|
}
|
|
|
|
type RoleImpersonationSelectorInterfaceProps = RoleImpersonationSelectorProps & {
|
|
state: RoleImpersonationController
|
|
}
|
|
|
|
export const RoleImpersonationSelectorInterface = (
|
|
props: RoleImpersonationSelectorInterfaceProps
|
|
) => {
|
|
const { state } = props
|
|
const serviceRoleLabel = props.serviceRoleLabel ?? 'Postgres'
|
|
const disallowAuthenticatedOption = props.disallowAuthenticatedOption ?? false
|
|
const { selectedOption, onSelectedChange, keepAuthenticatedSelected } =
|
|
useRoleImpersonationSelection(state)
|
|
|
|
const roleSummary = {
|
|
service_role: 'Bypasses RLS and can return all rows.',
|
|
anon: 'Returns rows available to anonymous users.',
|
|
authenticated: 'Returns rows available to the selected user.',
|
|
}[selectedOption]
|
|
|
|
return (
|
|
<div className="flex w-80 flex-col">
|
|
<form
|
|
className="p-3"
|
|
onSubmit={(event) => {
|
|
event.preventDefault()
|
|
}}
|
|
>
|
|
<ToggleGroup
|
|
type="single"
|
|
orientation="vertical"
|
|
value={selectedOption}
|
|
onValueChange={(value) => {
|
|
if (value === 'service_role' || value === 'anon' || value === 'authenticated') {
|
|
void onSelectedChange(value)
|
|
}
|
|
}}
|
|
variant="default"
|
|
aria-label={props.header ?? props.title ?? 'Run query as role'}
|
|
className="w-full flex-col items-stretch gap-0.5"
|
|
>
|
|
<ToggleGroupItem value="service_role" className="w-full justify-between text-left">
|
|
<span className="flex min-w-0 items-center gap-3">
|
|
<DatabaseIcon size={16} strokeWidth={1.5} className="shrink-0" />
|
|
<span className="flex min-w-0 flex-col items-start">
|
|
<span>{serviceRoleLabel}</span>
|
|
<span className="text-xs font-normal text-foreground-lighter">Superuser</span>
|
|
</span>
|
|
</span>
|
|
{selectedOption === 'service_role' && <CheckIcon size={14} />}
|
|
</ToggleGroupItem>
|
|
|
|
<ToggleGroupItem value="anon" className="w-full justify-between text-left">
|
|
<span className="flex min-w-0 items-center gap-3">
|
|
<UserXIcon size={16} strokeWidth={1.5} className="shrink-0" />
|
|
<span className="flex min-w-0 flex-col items-start">
|
|
<span>Anonymous</span>
|
|
<span className="text-xs font-normal text-foreground-lighter">Not logged in</span>
|
|
</span>
|
|
</span>
|
|
{selectedOption === 'anon' && <CheckIcon size={14} />}
|
|
</ToggleGroupItem>
|
|
|
|
{!disallowAuthenticatedOption && (
|
|
<ToggleGroupItem value="authenticated" className="w-full justify-between text-left">
|
|
<span className="flex min-w-0 items-center gap-3">
|
|
<UserCheckIcon size={16} strokeWidth={1.5} className="shrink-0" />
|
|
<span className="flex min-w-0 flex-col items-start">
|
|
<span>Authenticated</span>
|
|
<span className="text-xs font-normal text-foreground-lighter">
|
|
Logged-in user
|
|
</span>
|
|
</span>
|
|
</span>
|
|
{selectedOption === 'authenticated' && <CheckIcon size={14} />}
|
|
</ToggleGroupItem>
|
|
)}
|
|
</ToggleGroup>
|
|
|
|
{!disallowAuthenticatedOption && (
|
|
<>
|
|
<Separator className="my-2.5" />
|
|
<UserImpersonationSelector
|
|
state={state}
|
|
disabled={selectedOption !== 'authenticated'}
|
|
onUserImpersonationCleared={keepAuthenticatedSelected}
|
|
/>
|
|
</>
|
|
)}
|
|
</form>
|
|
<Separator />
|
|
<footer className="px-3 py-2">
|
|
<p aria-live="polite" className="text-xs text-foreground-lighter">
|
|
{roleSummary}
|
|
</p>
|
|
</footer>
|
|
</div>
|
|
)
|
|
}
|