Skip to content

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

First round of feedback address

Joshen Limaf53f26134d1
diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx
index 3917cca19bc..69ee72b3b1a 100644
--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx
+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx
@@ -80,7 +80,7 @@ const ColumnEditor: FC<Props> = ({
connectionString: project?.connectionString,
schema: selectedTable?.schema,
})
- const foreignKeyMeta = data?.result ?? []
+ const foreignKeyMeta = data || []
const keys = vault.listKeys()
const enumTypes = meta.types.list(
diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/ForeignKeySelector/ForeignKeySelector.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/ForeignKeySelector/ForeignKeySelector.tsx
index 19749994a14..7698ba73428 100644
--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/ForeignKeySelector/ForeignKeySelector.tsx
+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/ForeignKeySelector/ForeignKeySelector.tsx
@@ -276,7 +276,7 @@ const ForeignKeySelector: FC<Props> = ({ column, visible = false, closePanel, sa
<Listbox
id="deletionAction"
value={selectedForeignKey.deletionAction}
- label="Deletion action if referenced row is removed"
+ label="Delete action if referenced row is removed"
// @ts-ignore
descriptionText={generateDeletionActionDescription(
selectedForeignKey.deletionAction,
diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/ForeignKeySelector/ForeignKeySelector.utils.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/ForeignKeySelector/ForeignKeySelector.utils.tsx
index c0a97943d84..986708e4eec 100644
--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/ForeignKeySelector/ForeignKeySelector.utils.tsx
+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/ForeignKeySelector/ForeignKeySelector.utils.tsx
@@ -1,45 +1,53 @@
import { FOREIGN_KEY_DELETION_ACTION } from 'data/database/database-query-constants'
+import { getForeignKeyDeletionAction } from '../ColumnEditor/ColumnEditor.utils'
export const generateDeletionActionDescription = (deletionAction: string, reference: string) => {
+ const actionName = getForeignKeyDeletionAction(deletionAction) ?? 'No action'
+
switch (deletionAction) {
case FOREIGN_KEY_DELETION_ACTION.NO_ACTION:
return (
<>
- Deleting a record from <code className="text-xs text-scale-1100">{reference}</code> will{' '}
- <span className="text-brand-900 opacity-75">raise an error</span> if there exists
- referencing rows from this table
+ <span className="text-scale-1100">{actionName}</span>: Deleting a record from{' '}
+ <code className="text-xs text-scale-1100">{reference}</code> will{' '}
+ <span className="text-amber-900 opacity-75">raise an error</span> if there are records
+ existing in this table that reference it
</>
)
case FOREIGN_KEY_DELETION_ACTION.CASCADE:
return (
<>
- Deleting a record from <code className="text-xs text-scale-1100">{reference}</code> will{' '}
- <span className="text-brand-900 opacity-75">also delete</span> the referencing records
- from this table
+ <span className="text-scale-1100">{actionName}</span>: Deleting a record from{' '}
+ <code className="text-xs text-scale-1100">{reference}</code> will{' '}
+ <span className="text-amber-900 opacity-75">also delete</span> any records that reference
+ it in this table
</>
)
case FOREIGN_KEY_DELETION_ACTION.RESTRICT:
return (
<>
- Deleting a record from <code className="text-xs text-scale-1100">{reference}</code> will{' '}
- <span className="text-brand-900 opacity-75">prevent deletion</span> of existing
+ <span className="text-scale-1100">{actionName}</span>: Deleting a record from{' '}
+ <code className="text-xs text-scale-1100">{reference}</code> will{' '}
+ <span className="text-amber-900 opacity-75">prevent deletion</span> of existing
referencing rows from this table
</>
)
case FOREIGN_KEY_DELETION_ACTION.SET_DEFAULT:
return (
<>
- Deleting a record from <code className="text-xs text-scale-1100">{reference}</code> will{' '}
- set the values of existing referencing rows to their{' '}
- <span className="text-brand-900 opacity-75">default value</span> from this table
+ <span className="text-scale-1100">{actionName}</span>: Deleting a record from{' '}
+ <code className="text-xs text-scale-1100">{reference}</code> will set the value of any
+ existing records in this table referencing it back to their{' '}
+ <span className="text-amber-900 opacity-75">default value</span>
</>
)
case FOREIGN_KEY_DELETION_ACTION.SET_NULL:
return (
<>
- Deleting a record from <code className="text-xs text-scale-1100">{reference}</code> will{' '}
- set the values of existing referencing rows{' '}
- <span className="text-brand-900 opacity-75">to NULL</span> from this table
+ <span className="text-scale-1100">{actionName}</span>: Deleting a record from{' '}
+ <code className="text-xs text-scale-1100">{reference}</code> will set the value of any
+ existing records in this table referencing it{' '}
+ <span className="text-amber-900 opacity-75">to NULL</span>
</>
)
}
diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsx
index 175125e3588..ff450ac347d 100644
--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsx
+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsx
@@ -80,7 +80,7 @@ const TableEditor: FC<Props> = ({
connectionString: project?.connectionString,
schema: table?.schema,
})
- const foreignKeyMeta = data?.result ?? []
+ const foreignKeyMeta = data || []
useEffect(() => {
if (visible) {
diff --git a/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx b/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx
index a1cdb8cba8a..1bd8d33ac6b 100644
--- a/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx
+++ b/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx
@@ -213,7 +213,7 @@ const TableGridEditor: FC<Props> = ({
connectionString: project?.connectionString,
schema: selectedTable?.schema,
})
- const foreignKeyMeta = data?.result ?? []
+ const foreignKeyMeta = data || []
useEffect(() => {
if (selectedTable !== undefined && selectedTable.id !== undefined && isVaultEnabled) {
diff --git a/studio/data/database/foreign-key-constraints-query.ts b/studio/data/database/foreign-key-constraints-query.ts
index f11d2f44508..22c81246a76 100644
--- a/studio/data/database/foreign-key-constraints-query.ts
+++ b/studio/data/database/foreign-key-constraints-query.ts
@@ -81,29 +81,26 @@ export const useForeignKeyConstraintsQuery = <
{ projectRef, connectionString, schema }: ForeignKeyConstraintsVariables,
options: UseQueryOptions<ExecuteSqlData, ForeignKeyConstraintsError, TData> = {}
) => {
- const response = useExecuteSqlQuery(
+ return useExecuteSqlQuery(
{
projectRef,
connectionString,
sql: getForeignKeyConstraintsQuery({ schema }),
queryKey: ['foreignKeyConstraints'],
},
- options
- )
-
- // [Joshen] Convert target/source_columns into a string array
- // This should be safe as the returned data is rather scoped
- const formattedResults = ((response?.data as any)?.result ?? []).map(
- (foreignKey: ForeignKeyConstraint) => {
- return {
- ...foreignKey,
- source_columns: foreignKey.source_columns.replace('{', '').replace('}', '').split(','),
- target_columns: foreignKey.target_columns.replace('{', '').replace('}', '').split(','),
- }
+ {
+ select(data) {
+ return ((data as any)?.result ?? []).map((foreignKey: ForeignKeyConstraint) => {
+ return {
+ ...foreignKey,
+ source_columns: foreignKey.source_columns.replace('{', '').replace('}', '').split(','),
+ target_columns: foreignKey.target_columns.replace('{', '').replace('}', '').split(','),
+ }
+ })
+ },
+ ...options,
}
)
-
- return { ...response, data: { ...response.data, result: formattedResults } }
}
export const useForeignKeyConstraintsPrefetch = ({