mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
Part 5 of a 6-PR stack migrating all `next/link` imports in `apps/studio` onto TanStack Router's `Link` (or plain `<a>` for known external URLs) and removing `compat/next/link.tsx`. | Part | PR | Scope | | --- | --- | --- | | 1 | #54304 | `data/prefetchers/PrefetchableLink.tsx` and `components/ui/**` | | 2 | #54305 | `components/layouts/**` and top-level shell components | | 3 | #54306 | Database, TableGridEditor, Storage, SQLEditor, BranchManagement, Branching, Functions, Realtime | | 4 | #54307 | Integrations, Settings, Observability, LogDrains, Issues, Linter, Reports, QueryPerformance, QuerySources, ConfigDrift, DiskManagement, Compute | | **5** | **#54308 ← this PR** | **Remaining `components/interfaces/**` (Org, Billing, Auth, Support, Home, SignIn, ConnectSheet, etc.)** | | 6 | #54309 | Remove `compat/next/link.tsx` shim, Vite alias, and update basePath tests/docs | Migrates the remaining `components/interfaces/**` directories off `next/link`, leaving zero `next/link` component imports in `apps/studio`. **Changed:** - Replaced `next/link` across all 73 remaining interface files (`Organization`, `OrganizationInvite`, `Billing`, `Auth`, `Support`, `ProjectHome`, `Home`, `Project`, `ProjectCreation`, `ProjectAPIDocs`, `ApiAuthorization`, `App`, `ConnectSheet`, `SignIn`, `APIKeys`, `Account`, `CliLogin`, `Docs`, `JwtSecrets`, `Platform`) - Converted the sole remaining `UrlObject` link (`<Link href={{ pathname: '/sign-in-sso', query }}>`) in `SignInSSOForm.tsx` to `<Link to="/sign-in-sso" search={query}>` - Migrated `SupportLink.tsx` onto `DynamicLink` (`createSupportFormUrl(...)`) - Standardized external `target="_blank"` anchors with `rel="noreferrer noopener"`, switched `OverviewMetrics.tsx` observability link to typed `<Link to="/project/$ref/observability/auth">`, and adopted `InlineLink` / `InlineLinkClassName` on inline paragraph links per review feedback Addresses [FE-5108](https://linear.app/supabase/issue/FE-5108/replace-the-nextlink-shim-with-tanstack-link) ## To test - [ ] Check Organization (billing, usage, team, documents, AWS Marketplace), Auth (providers, templates, rate limits, users, OAuth apps), Support form/links, Project Home, Connect sheet, and Sign-In/SSO links - [ ] Verify `SignInWithSSOButton` preserves query params when navigating to `/sign-in-sso` - [ ] Verify `SupportLink` pre-populates support form query parameters cleanly --------- Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
271 lines
11 KiB
TypeScript
271 lines
11 KiB
TypeScript
import { Link } from '@tanstack/react-router'
|
|
import { useParams } from 'common'
|
|
import { ArrowRightIcon, CheckIcon, ChevronRightIcon, XIcon } from 'lucide-react'
|
|
import { memo, useMemo } from 'react'
|
|
import {
|
|
Badge,
|
|
cn,
|
|
HoverCard,
|
|
HoverCardContent,
|
|
HoverCardTrigger,
|
|
ScrollArea,
|
|
Tooltip,
|
|
TooltipContent,
|
|
TooltipTrigger,
|
|
} from 'ui'
|
|
import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
|
|
|
|
import { isInviteExpired } from '../Organization.utils'
|
|
import { MemberActions } from './MemberActions'
|
|
import { MEMBERS_GRID_CLASS } from './MembersList.constants'
|
|
import { useTeamSettingsData } from './TeamSettingsDataContext'
|
|
import { type RowComponentBaseProps } from '@/components/ui/InfiniteList'
|
|
import { InlineLink } from '@/components/ui/InlineLink'
|
|
import PartnerIcon from '@/components/ui/PartnerIcon'
|
|
import { ProfileImage } from '@/components/ui/ProfileImage'
|
|
import { type OrganizationRole } from '@/data/organization-members/organization-roles-query'
|
|
import { type OrganizationMember } from '@/data/organizations/organization-members-query'
|
|
import { pluralize } from '@/lib/helpers'
|
|
import { useProfile } from '@/lib/profile'
|
|
|
|
const MEMBER_ORIGIN_TO_MANAGED_BY = {
|
|
vercel: 'vercel-marketplace',
|
|
} as const
|
|
|
|
export const MemberRow = memo(function MemberRow({
|
|
item: member,
|
|
index,
|
|
style,
|
|
}: RowComponentBaseProps<OrganizationMember>) {
|
|
const { slug } = useParams()
|
|
const { profile } = useProfile()
|
|
const { roles, isLoadingRoles, totalNumOrgProjects } = useTeamSettingsData()
|
|
|
|
const hasProjectScopedRoles = (roles?.project_scoped_roles ?? []).length > 0
|
|
|
|
const isInvitedUser = Boolean(member.invited_id)
|
|
|
|
// Use generic avatar for all team members instead of attempting to fetch from GitHub
|
|
const profileImageUrl = undefined
|
|
|
|
const roleById = useMemo(() => {
|
|
const map = new Map<number, OrganizationRole>()
|
|
for (const role of roles?.org_scoped_roles ?? []) map.set(role.id, role)
|
|
for (const role of roles?.project_scoped_roles ?? []) map.set(role.id, role)
|
|
return map
|
|
}, [roles])
|
|
|
|
const roleRows = useMemo(() => {
|
|
return member.role_ids.map((id) => {
|
|
const role = roleById.get(id)
|
|
const roleName = (role?.name ?? '').split('_')[0]
|
|
const appliesToAllProjects = role?.projects.length === 0
|
|
const projectsApplied = role?.projects ?? []
|
|
|
|
return { id, roleName, appliesToAllProjects, projectsApplied }
|
|
})
|
|
}, [member.role_ids, roleById])
|
|
|
|
const roleBreakdown = useMemo(
|
|
() =>
|
|
roleRows.flatMap(({ id, roleName, appliesToAllProjects, projectsApplied }) =>
|
|
appliesToAllProjects
|
|
? [{ key: `${id}-all`, roleName, label: 'Organization' }]
|
|
: projectsApplied.map((project) => ({
|
|
key: `${id}-${project.ref}`,
|
|
roleName,
|
|
label: project.name,
|
|
}))
|
|
),
|
|
[roleRows]
|
|
)
|
|
const totalProjectsApplied = roleRows.reduce((sum, row) => sum + row.projectsApplied.length, 0)
|
|
|
|
return (
|
|
<div
|
|
role="row"
|
|
aria-rowindex={index + 2}
|
|
style={style}
|
|
className={cn(
|
|
MEMBERS_GRID_CLASS,
|
|
'border-b last:border-0 hover:bg-surface-200 transition-colors'
|
|
)}
|
|
>
|
|
<div role="cell" className="min-w-0">
|
|
<div className="flex items-center gap-x-4 min-w-0">
|
|
<ProfileImage
|
|
alt={member.primary_email ?? member.username ?? ''}
|
|
src={profileImageUrl}
|
|
className="border rounded-full w-6 h-6 md:w-8 md:h-8 shrink-0"
|
|
placeholder={
|
|
<div
|
|
className={cn(
|
|
'w-6 h-6 md:w-8 md:h-8 text-xs shrink-0',
|
|
'bg-surface-100 border border-overlay rounded-full text-foreground-lighter flex items-center justify-center'
|
|
)}
|
|
>
|
|
{member.primary_email?.[0]?.toUpperCase()}
|
|
</div>
|
|
}
|
|
/>
|
|
<div className="flex items-center gap-x-3 min-w-0">
|
|
<p
|
|
title={member.primary_email ?? ''}
|
|
className="text-foreground-light truncate text-sm"
|
|
>
|
|
{member.primary_email}
|
|
</p>
|
|
<div className="flex items-center gap-x-2 shrink-0 text-sm">
|
|
{member.gotrue_id === profile?.gotrue_id && <Badge>You</Badge>}
|
|
{isInvitedUser && member.invited_at && (
|
|
<Badge variant={isInviteExpired(member.invited_at) ? 'destructive' : 'warning'}>
|
|
{isInviteExpired(member.invited_at) ? 'Expired' : 'Invited'}
|
|
</Badge>
|
|
)}
|
|
{member.is_sso_user && <Badge variant="default">SSO</Badge>}
|
|
{Boolean(member.metadata?.origin) && (
|
|
<PartnerIcon
|
|
organization={{
|
|
managed_by:
|
|
MEMBER_ORIGIN_TO_MANAGED_BY[
|
|
member.metadata.origin as keyof typeof MEMBER_ORIGIN_TO_MANAGED_BY
|
|
] ?? 'supabase',
|
|
}}
|
|
tooltipText="Managed by Vercel Marketplace."
|
|
/>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div role="cell">
|
|
<div className="flex items-center ml-1">
|
|
<Tooltip>
|
|
<TooltipTrigger>
|
|
{member.mfa_enabled ? (
|
|
<CheckIcon className="text-primary" strokeWidth={2} size={16} />
|
|
) : (
|
|
<XIcon className="text-foreground-muted" strokeWidth={1.5} size={16} />
|
|
)}
|
|
</TooltipTrigger>
|
|
<TooltipContent side="bottom" className="max-w-70 text-center">
|
|
{member.mfa_enabled ? (
|
|
'Member has MFA enabled'
|
|
) : (
|
|
<span className="text-balance">
|
|
Member does not have MFA enabled. You can enforce MFA from your organization's{' '}
|
|
<InlineLink href={`/org/${slug}/security`}>security settings</InlineLink>,
|
|
restricting access until members enable it.
|
|
</span>
|
|
)}
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
</div>
|
|
</div>
|
|
|
|
<div role="cell" className="min-w-0">
|
|
{isLoadingRoles ? (
|
|
<ShimmeringLoader className="w-32" />
|
|
) : roleRows.length > 1 ? (
|
|
<div className="flex items-center gap-x-2 min-w-0 text-sm">
|
|
<p className="text-foreground-light whitespace-nowrap">Multiple roles</p>
|
|
<ChevronRightIcon className="text-foreground-muted/50 shrink-0" size={14} />
|
|
<HoverCard openDelay={200}>
|
|
<HoverCardTrigger asChild>
|
|
<span className="text-foreground-light truncate">
|
|
{totalProjectsApplied} {pluralize(totalProjectsApplied, 'project')}
|
|
</span>
|
|
</HoverCardTrigger>
|
|
<HoverCardContent className="p-0">
|
|
<div className="flex flex-col py-1">
|
|
<ScrollArea className={cn(roleBreakdown.length > 5 ? 'h-[130px]' : '')}>
|
|
{roleBreakdown.map(({ key, roleName, label }) => (
|
|
<div key={key} className="px-2 py-1 flex items-center gap-x-2 text-xs">
|
|
<span className="whitespace-nowrap">{roleName}</span>
|
|
<ChevronRightIcon className="text-foreground-muted/50 shrink-0" size={12} />
|
|
<span className="text-foreground-light truncate">{label}</span>
|
|
</div>
|
|
))}
|
|
</ScrollArea>
|
|
</div>
|
|
</HoverCardContent>
|
|
</HoverCard>
|
|
</div>
|
|
) : (
|
|
roleRows.map(({ id, roleName, appliesToAllProjects, projectsApplied }) => (
|
|
<div key={`role-${id}`} className="flex items-center gap-x-2 min-w-0 text-sm">
|
|
<p className="text-foreground-light whitespace-nowrap">{roleName}</p>
|
|
{hasProjectScopedRoles && (
|
|
<>
|
|
<ChevronRightIcon className="text-foreground-muted/50 shrink-0" size={14} />
|
|
{projectsApplied.length === 1 ? (
|
|
<span
|
|
className="text-foreground-light truncate"
|
|
title={projectsApplied[0].name}
|
|
>
|
|
{projectsApplied[0].name}
|
|
</span>
|
|
) : (
|
|
<HoverCard openDelay={200}>
|
|
<HoverCardTrigger asChild>
|
|
<span className="text-foreground-light truncate">
|
|
{appliesToAllProjects
|
|
? 'Organization'
|
|
: `${projectsApplied.length} ${pluralize(projectsApplied.length, 'project')}`}
|
|
</span>
|
|
</HoverCardTrigger>
|
|
<HoverCardContent className="p-0">
|
|
{
|
|
// If the role is org scoped, don't list all projects
|
|
appliesToAllProjects ? (
|
|
<p className="p-2 text-xs">
|
|
{roleName} role applies to {totalNumOrgProjects}{' '}
|
|
{pluralize(totalNumOrgProjects, 'project')}
|
|
</p>
|
|
) : (
|
|
<>
|
|
<p className="p-2 text-xs">
|
|
{roleName} role applies to {projectsApplied.length}{' '}
|
|
{pluralize(projectsApplied.length, 'project')}
|
|
</p>
|
|
<div className="border-t flex flex-col py-1">
|
|
<ScrollArea
|
|
className={cn(projectsApplied.length > 5 ? 'h-[130px]' : '')}
|
|
>
|
|
{projectsApplied.map(({ ref, name }) => (
|
|
<Link
|
|
key={ref}
|
|
to="/project/$ref"
|
|
params={{ ref }}
|
|
className="px-2 py-1 group hover:bg-surface-300 hover:text-foreground transition flex items-center justify-between"
|
|
>
|
|
<span className="text-xs truncate max-w-[60%]">{name}</span>
|
|
<span className="text-xs text-foreground flex items-center gap-x-1 opacity-0 group-hover:opacity-100 transition">
|
|
Go to project
|
|
<ArrowRightIcon size={14} />
|
|
</span>
|
|
</Link>
|
|
))}
|
|
</ScrollArea>
|
|
</div>
|
|
</>
|
|
)
|
|
}
|
|
</HoverCardContent>
|
|
</HoverCard>
|
|
)}
|
|
</>
|
|
)}
|
|
</div>
|
|
))
|
|
)}
|
|
</div>
|
|
|
|
<div role="cell">
|
|
<MemberActions member={member} />
|
|
</div>
|
|
</div>
|
|
)
|
|
})
|