mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 23:49:03 +00:00
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>
51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
import { createFileRoute, useNavigate } from '@tanstack/react-router'
|
|
import { useEffect } from 'react'
|
|
|
|
import { useDashboardHistory } from '@/hooks/misc/useDashboardHistory'
|
|
import { useTabsStateSnapshot } from '@/state/tabs'
|
|
|
|
export const Route = createFileRoute('/project/$ref/sql/')({
|
|
component: SQLEditorIndexPage,
|
|
})
|
|
|
|
function SQLEditorIndexPage() {
|
|
const navigate = useNavigate()
|
|
const { ref: projectRef } = Route.useParams()
|
|
const store = useTabsStateSnapshot()
|
|
|
|
const { history, isHistoryLoaded } = useDashboardHistory()
|
|
|
|
useEffect(() => {
|
|
if (isHistoryLoaded) {
|
|
// Handle redirect to last opened snippet tab, or last snippet tab
|
|
const lastOpenedTab = history.sql
|
|
const lastTabId = store.openTabs.find((id) => store.tabsMap[id]?.type === 'sql')
|
|
if (lastOpenedTab !== undefined) {
|
|
void navigate({
|
|
to: '/project/$ref/sql/$id',
|
|
params: { ref: projectRef, id: lastOpenedTab },
|
|
replace: true,
|
|
})
|
|
} else if (lastTabId) {
|
|
const lastTab = store.tabsMap[lastTabId]
|
|
if (lastTab) {
|
|
void navigate({
|
|
to: '/project/$ref/sql/$id',
|
|
params: { ref: projectRef, id: lastTab.id.replace('sql-', '') },
|
|
replace: true,
|
|
})
|
|
}
|
|
} else {
|
|
void navigate({
|
|
to: '/project/$ref/sql/$id',
|
|
params: { ref: projectRef, id: 'new' },
|
|
replace: true,
|
|
})
|
|
}
|
|
}
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [isHistoryLoaded])
|
|
|
|
return null
|
|
}
|