mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
Part 4 of a 6-PR stack migrating all `next/router` and `next/compat/router` imports in `apps/studio` onto TanStack Router hooks and removing the router shims. | Part | PR | Scope | | --- | --- | --- | | 1 | #54053 | Core navigation helpers, `hooks/**`, `lib/**`, `data/prefetchers/**` | | 2 | #54054 | `components/ui/**` | | 3 | #54055 | `components/layouts/**` and `state/tabs.tsx` | | **4** | **#54056 ← this PR** | **Database, Branching, Compute, Edge Functions, Explorer, SQL Editor, Storage, Table Editor** | | 5 | #54057 | Remaining `components/interfaces/**` and `QueryInsightsTable` router events | | 6 | #54058 | Remove `next/router` & `next/compat/router` shims, `_router-events.ts`, Vite aliases, and test mocks | Migrates the database, branching, compute, functions, explorer, SQL editor, storage, and table editor interfaces off `next/router` and `next/compat/router`. **Changed:** - Migrated the sole `next/compat/router` consumer (`components/interfaces/Database/Replication/Destinations.tsx`) to `useNavigate` - Replaced `useRouter` across `BranchManagement`, `Branching`, `Compute`, `Database` (`Backups`, `Functions`, `Replication`, `Schemas`, `Tables`, `Triggers`), `EdgeFunctions`, `Explorer`, `Functions`, `SQLEditor`, `Storage` (`AnalyticsBuckets`, `FilesBuckets`, `VectorBuckets`, `StorageMenuV2`, `Storage.utils`), and `TableGridEditor` with TanStack Router hooks (`useNavigate`, `useLocation`, `useRoutePattern`) and `useParams` from `common` - Updated unit and component tests across `Database/Replication`, `Explorer`, `Functions`, and `Storage/FilesBuckets/DeleteBucketModal.test.tsx` to use TanStack Router **Simplified:** - `useSnippetEditor` and `useRedirectLegacyReadReplicaDestination` read search values from `useParams` instead of casting `location.search` - `resolveSourceSwitch` returns `replace: boolean` instead of a `push`/`replace` method name - `ExplorerQueryTab` and `EdgeFunctionDetails` guard on a defined ref instead of navigating with `ref ?? ''` - `useFunctionsDetailShortcuts` and `StorageMenuV2` use a local `goTo` helper for their navigation shortcuts - Tests use the shared `createTestRouter` and `customRender` router, use `toMatchObject` for search assertions, and drop duplicate assertions Addresses [FE-5109](https://linear.app/supabase/issue/FE-5109/replace-the-nextrouter-shims-with-tanstack-router-hooks) ## To test - [ ] SQL Editor: creating, renaming, moving, opening templates/examples, and keyboard shortcuts navigate between snippets cleanly - [ ] Table Editor & Database: opening tables, schema table nodes, triggers, functions, backups/PITR, and replication destination flows navigate as expected - [ ] Storage: switching between Files, Analytics, and Vector buckets and deleting a bucket navigates cleanly - [ ] Edge Functions & Explorer: opening function details/logs, explorer chat/query tabs, and branch management actions navigate properly --------- Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
55 lines
1.7 KiB
TypeScript
55 lines
1.7 KiB
TypeScript
import { Link } from '@tanstack/react-router'
|
|
import { Button } from 'ui'
|
|
import { Admonition } from 'ui-patterns/Admonition'
|
|
|
|
import { useEditorType } from '@/components/layouts/editors/EditorsLayout.hooks'
|
|
import { useDashboardHistory } from '@/hooks/misc/useDashboardHistory'
|
|
import { useTabRouter, useTabsStateSnapshot } from '@/state/tabs'
|
|
|
|
interface SnippetNotFoundProps {
|
|
id?: string
|
|
projectRef: string
|
|
tabId?: string
|
|
}
|
|
|
|
export const SnippetNotFound = ({ id, projectRef, tabId }: SnippetNotFoundProps) => {
|
|
const router = useTabRouter()
|
|
const editor = useEditorType()
|
|
const tabs = useTabsStateSnapshot()
|
|
const { setLastVisitedSnippet } = useDashboardHistory()
|
|
|
|
return (
|
|
<div className="flex items-center justify-center h-full">
|
|
<div className="w-[400px]">
|
|
<Admonition
|
|
type="default"
|
|
title={`Unable to find snippet with ID ${id}`}
|
|
description="This snippet doesn't exist in your project"
|
|
>
|
|
{!!tabId ? (
|
|
<Button
|
|
className="mt-2"
|
|
onClick={() => {
|
|
tabs.handleTabClose({
|
|
id: tabId,
|
|
router,
|
|
editor,
|
|
onClearDashboardHistory: () => setLastVisitedSnippet(undefined),
|
|
})
|
|
}}
|
|
>
|
|
Close tab
|
|
</Button>
|
|
) : (
|
|
<Button asChild className="mt-2" onClick={() => setLastVisitedSnippet(undefined)}>
|
|
<Link to="/project/$ref/sql" params={{ ref: projectRef }}>
|
|
Head back
|
|
</Link>
|
|
</Button>
|
|
)}
|
|
</Admonition>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|