Files
supabase/apps/studio/components/interfaces/RoleImpersonationSelector/RoleImpersonationPopover.tsx
Alaister YoungandAlaister Young fcbdda8107 chore: migrate formatter from Prettier to oxfmt (#53835)
Migrate code formatting across the monorepo from Prettier to `oxfmt`
(`0.79.0`, pinned) for much faster formatting checks locally and in CI
while keeping code churn minimal (78 files total, 0.7% of the repo).

Studio's `@ianvs/prettier-plugin-sort-imports` ordering
(`<BUILTIN_MODULES>`, `<THIRD_PARTY_MODULES>`, blank line, then `@/` and
relative imports) is preserved via `oxfmt`'s native `sortImports`
override for `apps/studio/**/*.{js,jsx,ts,tsx}`.

### Performance (before vs after, uncached)

| Benchmark | Prettier (`3.8.x`) | oxfmt (`0.79.0`) | Speedup |
| --- | ---: | ---: | ---: |
| CI formatting step (`blacksmith-4vcpu-ubuntu-2404`, full repo) | `73s`
| **`7s`** | **~10×** |
| Local `apps/studio` JS/TS (`5,157` files) | `17.74s` | **`0.36s`** |
**~49×** |
| Local full monorepo (`11,131` files) | — | **`2.39s`** | — |

**Added:**

- `.oxfmtrc.jsonc` at repo root with Prettier-matching options,
`sortPackageJson: false`, the Studio `sortImports` override, and ignore
patterns migrated from `.prettierignore`
- `oxfmt` (`0.79.0` exact pin) in `pnpm-workspace.yaml` catalog and
workspace `devDependencies` / `dependencies`
- Shared `.agents/scripts/format_and_lint.sh` hook script and
`.agents/hooks.json` (used by both Claude Code and Antigravity)

**Changed:**

- Replaced `test:prettier` with `format:check` and switched `format` in
root `package.json` to `oxfmt`
- Updated `packages/api-types` (`codegen`,
`verify-production-types.mjs`), `apps/design-system` (`build:registry`),
`apps/docs` (`CodeSample.ts`, `generate-sitemap.ts`, `next.config.mjs`,
`spec/Makefile`), `apps/www` (`generate-sitemap.mjs`), and
`packages/build-icons` (`generateIconFiles.mjs`) from Prettier to
`oxfmt`
- Updated `.github/workflows/prettier.yml` (keeping the `format` job ID
intact), `.github/workflows/autofix_linters.yml`,
`.claude/settings.json`, `AGENTS.md`, `CONTRIBUTING.md`, and
`.github/copilot-instructions.md`
- Applied one-time `oxfmt` formatting pass in a separate commit (78
files: 30 `i18n/README.*.md` trailing spaces, 19 Studio files, 17 other
TS/TSX/generated types, 8 MD/MDX, 3 `package.json`, 2 example CSS files)

**Removed:**

- `prettier`, `@ianvs/prettier-plugin-sort-imports`, and
`prettier-plugin-sql-cst` from `devDependencies` (note: `.sql` files
were not part of the CI formatting glob; `eslint-config-prettier` is
kept for ESLint)
- `prettier.config.mjs`, `.prettierignore`, and
`.claude/scripts/format_and_lint.sh`

## To test

- Run `pnpm run format:check` and confirm it passes cleanly across all
matched files
- Run `pnpm --filter api-types test`, `pnpm --filter docs exec vitest
run features/directives/CodeSample.test.ts`, and `pnpm --filter www exec
vitest run generate-sitemap.test.ts`
- Edit an `apps/studio` file with out-of-order imports and run `pnpm run
format` to confirm builtin/third-party vs `@/`/relative grouping matches
prior behavior
- Check that the `Check Code Formatting` CI workflow passes on this PR

---------

Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
2026-11-24 12:51:31 +08:00

101 lines
3.8 KiB
TypeScript

import { ChevronDownIcon, UserIcon } from 'lucide-react'
import { useState } from 'react'
import { Button, cn, Popover, PopoverContent, PopoverTrigger } from 'ui'
import { RoleImpersonationSelector } from '.'
import { getAvatarUrl, getDisplayName } from '../Auth/Users/Users.utils'
import type { User } from '@/data/auth/users-infinite-query'
import { useRoleImpersonationStateSnapshot } from '@/state/role-impersonation-state'
export interface RoleImpersonationPopoverProps {
header?: string
serviceRoleLabel?: string
variant?: 'regular' | 'connected-on-right' | 'connected-on-left' | 'connected-on-both'
align?: 'center' | 'start' | 'end'
disallowAuthenticatedOption?: boolean
}
export const RoleImpersonationPopover = ({
header,
serviceRoleLabel,
variant = 'regular',
align = 'end',
disallowAuthenticatedOption = false,
}: RoleImpersonationPopoverProps) => {
const state = useRoleImpersonationStateSnapshot()
const [isOpen, setIsOpen] = useState(false)
const currentRole = state.role?.role ?? serviceRoleLabel ?? 'postgres'
return (
<Popover open={isOpen} onOpenChange={setIsOpen}>
<PopoverTrigger asChild>
<Button
size="tiny"
className={cn(
'h-[26px] pr-3 gap-0',
variant === 'connected-on-right' && 'rounded-r-none border-r-0',
variant === 'connected-on-left' && 'rounded-l-none border-l-0',
variant === 'connected-on-both' && 'rounded-none border-x-0'
)}
>
<div className="flex items-center gap-1">
<span className="text-foreground-muted">Role</span>
<span>{currentRole}</span>
{state.role?.type === 'postgrest' && state.role.role === 'authenticated' && (
<>
{state.role.userType === 'native' && state.role.user ? (
<UserRoleButtonSection user={state.role.user} />
) : state.role.userType === 'external' && state.role.externalAuth ? (
<ExternalAuthButtonSection sub={state.role.externalAuth.sub} />
) : null}
<span className="text-xs text-foreground-lighter font-light">
{state.role.aal === 'aal2' ? 'AAL2' : 'AAL1'}
</span>
</>
)}
<ChevronDownIcon className="text-muted" strokeWidth={1} size={12} />
</div>
</Button>
</PopoverTrigger>
<PopoverContent className="p-0 overflow-hidden w-min" side="bottom" align={align}>
<RoleImpersonationSelector
header={header}
serviceRoleLabel={serviceRoleLabel}
disallowAuthenticatedOption={disallowAuthenticatedOption}
/>
</PopoverContent>
</Popover>
)
}
const UserRoleButtonSection = ({ user }: { user: User }) => {
const avatarUrl = getAvatarUrl(user)
const displayName = getDisplayName(user, user.email ?? user.phone ?? user.id ?? 'Unknown')
return (
<div className="flex gap-1 items-center pl-0.5 pr-1.5 h-[21px] bg-surface-200 rounded-full overflow-hidden">
{avatarUrl ? (
<img className="rounded-full w-[18px] h-[18px]" src={avatarUrl} alt={displayName} />
) : (
<div className="rounded-full w-[18px] h-[18px] bg-surface-100 border flex items-center justify-center text-light">
<UserIcon size={12} strokeWidth={2} />
</div>
)}
<span className="truncate max-w-[84px]">{displayName}</span>
</div>
)
}
const ExternalAuthButtonSection = ({ sub }: { sub: string }) => {
return (
<div className="flex gap-1 items-center pl-0.5 pr-1.5 h-[21px] bg-surface-200 rounded-full overflow-hidden">
<div className="rounded-full w-[18px] h-[18px] bg-surface-100 border flex items-center justify-center text-light">
<UserIcon size={12} strokeWidth={2} />
</div>
<span className="truncate max-w-[84px]">{sub}</span>
</div>
)
}