Files
supabase/apps/studio/routes/project/$ref/explorer/index.tsx
Alaister YoungandAlaister Young f8cbf2ae56 [FE-3106] (part 11) – refactor(studio): move sql, editor, explorer and integrations (#53220)
Moves the SQL editor, table editor, explorer and project integrations
page bodies into their route files and deletes the pages (FE-3106). Part
11 of the stack.

**Depends on:** #53219

**Changed:**
- `routes/project/$ref/{sql,editor,explorer,integrations}/**` – 15 page
bodies inlined. Every `router.push/replace` became the equivalent
`navigate` with the same path, `search` and `replace`; the
last-opened-table redirect splits `buildTableEditorUrl`'s absolute URL
with `splitInternalUrl` so it stays a client-side navigation
- `components/interfaces/SQLEditor/SnippetNotFound.tsx` – the
invalid-snippet state moves out of the route because
`tabs.handleTabClose` still takes a Next-shaped router
- `tests/routes/project/$ref/explorer/index.test.tsx` – moved and
rendered with `renderRoute`

**Removed:**
- 15 page files

Addresses
[FE-3106](https://linear.app/supabase/issue/FE-3106/move-page-bodies-into-route-files-and-delete-pages).

## To test

- SQL editor: open `/sql` (redirects to the last snippet or `new`),
open/close snippets and tabs, an invalid snippet id shows "Unable to
find snippet"
- Table editor: open `/editor` (redirects to the last table), create a
table – lands on it with `?schema=`
- Explorer and Integrations pages – same layout; integration sub-pages
redirect as before

---------

Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
2026-11-17 16:52:36 +09:00

115 lines
3.4 KiB
TypeScript

import { createFileRoute, useNavigate } from '@tanstack/react-router'
import { useEffect, useEffectEvent } from 'react'
import {
ExplorerHomeLoading,
ExplorerHomeTab,
} from '@/components/interfaces/Explorer/ExplorerHomeTab'
import { useLoadNotebook } from '@/components/interfaces/Explorer/hooks'
import { useDashboardHistory } from '@/hooks/misc/useDashboardHistory'
import { useAiAssistantStateSnapshot } from '@/state/ai-assistant-state'
import { explorerQueryState } from '@/state/explorer-query'
import { EXPLORER_HOME_TAB, useTabsStateSnapshot } from '@/state/tabs'
export const Route = createFileRoute('/project/$ref/explorer/')({
component: ProjectExplorerPage,
})
function ProjectExplorerPage() {
const navigate = useNavigate()
const { ref: projectRef } = Route.useParams()
const tabs = useTabsStateSnapshot()
const aiAssistant = useAiAssistantStateSnapshot()
const { history, isHistoryLoaded, setLastVisitedExplorerTab } = useDashboardHistory()
const lastVisited = history.explorer
const lastVisitedNotebookId = lastVisited?.type === 'notebook' ? lastVisited.id : undefined
const { isNotFound: isNotebookNotFound, isLoading: isNotebookLoading } = useLoadNotebook({
id: lastVisitedNotebookId,
projectRef,
})
const activateHomeTab = useEffectEvent(() => {
tabs.activatePinnedTab(EXPLORER_HOME_TAB)
})
// Redirects to the last opened Explorer tab if it still exists, otherwise falls
// back to (and stays on) the Home tab. Existence is checked per tab type: query
// drafts and chats are local and resolve synchronously, notebooks require the
// server round trip in `useLoadNotebook` above to resolve first.
const goToLastVisitedTab = useEffectEvent(() => {
if (!projectRef) return
if (!lastVisited) {
activateHomeTab()
return
}
if (lastVisited.type === 'query') {
const exists = explorerQueryState.restoreDraft({ id: lastVisited.id, projectRef })
if (exists) {
void navigate({
to: '/project/$ref/explorer/query/$id',
params: { ref: projectRef, id: lastVisited.id },
replace: true,
})
} else {
setLastVisitedExplorerTab(undefined)
activateHomeTab()
}
return
}
if (lastVisited.type === 'chat') {
if (!aiAssistant.isInitialized) return
if (aiAssistant.chats[lastVisited.id]) {
void navigate({
to: '/project/$ref/explorer/chat/$id',
params: { ref: projectRef, id: lastVisited.id },
replace: true,
})
} else {
setLastVisitedExplorerTab(undefined)
activateHomeTab()
}
return
}
// notebook
if (isNotebookLoading) return
if (isNotebookNotFound) {
setLastVisitedExplorerTab(undefined)
activateHomeTab()
} else {
void navigate({
to: '/project/$ref/explorer/notebook/$id',
params: { ref: projectRef, id: lastVisited.id },
replace: true,
})
}
})
useEffect(() => {
if (isHistoryLoaded) goToLastVisitedTab()
}, [
isHistoryLoaded,
projectRef,
lastVisited?.type,
lastVisited?.id,
aiAssistant.isInitialized,
isNotebookLoading,
isNotebookNotFound,
])
const isCheckingLastTab =
!projectRef ||
!isHistoryLoaded ||
(lastVisited?.type === 'chat' && !aiAssistant.isInitialized) ||
(lastVisited?.type === 'notebook' && isNotebookLoading)
if (isCheckingLastTab) return <ExplorerHomeLoading />
return <ExplorerHomeTab />
}