mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +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>
326 lines
10 KiB
TypeScript
326 lines
10 KiB
TypeScript
import { Link, useLocation } from '@tanstack/react-router'
|
|
import { IS_PLATFORM, useParams } from 'common'
|
|
import { ChevronRightIcon, PlusIcon } from 'lucide-react'
|
|
import React, { useState } from 'react'
|
|
import { Button, cn, Collapsible, CollapsibleContent, CollapsibleTrigger, Separator } from 'ui'
|
|
import {
|
|
InnerSideBarEmptyPanel,
|
|
InnerSideBarFilters,
|
|
InnerSideBarFilterSearchInput,
|
|
InnerSideMenuItem,
|
|
} from 'ui-patterns/InnerSideMenu'
|
|
import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'
|
|
|
|
import { FeaturePreviewSidebarPanel } from '../../ui/FeaturePreviewSidebarPanel'
|
|
import { LOG_DRAIN_TYPES } from '@/components/interfaces/LogDrains/LogDrains.constants'
|
|
import { SavedQueriesItem } from '@/components/interfaces/Settings/Logs/Logs.SavedQueriesItem'
|
|
import { LogsSidebarItem } from '@/components/interfaces/Settings/Logs/SidebarV2/SidebarItem'
|
|
import { UnifiedLogsBanner } from '@/components/interfaces/UnifiedLogs/UnifiedLogsBanner'
|
|
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
|
|
import { useContentQuery } from '@/data/content/content-query'
|
|
import { useCheckEntitlements } from '@/hooks/misc/useCheckEntitlements'
|
|
import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
|
|
import { useShowMultigresLogs } from '@/hooks/misc/useShowMultigresLogs'
|
|
import { useShowPipelinesLogs } from '@/hooks/misc/useShowPipelinesLogs'
|
|
import { useShowPostgresUpgradeLogs } from '@/hooks/misc/useShowPostgresUpgradeLogs'
|
|
|
|
export function SidebarCollapsible({
|
|
children,
|
|
title,
|
|
defaultOpen,
|
|
}: {
|
|
children: React.ReactNode
|
|
title: string
|
|
defaultOpen?: boolean
|
|
}) {
|
|
return (
|
|
<Collapsible defaultOpen={defaultOpen}>
|
|
<CollapsibleTrigger className="flex items-center gap-x-2 px-4 [&[data-state=open]>svg]:rotate-90! pb-2">
|
|
<ChevronRightIcon
|
|
size={16}
|
|
className={'text-foreground-light transition-transform duration-200'}
|
|
/>
|
|
|
|
<span className="text-foreground-light font-mono text-sm uppercase">{title}</span>
|
|
</CollapsibleTrigger>
|
|
<CollapsibleContent>{children}</CollapsibleContent>
|
|
</Collapsible>
|
|
)
|
|
}
|
|
|
|
export function LogsSidebarMenuV2() {
|
|
const href = useLocation({ select: (location) => location.href })
|
|
const { ref } = useParams() as { ref: string }
|
|
|
|
const [searchText, setSearchText] = useState('')
|
|
|
|
const {
|
|
projectAuthAll: authEnabled,
|
|
projectStorageAll: storageEnabled,
|
|
realtimeAll: realtimeEnabled,
|
|
logsTemplates: templatesEnabled,
|
|
logsCollections: collectionsEnabled,
|
|
} = useIsFeatureEnabled([
|
|
'project_storage:all',
|
|
'project_auth:all',
|
|
'realtime:all',
|
|
'logs:templates',
|
|
'logs:collections',
|
|
])
|
|
|
|
const { showPipelinesLogs } = useShowPipelinesLogs()
|
|
|
|
const { hasAccess: hasDedicatedPooler } = useCheckEntitlements('dedicated_pooler')
|
|
const showMultigresLogs = useShowMultigresLogs()
|
|
const showPostgresUpgradeLogs = useShowPostgresUpgradeLogs()
|
|
|
|
const { data: savedQueriesRes, isPending: savedQueriesLoading } = useContentQuery({
|
|
projectRef: ref,
|
|
type: 'log_sql',
|
|
})
|
|
|
|
const savedQueries = [...(savedQueriesRes?.content ?? [])]
|
|
.filter((c) => c.type === 'log_sql')
|
|
.sort((a, b) => a.name.localeCompare(b.name))
|
|
|
|
function isActive(path: string) {
|
|
return href.includes(path)
|
|
}
|
|
|
|
const BASE_COLLECTIONS = [
|
|
{
|
|
name: 'API Gateway',
|
|
key: 'edge-logs',
|
|
url: `/project/${ref}/logs/edge-logs`,
|
|
items: [],
|
|
},
|
|
{
|
|
name: 'Postgres',
|
|
key: 'postgres-logs',
|
|
url: `/project/${ref}/logs/postgres-logs`,
|
|
items: [],
|
|
},
|
|
{
|
|
name: 'PostgREST',
|
|
key: 'postgrest-logs',
|
|
url: `/project/${ref}/logs/postgrest-logs`,
|
|
items: [],
|
|
},
|
|
IS_PLATFORM
|
|
? {
|
|
name: hasDedicatedPooler ? 'Shared Pooler' : 'Pooler',
|
|
key: 'pooler-logs',
|
|
url: `/project/${ref}/logs/pooler-logs`,
|
|
items: [],
|
|
}
|
|
: null,
|
|
hasDedicatedPooler && IS_PLATFORM
|
|
? {
|
|
name: 'Dedicated Pooler',
|
|
key: 'dedicated-pooler-logs',
|
|
url: `/project/${ref}/logs/dedicated-pooler-logs`,
|
|
items: [],
|
|
}
|
|
: null,
|
|
authEnabled
|
|
? {
|
|
name: 'Auth',
|
|
key: 'auth-logs',
|
|
url: `/project/${ref}/logs/auth-logs`,
|
|
items: [],
|
|
}
|
|
: null,
|
|
storageEnabled
|
|
? {
|
|
name: 'Storage',
|
|
key: 'storage-logs',
|
|
url: `/project/${ref}/logs/storage-logs`,
|
|
items: [],
|
|
}
|
|
: null,
|
|
realtimeEnabled
|
|
? {
|
|
name: 'Realtime',
|
|
key: 'realtime-logs',
|
|
url: `/project/${ref}/logs/realtime-logs`,
|
|
items: [],
|
|
}
|
|
: null,
|
|
{
|
|
name: 'Edge Functions',
|
|
key: 'edge-functions-logs',
|
|
url: `/project/${ref}/logs/edge-functions-logs`,
|
|
items: [],
|
|
},
|
|
{
|
|
name: 'Cron',
|
|
key: 'pg_cron',
|
|
url: `/project/${ref}/logs/pgcron-logs`,
|
|
items: [],
|
|
},
|
|
showPipelinesLogs
|
|
? {
|
|
name: 'Pipelines',
|
|
key: 'pipelines-logs',
|
|
url: `/project/${ref}/logs/pipelines-logs`,
|
|
items: [],
|
|
}
|
|
: null,
|
|
showMultigresLogs
|
|
? {
|
|
name: 'Multigres',
|
|
key: 'multigres-logs',
|
|
url: `/project/${ref}/logs/multigres-logs`,
|
|
items: [],
|
|
}
|
|
: null,
|
|
].filter((x) => x !== null)
|
|
|
|
const OPERATIONAL_COLLECTIONS =
|
|
IS_PLATFORM && showPostgresUpgradeLogs
|
|
? [
|
|
{
|
|
name: 'Postgres Version Upgrade',
|
|
key: 'pg-upgrade-logs',
|
|
url: `/project/${ref}/logs/pg-upgrade-logs`,
|
|
items: [],
|
|
},
|
|
]
|
|
: []
|
|
|
|
const filteredLogs = BASE_COLLECTIONS.filter((collection) => {
|
|
return collection?.name.toLowerCase().includes(searchText.toLowerCase())
|
|
})
|
|
const filteredOperationalLogs = OPERATIONAL_COLLECTIONS.filter((collection) => {
|
|
return collection?.name.toLowerCase().includes(searchText.toLowerCase())
|
|
})
|
|
|
|
return (
|
|
<div className="pb-4 relative">
|
|
<UnifiedLogsBanner />
|
|
|
|
<div
|
|
className={cn(
|
|
'flex gap-x-2 items-center sticky top-0 bg-dash-sidebar z-1 px-4',
|
|
!templatesEnabled ? 'pt-4' : 'py-4'
|
|
)}
|
|
>
|
|
<InnerSideBarFilters className="w-full p-0 gap-0">
|
|
<InnerSideBarFilterSearchInput
|
|
name="search-collections"
|
|
placeholder="Search collections..."
|
|
aria-labelledby="Search collections"
|
|
value={searchText}
|
|
onChange={(e) => setSearchText(e.target.value)}
|
|
/>
|
|
</InnerSideBarFilters>
|
|
|
|
<ButtonTooltip
|
|
asChild
|
|
icon={<PlusIcon className="text-foreground" />}
|
|
className="w-[26px]"
|
|
tooltip={{ content: { text: 'New query', side: 'bottom' } }}
|
|
>
|
|
<Link to="/project/$ref/logs/explorer" params={{ ref: ref ?? '_' }} />
|
|
</ButtonTooltip>
|
|
</div>
|
|
{templatesEnabled && (
|
|
<div className="px-2">
|
|
<InnerSideMenuItem
|
|
title="Templates"
|
|
isActive={isActive(`/project/${ref}/logs/explorer/templates`)}
|
|
href={`/project/${ref}/logs/explorer/templates`}
|
|
>
|
|
Templates
|
|
</InnerSideMenuItem>
|
|
</div>
|
|
)}
|
|
<Separator className="my-4" />
|
|
|
|
{collectionsEnabled && (
|
|
<>
|
|
<SidebarCollapsible title="Collections" defaultOpen={true}>
|
|
{filteredLogs.map((collection) => {
|
|
const isItemActive = isActive(collection?.url ?? '')
|
|
return (
|
|
<LogsSidebarItem
|
|
key={collection?.key ?? ''}
|
|
isActive={isItemActive}
|
|
href={collection?.url ?? ''}
|
|
label={collection?.name ?? ''}
|
|
/>
|
|
)
|
|
})}
|
|
</SidebarCollapsible>
|
|
{OPERATIONAL_COLLECTIONS.length > 0 && (
|
|
<>
|
|
<Separator className="my-4" />
|
|
<SidebarCollapsible title="Database operations" defaultOpen={true}>
|
|
{filteredOperationalLogs.map((collection) => (
|
|
<LogsSidebarItem
|
|
key={collection.key}
|
|
isActive={isActive(collection.url)}
|
|
href={collection.url}
|
|
label={collection.name}
|
|
/>
|
|
))}
|
|
</SidebarCollapsible>
|
|
</>
|
|
)}
|
|
<Separator className="my-4" />
|
|
</>
|
|
)}
|
|
<SidebarCollapsible title="Queries" defaultOpen={true}>
|
|
{savedQueriesLoading && (
|
|
<div className="p-4">
|
|
<GenericSkeletonLoader />
|
|
</div>
|
|
)}
|
|
{savedQueries.length === 0 && (
|
|
<InnerSideBarEmptyPanel
|
|
className="mx-4"
|
|
title="No queries created yet"
|
|
description={
|
|
IS_PLATFORM ? 'Create and save your queries to use them in the explorer' : undefined
|
|
}
|
|
actions={
|
|
<Button asChild>
|
|
<Link to="/project/$ref/logs/explorer" params={{ ref: ref ?? '_' }}>
|
|
Create query
|
|
</Link>
|
|
</Button>
|
|
}
|
|
/>
|
|
)}
|
|
{savedQueries.map((query) => (
|
|
<SavedQueriesItem item={query} key={query.id} />
|
|
))}
|
|
</SidebarCollapsible>
|
|
|
|
<Separator className="my-4" />
|
|
|
|
<FeaturePreviewSidebarPanel
|
|
className="mx-4 mt-4"
|
|
title="Capture your logs"
|
|
description="Send logs to your preferred observability or storage platform."
|
|
illustration={
|
|
<div className="flex items-center gap-4">
|
|
{LOG_DRAIN_TYPES.filter((t) =>
|
|
['datadog', 'sentry', 'webhook', 'loki'].includes(t.value)
|
|
).map((type) =>
|
|
React.cloneElement(type.icon, { key: type.name, height: 20, width: 20 })
|
|
)}
|
|
</div>
|
|
}
|
|
actions={
|
|
<Button asChild>
|
|
<Link to="/project/$ref/settings/log-drains" params={{ ref: ref ?? '_' }}>
|
|
Go to Log Drains
|
|
</Link>
|
|
</Button>
|
|
}
|
|
/>
|
|
</div>
|
|
)
|
|
}
|