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>
57 lines
2.2 KiB
TypeScript
57 lines
2.2 KiB
TypeScript
import { useNavigate } from '@tanstack/react-router'
|
|
import { useParams } from 'common'
|
|
import { Button, GithubIcon } from 'ui'
|
|
|
|
import { useGitHubAuthorizationQuery } from '@/data/integrations/github-authorization-query'
|
|
import { useGitHubConnectionsQuery } from '@/data/integrations/github-connections-query'
|
|
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
import { openInstallGitHubIntegrationWindow } from '@/lib/github'
|
|
import { navigateToUrl } from '@/lib/navigation'
|
|
import { useAppStateSnapshot } from '@/state/app-state'
|
|
|
|
export const ConnectToGitHub = () => {
|
|
const navigate = useNavigate()
|
|
const { ref } = useParams()
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const { data: selectedOrg } = useSelectedOrganizationQuery()
|
|
const { showCreateBranchModal, setShowCreateBranchModal } = useAppStateSnapshot()
|
|
|
|
const isBranch = project?.parent_project_ref !== undefined
|
|
const projectRef =
|
|
project !== undefined ? (isBranch ? project.parent_project_ref : ref) : undefined
|
|
|
|
const { data: gitHubAuthorization } = useGitHubAuthorizationQuery()
|
|
|
|
const { data: connections } = useGitHubConnectionsQuery(
|
|
{ organizationId: selectedOrg?.id },
|
|
{ enabled: showCreateBranchModal }
|
|
)
|
|
const githubConnection = connections?.find((connection) => connection.project.ref === projectRef)
|
|
|
|
const showAuthorizeCta = githubConnection && !gitHubAuthorization
|
|
|
|
const onClick = () => {
|
|
if (showAuthorizeCta) {
|
|
openInstallGitHubIntegrationWindow('authorize')
|
|
} else {
|
|
if (showCreateBranchModal) setShowCreateBranchModal(false)
|
|
void navigateToUrl(navigate, `/project/${projectRef}/settings/integrations`)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="flex items-center gap-2 justify-between">
|
|
<div className="flex flex-col gap-1">
|
|
<span className="text-sm text leading-none">Sync with a GitHub branch</span>
|
|
<p className="text-sm text-foreground-lighter">
|
|
Keep this preview branch in sync with a chosen GitHub branch
|
|
</p>
|
|
</div>
|
|
<Button icon={<GithubIcon />} onClick={onClick}>
|
|
{showAuthorizeCta ? 'Authorize' : 'Configure'}
|
|
</Button>
|
|
</div>
|
|
)
|
|
}
|