Skip to content

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

Support opening table rows for foreign tables in side panel (read only) (#38699)

Joshen Lim466760099d4c
diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.utils.ts b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.utils.ts
index 1dbff8c42ed..03236f0f374 100644
--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.utils.ts
+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.utils.ts
@@ -46,7 +46,7 @@ export const generateRowFields = (
table: PostgresTable,
foreignKeys: ForeignKey[]
): RowField[] => {
- const { primary_keys } = table
+ const { primary_keys = [] } = table
const primaryKeyColumns = primary_keys.map((key) => key.name)
return (table.columns ?? []).map((column) => {
diff --git a/apps/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx b/apps/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx
index 5a31e04f07c..2cceac5f76d 100644
--- a/apps/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx
+++ b/apps/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx
@@ -8,9 +8,11 @@ import { SupabaseGrid } from 'components/grid/SupabaseGrid'
import { useLoadTableEditorStateFromLocalStorageIntoUrl } from 'components/grid/SupabaseGrid.utils'
import {
Entity,
+ isForeignTable,
isMaterializedView,
isTableLike,
isView,
+ TableLike,
} from 'data/table-editor/table-editor-types'
import { useAsyncCheckProjectPermissions } from 'hooks/misc/useCheckPermissions'
import { useDashboardHistory } from 'hooks/misc/useDashboardHistory'
@@ -147,6 +149,7 @@ export const TableGridEditor = ({
const isViewSelected = isView(selectedTable) || isMaterializedView(selectedTable)
const isTableSelected = isTableLike(selectedTable)
+ const isForeignTableSelected = isForeignTable(selectedTable)
const canEditViaTableEditor = isTableSelected && !isSchemaLocked
const editable = !isReadOnly && canEditViaTableEditor
@@ -188,11 +191,13 @@ export const TableGridEditor = ({
<SidePanelEditor
editable={editable}
- selectedTable={isTableLike(selectedTable) ? selectedTable : undefined}
+ selectedTable={
+ isTableSelected || isForeignTableSelected ? (selectedTable as TableLike) : undefined
+ }
onTableCreated={onTableCreated}
/>
<DeleteConfirmationDialogs
- selectedTable={isTableLike(selectedTable) ? selectedTable : undefined}
+ selectedTable={isTableSelected ? selectedTable : undefined}
onTableDeleted={onTableDeleted}
/>
</TableEditorTableStateContextProvider>