Skip to content

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

adds default filter to view referenced row

Alaister Younge4442c2fa91c
diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/ForeignRowSelector/ForeignRowSelector.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/ForeignRowSelector/ForeignRowSelector.tsx
index 7c55fa99acd..a7f2e98fdae 100644
--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/ForeignRowSelector/ForeignRowSelector.tsx
+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/ForeignRowSelector/ForeignRowSelector.tsx
@@ -56,7 +56,14 @@ const ForeignRowSelector = ({
encryptedColumns
)
- const [params, setParams] = useState<any>({ filter: [], sort: [] })
+ const [params, setParams] = useState<any>(() => {
+ const targetColName = referenceRow?.foreignKey?.target_column_name
+ const value = referenceRow?.value
+
+ const initialFilters = targetColName && value ? [`${targetColName}:eq:${value}`] : []
+
+ return { filter: initialFilters, sort: [] }
+ })
const sorts = formatSortURLParams(params.sort ?? [])
const filters = formatFilterURLParams(params.filter ?? [])
diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.tsx
index 11d77b70a01..bfab3d84d8d 100644
--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.tsx
+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/RowEditor/RowEditor.tsx
@@ -192,6 +192,7 @@ const RowEditor = ({
/>
<ForeignRowSelector
+ key={`foreign-row-selector-${referenceRow?.name}`}
visible={isSelectingForeignKey}
referenceRow={referenceRow}
onSelect={onSelectForeignRowValue}