mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
Part 2 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 ← this PR** | **`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 | 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 all `apps/studio/components/layouts/**` files and top-level navigation shell components off `next/link`. **Changed:** - Replaced `next/link` across `components/layouts/**` (`AccountLayout`, `AppLayout`, `AuthLayout`, `BranchLayout`, `DatabaseLayout`, `EdgeFunctionsLayout`, `ExplorerLayout`, `IssuesLayout`, `LogsLayout`, `Navigation`, `ObservabilityLayout`, `ProjectLayout`, `ProjectNeedsSecuring`, `SQLEditorLayout`, `SignInLayout`, `TableEditorLayout`, `Tabs`) and top-level shell components (`Sidebar.tsx`, `UserDropdown.tsx`, `LocalDropdown.tsx`, `HomePageActions.tsx`) - Removed `vi.mock('next/link', ...)` from `LocalDropdown.test.tsx` and `ProjectNeedsSecuring.test.tsx` - Added accessible labels where external icon/logo links switched from `<Link>` to plain `<a>` (`AdminStudioButton.tsx`, `ForgotPasswordLayout.tsx`) Addresses [FE-5108](https://linear.app/supabase/issue/FE-5108/replace-the-nextlink-shim-with-tanstack-link) ## To test - [ ] Navigate across top header, left sidebar, user/local dropdown, and project/org/branch switchers - [ ] Verify mobile navigation menu items and recent-tab links navigate with expected query params - [ ] Verify sign-in and forgot-password layout links work cleanly --------- Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
241 lines
8.4 KiB
TypeScript
241 lines
8.4 KiB
TypeScript
import { Link, useNavigate } from '@tanstack/react-router'
|
|
import { ArrowRightIcon, CheckIcon, ExternalLinkIcon, LightbulbIcon, XIcon } from 'lucide-react'
|
|
import { useMemo } from 'react'
|
|
import {
|
|
Button,
|
|
Button_Shadcn_,
|
|
Card,
|
|
Table,
|
|
TableBody,
|
|
TableCell,
|
|
TableHead,
|
|
TableHeader,
|
|
TableRow,
|
|
} from 'ui'
|
|
import { PageContainer } from 'ui-patterns/PageContainer'
|
|
import {
|
|
PageHeader,
|
|
PageHeaderAside,
|
|
PageHeaderDescription,
|
|
PageHeaderIcon,
|
|
PageHeaderMeta,
|
|
PageHeaderSummary,
|
|
PageHeaderTitle,
|
|
} from 'ui-patterns/PageHeader'
|
|
import {
|
|
PageSection,
|
|
PageSectionAside,
|
|
PageSectionContent,
|
|
PageSectionMeta,
|
|
PageSectionSummary,
|
|
PageSectionTitle,
|
|
} from 'ui-patterns/PageSection'
|
|
import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'
|
|
|
|
import type {
|
|
ProjectSecurityActionDetails,
|
|
ProjectSecurityActionType,
|
|
ProjectSecurityTable,
|
|
} from './ProjectNeedsSecuring.types'
|
|
import {
|
|
buildSecurityPromptMarkdown,
|
|
formatRlsDescription,
|
|
getTableKey,
|
|
getTablePoliciesHref,
|
|
} from './ProjectNeedsSecuring.utils'
|
|
import { SIDEBAR_KEYS } from '@/components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider'
|
|
import { AiAssistantDropdown } from '@/components/ui/AiAssistantDropdown'
|
|
import { AlertError } from '@/components/ui/AlertError'
|
|
import { createNavigationHandler } from '@/lib/navigation'
|
|
import { useAiAssistantStateSnapshot } from '@/state/ai-assistant-state'
|
|
import { useSidebarManagerSnapshot } from '@/state/sidebar-manager-state'
|
|
|
|
const StatusCell = ({ enabled, label }: { enabled: boolean; label: string }) => (
|
|
<div className="flex items-center gap-2 text-sm">
|
|
{enabled ? (
|
|
<CheckIcon size={14} className="text-primary" aria-hidden="true" />
|
|
) : (
|
|
<XIcon size={14} className="text-destructive" aria-hidden="true" />
|
|
)}
|
|
<span>{label}</span>
|
|
</div>
|
|
)
|
|
|
|
export const ProjectNeedsSecuringView = ({
|
|
projectRef,
|
|
issueCount,
|
|
tables,
|
|
isLoading,
|
|
error,
|
|
onDismiss,
|
|
onTrackAction,
|
|
}: {
|
|
projectRef: string
|
|
issueCount: number
|
|
tables: ProjectSecurityTable[]
|
|
isLoading: boolean
|
|
error?: { message: string } | null
|
|
onDismiss: () => void
|
|
onTrackAction: (type: ProjectSecurityActionType, details?: ProjectSecurityActionDetails) => void
|
|
}) => {
|
|
const navigate = useNavigate()
|
|
const aiSnap = useAiAssistantStateSnapshot()
|
|
const { openSidebar } = useSidebarManagerSnapshot()
|
|
|
|
const promptMarkdown = useMemo(
|
|
() => buildSecurityPromptMarkdown(issueCount, tables),
|
|
[issueCount, tables]
|
|
)
|
|
|
|
const handleOpenAssistant = () => {
|
|
onTrackAction('ask_assistant')
|
|
openSidebar(SIDEBAR_KEYS.AI_ASSISTANT)
|
|
aiSnap.newChat({
|
|
name: 'Review project security',
|
|
initialInput: promptMarkdown,
|
|
})
|
|
}
|
|
|
|
return (
|
|
<div className="flex flex-1 flex-col overflow-y-auto">
|
|
<PageHeader size="default">
|
|
<PageHeaderMeta>
|
|
<PageHeaderIcon>
|
|
<div className="shrink-0 w-14 h-14 relative bg-destructive-200 border border-destructive-400 rounded-md flex items-center justify-center">
|
|
<LightbulbIcon size={20} strokeWidth={1.5} className="text-destructive" />
|
|
</div>
|
|
</PageHeaderIcon>
|
|
<PageHeaderSummary>
|
|
<PageHeaderTitle>Your project needs securing</PageHeaderTitle>
|
|
<PageHeaderDescription>{formatRlsDescription(issueCount)}</PageHeaderDescription>
|
|
</PageHeaderSummary>
|
|
<PageHeaderAside>
|
|
<Button asChild variant="text" iconRight={<ArrowRightIcon />}>
|
|
<Link
|
|
to="/project/$ref"
|
|
params={{ ref: projectRef }}
|
|
onClick={() => {
|
|
onTrackAction('skip_to_home')
|
|
onDismiss()
|
|
}}
|
|
>
|
|
Skip to home
|
|
</Link>
|
|
</Button>
|
|
</PageHeaderAside>
|
|
</PageHeaderMeta>
|
|
</PageHeader>
|
|
|
|
<PageContainer size="default" className="pb-12">
|
|
<PageSection>
|
|
<PageSectionMeta>
|
|
<PageSectionSummary>
|
|
<PageSectionTitle>Review and fix</PageSectionTitle>
|
|
</PageSectionSummary>
|
|
<PageSectionAside>
|
|
<AiAssistantDropdown
|
|
label="Ask Assistant"
|
|
size="tiny"
|
|
buildPrompt={() => promptMarkdown}
|
|
onOpenAssistant={handleOpenAssistant}
|
|
onCopyPrompt={() => onTrackAction('copy_prompt')}
|
|
copyLabel="Copy Markdown"
|
|
disabled={isLoading}
|
|
/>
|
|
</PageSectionAside>
|
|
</PageSectionMeta>
|
|
<PageSectionContent>
|
|
{isLoading ? (
|
|
<GenericSkeletonLoader />
|
|
) : error ? (
|
|
<AlertError
|
|
projectRef={projectRef}
|
|
error={error}
|
|
subject="Failed to retrieve project tables"
|
|
/>
|
|
) : (
|
|
<Card>
|
|
<Table>
|
|
<TableHeader>
|
|
<TableRow>
|
|
<TableHead>Name</TableHead>
|
|
<TableHead>Schema</TableHead>
|
|
<TableHead>
|
|
<div className="flex items-center gap-1.5">
|
|
<span>Accessible via Data API</span>
|
|
<Button_Shadcn_ asChild variant="ghost" size="icon" className="h-6 w-6">
|
|
<Link
|
|
to="/project/$ref/integrations/$id/$pageId"
|
|
params={{ ref: projectRef, id: 'data_api', pageId: 'settings' }}
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
aria-label="Open Data API settings"
|
|
>
|
|
<ExternalLinkIcon size={14} aria-hidden="true" />
|
|
</Link>
|
|
</Button_Shadcn_>
|
|
</div>
|
|
</TableHead>
|
|
<TableHead>RLS</TableHead>
|
|
</TableRow>
|
|
</TableHeader>
|
|
<TableBody>
|
|
{tables.map((table) => {
|
|
const policiesHref = getTablePoliciesHref(
|
|
projectRef,
|
|
table.schema,
|
|
table.name
|
|
)
|
|
const handleNavigation = createNavigationHandler(policiesHref, navigate)
|
|
const trackViewPolicies = () =>
|
|
onTrackAction('view_policies', {
|
|
schema: table.schema,
|
|
tableName: table.name,
|
|
})
|
|
|
|
return (
|
|
<TableRow
|
|
key={getTableKey(table)}
|
|
className="relative cursor-pointer focus-inset"
|
|
onClick={(event) => {
|
|
trackViewPolicies()
|
|
handleNavigation(event)
|
|
}}
|
|
onAuxClick={(event) => {
|
|
if (event.button === 1) trackViewPolicies()
|
|
handleNavigation(event)
|
|
}}
|
|
onKeyDown={(event) => {
|
|
if (event.key === 'Enter' || event.key === ' ') trackViewPolicies()
|
|
handleNavigation(event)
|
|
}}
|
|
tabIndex={0}
|
|
>
|
|
<TableCell className="font-medium">{table.name}</TableCell>
|
|
<TableCell>{table.schema}</TableCell>
|
|
<TableCell>
|
|
<StatusCell
|
|
enabled={table.dataApiAccessible}
|
|
label={table.dataApiAccessible ? 'Accessible' : 'Not accessible'}
|
|
/>
|
|
</TableCell>
|
|
<TableCell>
|
|
<StatusCell
|
|
enabled={table.rlsEnabled}
|
|
label={table.rlsEnabled ? 'Enabled' : 'Disabled'}
|
|
/>
|
|
</TableCell>
|
|
</TableRow>
|
|
)
|
|
})}
|
|
</TableBody>
|
|
</Table>
|
|
</Card>
|
|
)}
|
|
</PageSectionContent>
|
|
</PageSection>
|
|
</PageContainer>
|
|
</div>
|
|
)
|
|
}
|