Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix: Refactor all Table Editor links to include sorts and filters (#41075)

Ivan Vasilova36b65e7a368
diff --git a/apps/studio/components/grid/SupabaseGrid.utils.ts b/apps/studio/components/grid/SupabaseGrid.utils.ts
index b6401bbbb8b..289acb87910 100644
--- a/apps/studio/components/grid/SupabaseGrid.utils.ts
+++ b/apps/studio/components/grid/SupabaseGrid.utils.ts
@@ -5,16 +5,15 @@ import { CalculatedColumn, CellKeyboardEvent } from 'react-data-grid'
import type { Filter, SavedState } from 'components/grid/types'
import { Entity, isTableLike } from 'data/table-editor/table-editor-types'
+import { BASE_PATH } from 'lib/constants'
import { useSearchParams } from 'next/navigation'
-import { parseAsBoolean, parseAsNativeArrayOf, parseAsString, useQueryStates } from 'nuqs'
+import { parseAsNativeArrayOf, parseAsString, useQueryStates } from 'nuqs'
import { copyToClipboard } from 'ui'
import { FilterOperatorOptions } from './components/header/filter/Filter.constants'
import { STORAGE_KEY_PREFIX } from './constants'
import type { Sort, SupaColumn, SupaTable } from './types'
import { formatClipboardValue } from './utils/common'
-export const LOAD_TAB_FROM_CACHE_PARAM = 'loadFromCache'
-
export function formatSortURLParams(tableName: string, sort?: string[]): Sort[] {
if (Array.isArray(sort)) {
return compact(
@@ -29,7 +28,7 @@ export function formatSortURLParams(tableName: string, sort?: string[]): Sort[]
return []
}
-export function sortsToUrlParams(sorts: Sort[]) {
+export function sortsToUrlParams(sorts: { column: string; ascending?: boolean }[]) {
return sorts.map((sort) => `${sort.column}:${sort.ascending ? 'asc' : 'desc'}`)
}
@@ -54,7 +53,9 @@ export function formatFilterURLParams(filter?: string[]): Filter[] {
) as Filter[]
}
-export function filtersToUrlParams(filters: Filter[]) {
+export function filtersToUrlParams(
+ filters: { column: string | Array<string>; operator: string; value: string }[]
+) {
return filters.map((filter) => {
const selectedOperator = FilterOperatorOptions.find(
(option) => option.value === filter.operator
@@ -134,50 +135,75 @@ export function getStorageKey(prefix: string, ref: string) {
export function loadTableEditorStateFromLocalStorage(
projectRef: string,
- tableName: string,
- schema?: string | null
+ tableId: number
): SavedState | undefined {
const storageKey = getStorageKey(STORAGE_KEY_PREFIX, projectRef)
// Prefer sessionStorage (scoped to current tab) over localStorage
const jsonStr = sessionStorage.getItem(storageKey) ?? localStorage.getItem(storageKey)
if (!jsonStr) return
const json = JSON.parse(jsonStr)
- const tableKey = !schema || schema == 'public' ? tableName : `${schema}.${tableName}`
- return json[tableKey]
+ return json[tableId]
+}
+
+/**
+ * Builds a table editor URL with the given project reference, table ID. It will load the saved state from local storage
+ * and add the sort and filter parameters to the URL.
+ */
+export function buildTableEditorUrl({
+ projectRef = 'default',
+ tableId,
+ schema,
+}: {
+ projectRef?: string
+ tableId: number
+ schema?: string
+}) {
+ const url = new URL(`${BASE_PATH}/project/${projectRef}/editor/${tableId}`, location.origin)
+
+ // If the schema is provided, add it to the URL so that the left sidebar is opened to the correct schema
+ if (schema) {
+ url.searchParams.set('schema', schema)
+ }
+
+ const savedState = loadTableEditorStateFromLocalStorage(projectRef, tableId)
+ if (savedState?.sorts && savedState.sorts.length > 0) {
+ savedState.sorts?.forEach((sort) => url.searchParams.append('sort', sort))
+ }
+ if (savedState?.filters && savedState.filters.length > 0) {
+ savedState.filters?.forEach((filter) => url.searchParams.append('filter', filter))
+ }
+ return url.toString()
}
export function saveTableEditorStateToLocalStorage({
projectRef,
- tableName,
- schema,
+ tableId,
gridColumns,
sorts,
filters,
}: {
projectRef: string
- tableName: string
- schema?: string | null
+ tableId: number
gridColumns?: CalculatedColumn<any, any>[]
sorts?: string[]
filters?: string[]
}) {
const storageKey = getStorageKey(STORAGE_KEY_PREFIX, projectRef)
const savedStr = sessionStorage.getItem(storageKey) ?? localStorage.getItem(storageKey)
- const tableKey = !schema || schema == 'public' ? tableName : `${schema}.${tableName}`
const config = {
...(gridColumns !== undefined && { gridColumns }),
- ...(sorts !== undefined && { sorts }),
- ...(filters !== undefined && { filters }),
+ ...(sorts !== undefined && { sorts: sorts.filter((sort) => sort !== '') }),
+ ...(filters !== undefined && { filters: filters.filter((filter) => filter !== '') }),
}
let savedJson
if (savedStr) {
savedJson = JSON.parse(savedStr)
- const previousConfig = savedJson[tableKey]
- savedJson = { ...savedJson, [tableKey]: { ...previousConfig, ...config } }
+ const previousConfig = savedJson[tableId]
+ savedJson = { ...savedJson, [tableId]: { ...previousConfig, ...config } }
} else {
- savedJson = { [tableKey]: config }
+ savedJson = { [tableId]: config }
}
// Save to both localStorage and sessionStorage so it's consistent to current tab
localStorage.setItem(storageKey, JSON.stringify(savedJson))
@@ -193,8 +219,7 @@ function getLatestParams() {
const queryParams = new URLSearchParams(window.location.search)
const sort = queryParams.getAll('sort')
const filter = queryParams.getAll('filter')
- const loadFromCache = !!queryParams.get(LOAD_TAB_FROM_CACHE_PARAM)
- return { sort, filter, loadFromCache }
+ return { sort, filter }
}
export function useSyncTableEditorStateFromLocalStorageWithUrl({
@@ -209,7 +234,6 @@ export function useSyncTableEditorStateFromLocalStorageWithUrl({
{
sort: parseAsNativeArrayOf(parseAsString),
filter: parseAsNativeArrayOf(parseAsString),
- [LOAD_TAB_FROM_CACHE_PARAM]: parseAsBoolean.withDefault(false),
},
{
history: 'replace',
@@ -220,8 +244,7 @@ export function useSyncTableEditorStateFromLocalStorageWithUrl({
const urlParams = useMemo(() => {
const sort = searchParams.getAll('sort')
const filter = searchParams.getAll('filter')
- const loadFromCache = !!searchParams.get(LOAD_TAB_FROM_CACHE_PARAM)
- return { sort, filter, loadFromCache }
+ return { sort, filter }
}, [searchParams])
useEffect(() => {
@@ -232,25 +255,12 @@ export function useSyncTableEditorStateFromLocalStorageWithUrl({
// `urlParams` from `useQueryStates` can be stale so always get the latest from the URL
const latestUrlParams = getLatestParams()
- if (latestUrlParams.loadFromCache) {
- const savedState = loadTableEditorStateFromLocalStorage(projectRef, table.name, table.schema)
- updateUrlParams(
- {
- sort: savedState?.sorts ?? [],
- filter: savedState?.filters ?? [],
- loadFromCache: false,
- },
- { clearOnDefault: true }
- )
- } else {
- saveTableEditorStateToLocalStorage({
- projectRef,
- tableName: table.name,
- schema: table.schema,
- sorts: latestUrlParams.sort,
- filters: latestUrlParams.filter,
- })
- }
+ saveTableEditorStateToLocalStorage({
+ projectRef,
+ tableId: table.id,
+ sorts: latestUrlParams.sort,
+ filters: latestUrlParams.filter,
+ })
}, [urlParams, table, projectRef])
}
diff --git a/apps/studio/components/interfaces/Database/Schemas/SchemaTableNode.tsx b/apps/studio/components/interfaces/Database/Schemas/SchemaTableNode.tsx
index cb80338d86e..effd0546cdc 100644
--- a/apps/studio/components/interfaces/Database/Schemas/SchemaTableNode.tsx
+++ b/apps/studio/components/interfaces/Database/Schemas/SchemaTableNode.tsx
@@ -1,4 +1,4 @@
-import { LOAD_TAB_FROM_CACHE_PARAM } from 'components/grid/SupabaseGrid.utils'
+import { buildTableEditorUrl } from 'components/grid/SupabaseGrid.utils'
import { DiamondIcon, ExternalLink, Fingerprint, Hash, Key, Table2 } from 'lucide-react'
import Link from 'next/link'
import { Handle, NodeProps } from 'reactflow'
@@ -10,9 +10,10 @@ export const TABLE_NODE_WIDTH = 320
export const TABLE_NODE_ROW_HEIGHT = 40
export type TableNodeData = {
- id?: number
+ id: number
+ schema: string
name: string
- ref: string
+ ref?: string
isForeign: boolean
columns: {
id: string
@@ -66,10 +67,14 @@ export const TableNode = ({
<Table2 strokeWidth={1} size={12} className="text-light" />
{data.name}
</div>
- {data.id && !placeholder && (
+ {!placeholder && (
<Button asChild type="text" className="px-0 w-[16px] h-[16px] rounded">
<Link
- href={`/project/${data.ref}/editor/${data.id}?${LOAD_TAB_FROM_CACHE_PARAM}=true`}
+ href={buildTableEditorUrl({
+ projectRef: data.ref,
+ tableId: data.id,
+ schema: data.schema,
+ })}
>
<ExternalLink size={10} className="text-foreground-light" />
</Link>
diff --git a/apps/studio/components/interfaces/Database/Schemas/Schemas.utils.ts b/apps/studio/components/interfaces/Database/Schemas/Schemas.utils.ts
index 2a3aaaa2828..4251a30e284 100644
--- a/apps/studio/components/interfaces/Database/Schemas/Schemas.utils.ts
+++ b/apps/studio/components/interfaces/Database/Schemas/Schemas.utils.ts
@@ -4,9 +4,9 @@ import { uniqBy } from 'lodash'
import { Edge, Node, Position } from 'reactflow'
import 'reactflow/dist/style.css'
+import { LOCAL_STORAGE_KEYS } from 'common'
import { tryParseJson } from 'lib/helpers'
import { TABLE_NODE_ROW_HEIGHT, TABLE_NODE_WIDTH, TableNodeData } from './SchemaTableNode'
-import { LOCAL_STORAGE_KEYS } from 'common'
const NODE_SEP = 25
const RANK_SEP = 50
@@ -37,16 +37,19 @@ export async function getGraphDataFromTables(
}
})
+ const data: TableNodeData = {
+ ref,
+ id: table.id,
+ name: table.name,
+ schema: table.schema,
+ isForeign: false,
+ columns,
+ }
+
return {
+ data,
id: `${table.id}`,
type: 'table',
- data: {
- ref,
- id: table.id,
- name: table.name,
- isForeign: false,
- columns,
- } as TableNodeData,
position: { x: 0, y: 0 },
}
})
@@ -66,15 +69,19 @@ export async function getGraphDataFromTables(
// Create additional [this->foreign] node that we can point to on the graph.
if (rel.target_table_schema !== currentSchema) {
+ const data: TableNodeData = {
+ id: rel.id,
+ ref: ref!,
+ schema: rel.target_table_schema,
+ name: `${rel.target_table_schema}.${rel.target_table_name}.${rel.target_column_name}`,
+ isForeign: true,
+ columns: [],
+ }
+
nodes.push({
+ data,
id: rel.constraint_name,
type: 'table',
- data: {
- ref,
- name: `${rel.target_table_schema}.${rel.target_table_name}.${rel.target_column_name}`,
- isForeign: true,
- columns: [],
- } as TableNodeData,
position: { x: 0, y: 0 },
})
diff --git a/apps/studio/components/interfaces/Database/Tables/TableList.tsx b/apps/studio/components/interfaces/Database/Tables/TableList.tsx
index 330a50fbdff..fb764651592 100644
--- a/apps/studio/components/interfaces/Database/Tables/TableList.tsx
+++ b/apps/studio/components/interfaces/Database/Tables/TableList.tsx
@@ -19,7 +19,7 @@ import { useRouter } from 'next/router'
import { useState } from 'react'
import { useParams } from 'common'
-import { LOAD_TAB_FROM_CACHE_PARAM } from 'components/grid/SupabaseGrid.utils'
+import { buildTableEditorUrl } from 'components/grid/SupabaseGrid.utils'
import AlertError from 'components/ui/AlertError'
import { ButtonTooltip } from 'components/ui/ButtonTooltip'
import { DropdownMenuItemTooltip } from 'components/ui/DropdownMenuItemTooltip'
@@ -470,7 +470,11 @@ export const TableList = ({
className="flex items-center space-x-2"
onClick={() =>
router.push(
- `/project/${project?.ref}/editor/${x.id}?${LOAD_TAB_FROM_CACHE_PARAM}=true`
+ buildTableEditorUrl({
+ projectRef: project?.ref,
+ tableId: x.id,
+ schema: x.schema,
+ })
)
}
onMouseEnter={() =>
diff --git a/apps/studio/components/interfaces/Database/Tables/Tables.utils.ts b/apps/studio/components/interfaces/Database/Tables/Tables.utils.ts
index d9acbb4e0f6..1d5d69e843b 100644
--- a/apps/studio/components/interfaces/Database/Tables/Tables.utils.ts
+++ b/apps/studio/components/interfaces/Database/Tables/Tables.utils.ts
@@ -2,7 +2,7 @@ import { PostgresMaterializedView, PostgresTable, PostgresView } from '@supabase
import { PostgresForeignTable } from '@supabase/postgres-meta/dist/lib/types'
import { ENTITY_TYPE } from 'data/entity-types/entity-type-constants'
-// [Joshen] We just need name, description, rows, size, and the number of columns
+// [Joshen] We just need name, schema, description, rows, size, and the number of columns
// Just missing partitioned tables as missing pg-meta support
export const formatAllEntities = ({
tables = [],
@@ -30,6 +30,7 @@ export const formatAllEntities = ({
id: x.id,
name: x.name,
comment: x.comment,
+ schema: x.schema,
rows: undefined,
size: undefined,
columns: x.columns ?? [],
@@ -42,6 +43,7 @@ export const formatAllEntities = ({
id: x.id,
name: x.name,
comment: x.comment,
+ schema: x.schema,
rows: undefined,
size: undefined,
columns: x.columns ?? [],
@@ -54,6 +56,7 @@ export const formatAllEntities = ({
id: x.id,
name: x.name,
comment: x.comment,
+ schema: x.schema,
rows: undefined,
size: undefined,
columns: x.columns ?? [],
diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/ForeignRowSelector/ForeignRowSelector.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/ForeignRowSelector/ForeignRowSelector.tsx
index 02ac21c5f5f..e2f2387a52c 100644
--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/ForeignRowSelector/ForeignRowSelector.tsx
+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/ForeignRowSelector/ForeignRowSelector.tsx
@@ -131,12 +131,7 @@ export const ForeignRowSelector = ({
if (!project?.ref || !table?.name || !table?.schema) return
try {
- const persistenceTableName = table.name + FOREIGN_ROW_SELECTOR_TABLE_NAME_SUFFIX
- const savedState = loadTableEditorStateFromLocalStorage(
- project.ref,
- persistenceTableName,
- table.schema
- )
+ const savedState = loadTableEditorStateFromLocalStorage(project.ref, table.id)
const urlSorts = savedState?.sorts ?? []
const parsedSorts = formatSortURLParams(table.name, urlSorts)
if (parsedSorts.length > 0) {
@@ -147,24 +142,22 @@ export const ForeignRowSelector = ({
} finally {
setShouldSaveSorts(true)
}
- }, [project?.ref, table?.schema, table?.name])
+ }, [project?.ref, table?.schema, table?.name, table?.id])
// Persist sorts to local storage
useEffect(() => {
- if (!project?.ref || !table?.name || !table?.schema || !shouldSaveSorts) return
+ if (!project?.ref || !table?.id || !shouldSaveSorts) return
try {
const urlSorts = sortsToUrlParams(sorts)
- const persistenceTableName = table.name + FOREIGN_ROW_SELECTOR_TABLE_NAME_SUFFIX
saveTableEditorStateToLocalStorage({
projectRef: project.ref,
- tableName: persistenceTableName,
- schema: table.schema,
+ tableId: table.id,
sorts: urlSorts,
})
} catch (e) {
console.error(e)
}
- }, [shouldSaveSorts, sorts, project?.ref, table?.schema, table?.name])
+ }, [shouldSaveSorts, sorts, project?.ref, table?.id])
return (
<SidePanel
diff --git a/apps/studio/components/layouts/TableEditorLayout/EntityListItem.tsx b/apps/studio/components/layouts/TableEditorLayout/EntityListItem.tsx
index 90676a4c35d..a4237116cf2 100644
--- a/apps/studio/components/layouts/TableEditorLayout/EntityListItem.tsx
+++ b/apps/studio/components/layouts/TableEditorLayout/EntityListItem.tsx
@@ -5,7 +5,7 @@ import { toast } from 'sonner'
import { useParams } from 'common'
import { useTableFilter } from 'components/grid/hooks/useTableFilter'
-import { LOAD_TAB_FROM_CACHE_PARAM } from 'components/grid/SupabaseGrid.utils'
+import { buildTableEditorUrl } from 'components/grid/SupabaseGrid.utils'
import { getEntityLintDetails } from 'components/interfaces/TableGridEditor/TableEntity.utils'
import { EntityTypeIcon } from 'components/ui/EntityTypeIcon'
import { InlineLink } from 'components/ui/InlineLink'
@@ -167,7 +167,7 @@ const EntityListItem = ({
title={entity.name}
style={style}
id={String(entity.id)}
- href={`/project/${projectRef}/editor/${entity.id}?schema=${entity.schema}&${LOAD_TAB_FROM_CACHE_PARAM}=true`}
+ href={buildTableEditorUrl({ projectRef, tableId: entity.id, schema: entity.schema })}
role="button"
aria-label={`View ${entity.name}`}
className={cn(
diff --git a/apps/studio/components/layouts/Tabs/RecentItems.tsx b/apps/studio/components/layouts/Tabs/RecentItems.tsx
index 315d4196659..90fb50e4852 100644
--- a/apps/studio/components/layouts/Tabs/RecentItems.tsx
+++ b/apps/studio/components/layouts/Tabs/RecentItems.tsx
@@ -3,11 +3,11 @@ import { AnimatePresence, motion } from 'framer-motion'
import Link from 'next/link'
import { useParams } from 'common'
+import { buildTableEditorUrl } from 'components/grid/SupabaseGrid.utils'
import { EntityTypeIcon } from 'components/ui/EntityTypeIcon'
import { ENTITY_TYPE } from 'data/entity-types/entity-type-constants'
import { editorEntityTypes, useTabsStateSnapshot } from 'state/tabs'
import { useEditorType } from '../editors/EditorsLayout.hooks'
-import { LOAD_TAB_FROM_CACHE_PARAM } from 'components/grid/SupabaseGrid.utils'
export function RecentItems() {
const { ref } = useParams()
@@ -53,17 +53,21 @@ export function RecentItems() {
transition={{ delay: index * 0.012, duration: 0.15 }}
>
<Link
- href={`/project/${ref}/${
+ href={
item.type === 'sql'
- ? `sql/${item.metadata?.sqlId}`
+ ? `/project/${ref}/sql/${item.metadata?.sqlId}`
: item.type === 'r' ||
item.type === 'v' ||
item.type === 'm' ||
item.type === 'f' ||
item.type === 'p'
- ? `editor/${item.metadata?.tableId}?schema=${item.metadata?.schema}&${LOAD_TAB_FROM_CACHE_PARAM}=true`
- : `explorer/${item.type}/${item.metadata?.schema}/${item.metadata?.name}`
- }`}
+ ? buildTableEditorUrl({
+ projectRef: ref,
+ tableId: item.metadata?.tableId!,
+ schema: item.metadata?.schema,
+ })
+ : `/project/${ref}/explorer/${item.type}/${item.metadata?.schema}/${item.metadata?.name}`
+ }
className="flex items-center gap-4 rounded-lg bg-surface-100 py-2 transition-colors hover:bg-surface-200"
>
<div className="flex h-6 w-6 items-center justify-center rounded bg-surface-100 border">
diff --git a/apps/studio/data/prefetchers/project.$ref.editor.$id.tsx b/apps/studio/data/prefetchers/project.$ref.editor.$id.tsx
index 3468fb8a62a..36e8cb25162 100644
--- a/apps/studio/data/prefetchers/project.$ref.editor.$id.tsx
+++ b/apps/studio/data/prefetchers/project.$ref.editor.$id.tsx
@@ -45,7 +45,7 @@ export function prefetchEditorTablePage({
const supaTable = parseSupaTable(entity)
const { sorts: localSorts = [], filters: localFilters = [] } =
- loadTableEditorStateFromLocalStorage(projectRef, entity.name, entity.schema) ?? {}
+ loadTableEditorStateFromLocalStorage(projectRef, entity.id) ?? {}
prefetchTableRows(queryClient, {
projectRef,
diff --git a/apps/studio/pages/project/[ref]/editor/index.tsx b/apps/studio/pages/project/[ref]/editor/index.tsx
index 325696c0858..d3484ceae44 100644
--- a/apps/studio/pages/project/[ref]/editor/index.tsx
+++ b/apps/studio/pages/project/[ref]/editor/index.tsx
@@ -2,7 +2,7 @@ import { useRouter } from 'next/router'
import { useEffect } from 'react'
import { useParams } from 'common'
-import { LOAD_TAB_FROM_CACHE_PARAM } from 'components/grid/SupabaseGrid.utils'
+import { buildTableEditorUrl } from 'components/grid/SupabaseGrid.utils'
import { SidePanelEditor } from 'components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor'
import { DefaultLayout } from 'components/layouts/DefaultLayout'
import { EditorBaseLayout } from 'components/layouts/editors/EditorBaseLayout'
@@ -28,26 +28,35 @@ const TableEditorPage: NextPageWithLayout = () => {
}
useEffect(() => {
- if (isHistoryLoaded) {
- const lastOpenedTable = history.editor
- const lastTabId = tabStore.openTabs.find((id) =>
- editorEntityTypes.table.includes(tabStore.tabsMap[id]?.type)
+ if (isHistoryLoaded && projectRef && router) {
+ const lastOpenedTableId = Number(history.editor)
+ const lastTabId = Number(
+ tabStore.openTabs.find((id) => editorEntityTypes.table.includes(tabStore.tabsMap[id]?.type))
)
// Handle redirect to last opened table tab, or last table tab
- if (lastOpenedTable !== undefined) {
+ if (Number.isInteger(lastOpenedTableId)) {
+ const lastOpenedTableData = tabStore.tabsMap[lastOpenedTableId]
router.push(
- `/project/${projectRef}/editor/${history.editor}?${LOAD_TAB_FROM_CACHE_PARAM}=true`
+ buildTableEditorUrl({
+ projectRef,
+ tableId: lastOpenedTableId,
+ schema: lastOpenedTableData?.metadata?.schema,
+ })
+ )
+ } else if (Number.isInteger(lastTabId)) {
+ const lastOpenedTableData = tabStore.tabsMap[lastTabId]
+ router.push(
+ buildTableEditorUrl({
+ projectRef,
+ tableId: lastTabId,
+ schema: lastOpenedTableData?.metadata?.schema,
+ })
)
- } else if (lastTabId) {
- const lastTab = tabStore.tabsMap[lastTabId]
- if (lastTab)
- router.push(
- `/project/${projectRef}/editor/${lastTab.metadata?.tableId}?${LOAD_TAB_FROM_CACHE_PARAM}=true`
- )
}
}
- }, [isHistoryLoaded])
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [isHistoryLoaded, projectRef, router])
return (
<>
diff --git a/apps/studio/state/table-editor-table.tsx b/apps/studio/state/table-editor-table.tsx
index 160544614e4..384681fcd2e 100644
--- a/apps/studio/state/table-editor-table.tsx
+++ b/apps/studio/state/table-editor-table.tsx
@@ -34,7 +34,7 @@ export const createTableEditorTableState = ({
}) => {
const table = parseSupaTable(originalTable)
- const savedState = loadTableEditorStateFromLocalStorage(projectRef, table.name, table.schema)
+ const savedState = loadTableEditorStateFromLocalStorage(projectRef, table.id)
const gridColumns = getInitialGridColumns(
getGridColumns(table, {
tableId: table.id,
@@ -205,8 +205,7 @@ export const TableEditorTableStateContextProvider = ({
saveTableEditorStateToLocalStorageDebounced({
gridColumns: state.gridColumns,
projectRef,
- tableName: state.table.name,
- schema: state.table.schema,
+ tableId: state.table.id,
})
})
}
diff --git a/apps/studio/state/tabs.tsx b/apps/studio/state/tabs.tsx
index 3064047b4d7..6a136cfbe69 100644
--- a/apps/studio/state/tabs.tsx
+++ b/apps/studio/state/tabs.tsx
@@ -1,9 +1,9 @@
-import { LOAD_TAB_FROM_CACHE_PARAM } from 'components/grid/SupabaseGrid.utils'
+import { buildTableEditorUrl } from 'components/grid/SupabaseGrid.utils'
import { ENTITY_TYPE } from 'data/entity-types/entity-type-constants'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { partition } from 'lodash'
import { NextRouter } from 'next/router'
-import { createContext, PropsWithChildren, ReactNode, useContext, useEffect, useState } from 'react'
+import { createContext, PropsWithChildren, useContext, useEffect, useState } from 'react'
import { proxy, subscribe, useSnapshot } from 'valtio'
export const editorEntityTypes = {
@@ -30,7 +30,6 @@ export interface Tab {
id: string
type: TabType
label?: string
- icon?: ReactNode
metadata?: {
schema?: string
name?: string
@@ -76,7 +75,7 @@ function getSavedRecentItems(ref: string): RecentItem[] {
const DEFAULT_TABS_STATE = {
activeTab: null as string | null,
openTabs: [] as string[],
- tabsMap: {} as { [key: string]: Tab },
+ tabsMap: {} as Record<string, Tab>,
previewTabId: undefined as string | undefined,
recentItems: [],
}
@@ -290,7 +289,11 @@ function createTabsState(projectRef: string) {
case 'f':
case 'p':
router.push(
- `/project/${router.query.ref}/editor/${tab.metadata?.tableId}?schema=${tab.metadata?.schema}&${LOAD_TAB_FROM_CACHE_PARAM}=true`
+ buildTableEditorUrl({
+ projectRef: router.query.ref as string,
+ tableId: tab.metadata?.tableId!,
+ schema: tab.metadata?.schema,
+ })
)
break
}