mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +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>
56 lines
1.8 KiB
TypeScript
56 lines
1.8 KiB
TypeScript
import { createFileRoute } from '@tanstack/react-router'
|
|
import { useParams } from 'common'
|
|
import { useEffect } from 'react'
|
|
|
|
import { TableGridEditor } from '@/components/interfaces/TableGridEditor/TableGridEditor'
|
|
import { useTableEditorQuery } from '@/data/table-editor/table-editor-query'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
import { createTabId, useTabsStateSnapshot } from '@/state/tabs'
|
|
|
|
export const Route = createFileRoute('/project/$ref/editor/$id')({
|
|
component: TableEditorPage,
|
|
})
|
|
|
|
function TableEditorPage() {
|
|
const { id: _id, ref: projectRef } = useParams()
|
|
const id = _id ? Number(_id) : undefined
|
|
const store = useTabsStateSnapshot()
|
|
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const { data: selectedTable, isPending: isLoading } = useTableEditorQuery({
|
|
projectRef: project?.ref,
|
|
connectionString: project?.connectionString,
|
|
id,
|
|
})
|
|
|
|
/**
|
|
* Effect: Creates or updates tab when table is loaded
|
|
* Runs when:
|
|
* - selectedTable changes (when a new table is loaded)
|
|
* - id changes (when URL parameter changes)
|
|
*/
|
|
|
|
useEffect(() => {
|
|
if (selectedTable && projectRef) {
|
|
const tabId = createTabId(selectedTable.entity_type, { id: selectedTable.id })
|
|
if (!store.tabsMap[tabId]) {
|
|
store.addTab({
|
|
id: tabId,
|
|
type: selectedTable.entity_type,
|
|
label: selectedTable.name,
|
|
metadata: {
|
|
schema: selectedTable.schema,
|
|
name: selectedTable.name,
|
|
tableId: id,
|
|
},
|
|
})
|
|
} else {
|
|
// If tab already exists, just make it active
|
|
store.makeTabActive(tabId)
|
|
}
|
|
}
|
|
}, [selectedTable, id, projectRef])
|
|
|
|
return <TableGridEditor isLoadingSelectedTable={isLoading} selectedTable={selectedTable} />
|
|
}
|