Skip to content

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

Add tooltips for foreign keys in table editor side panel

Joshen Lim5248435753ba
diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnForeignKey.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnForeignKey.tsx
index b9dacdbd220..f34be04ed41 100644
--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnForeignKey.tsx
+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnForeignKey.tsx
@@ -101,7 +101,9 @@ const ColumnForeignKeyInformation: FC<{
{foreignKey?.target_table_schema}.{foreignKey?.target_table_name}.
{foreignKey?.target_column_name}
</span>
- {deletionAction !== undefined && <Badge color="gray">Delete: {deletionAction}</Badge>}
+ {deletionAction !== undefined && (
+ <Badge color="gray">On delete: {deletionAction}</Badge>
+ )}
</div>
</div>
<div className="flex items-center space-x-2">
@@ -148,7 +150,9 @@ const ColumnForeignKeyAdded: FC<{
{foreignKey?.target_table_schema}.{foreignKey?.target_table_name}.
{foreignKey?.target_column_name}
</span>
- {deletionAction !== undefined && <Badge color="gray">Delete: {deletionAction}</Badge>}
+ {deletionAction !== undefined && (
+ <Badge color="gray">On delete: {deletionAction}</Badge>
+ )}
</div>
</div>
<div className="flex items-center space-x-2">
@@ -248,11 +252,11 @@ const ColumnForeignKeyUpdated: FC<{
{originalDeletionAction !== undefined &&
originalDeletionAction !== updatedDeletionAction && (
<Badge color="gray" className="line-through">
- Delete: {originalDeletionAction}
+ On delete: {originalDeletionAction}
</Badge>
)}
{updatedDeletionAction !== undefined && (
- <Badge color="green">Delete: {updatedDeletionAction}</Badge>
+ <Badge color="green">On delete: {updatedDeletionAction}</Badge>
)}
</div>
</div>
diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/Column.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/Column.tsx
index 5970f19f8d8..ceb74988e6c 100644
--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/Column.tsx
+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/Column.tsx
@@ -1,6 +1,16 @@
import { FC } from 'react'
-import { isUndefined } from 'lodash'
-import { Checkbox, Input, IconX, IconMenu, Popover, IconLink, IconSettings, Button } from 'ui'
+import * as Tooltip from '@radix-ui/react-tooltip'
+import {
+ Checkbox,
+ Input,
+ IconX,
+ IconMenu,
+ Popover,
+ IconLink,
+ IconSettings,
+ Button,
+ IconArrowRight,
+} from 'ui'
import type { PostgresType } from '@supabase/postgres-meta'
import { ColumnField } from '../SidePanelEditor.types'
@@ -8,6 +18,8 @@ import ColumnType from '../ColumnEditor/ColumnType'
import InputWithSuggestions from '../ColumnEditor/InputWithSuggestions'
import { Suggestion } from '../ColumnEditor/ColumnEditor.types'
import { typeExpressionSuggestions } from '../ColumnEditor/ColumnEditor.constants'
+import { FOREIGN_KEY_DELETION_ACTION } from 'data/database/database-query-constants'
+import { getForeignKeyDeletionAction } from '../ColumnEditor/ColumnEditor.utils'
/**
* [Joshen] For context:
@@ -50,12 +62,12 @@ const Column: FC<Props> = ({
}) => {
const suggestions: Suggestion[] = typeExpressionSuggestions?.[column.format] ?? []
- let settingsCount = 0
-
- column.isNullable ? (settingsCount += 1) : null
- column.isIdentity ? (settingsCount += 1) : null
- column.isUnique ? (settingsCount += 1) : null
- column.isArray ? (settingsCount += 1) : null
+ const settingsCount = [
+ column.isNullable ? 1 : 0,
+ column.isIdentity ? 1 : 0,
+ column.isUnique ? 1 : 0,
+ column.isArray ? 1 : 0,
+ ].reduce((a, b) => a + b, 0)
return (
<div className="flex w-full items-center">
@@ -80,13 +92,50 @@ const Column: FC<Props> = ({
</div>
</div>
<div className="w-[5%] pl-0.5">
- <Button
- type={!isUndefined(column.foreignKey) ? 'secondary' : 'default'}
- onClick={() => onEditRelation(column)}
- className="px-1 py-2"
- >
- <IconLink size={14} strokeWidth={!isUndefined(column.foreignKey) ? 2 : 1} />
- </Button>
+ <Tooltip.Root delayDuration={0}>
+ <Tooltip.Trigger>
+ <Button
+ type={column.foreignKey !== undefined ? 'secondary' : 'default'}
+ onClick={() => onEditRelation(column)}
+ className="px-1 py-2"
+ >
+ <IconLink size={14} strokeWidth={column.foreignKey !== undefined ? 2 : 1} />
+ </Button>
+ </Tooltip.Trigger>
+ <Tooltip.Content side="bottom">
+ <Tooltip.Arrow className="radix-tooltip-arrow" />
+ <div
+ className={[
+ 'rounded bg-scale-100 py-1 px-2 leading-none shadow', // background
+ 'border border-scale-200 ', //border
+ ].join(' ')}
+ >
+ {column.foreignKey === undefined ? (
+ <span className="text-xs text-scale-1200">Edit foreign key relation</span>
+ ) : (
+ <div>
+ <p className="text-xs text-scale-1100">Foreign key relation:</p>
+ <div className="flex items-center space-x-1">
+ <p className="text-xs text-scale-1200">
+ {column.foreignKey.source_schema}.{column.foreignKey.source_table_name}.
+ {column.foreignKey.source_column_name}
+ </p>
+ <IconArrowRight size="tiny" strokeWidth={1.5} />
+ <p className="text-xs text-scale-1200">
+ {column.foreignKey.target_table_schema}.{column.foreignKey.target_table_name}.
+ {column.foreignKey.target_column_name}
+ </p>
+ </div>
+ {column.foreignKey.deletion_action !== FOREIGN_KEY_DELETION_ACTION.NO_ACTION && (
+ <p className="text-xs text-scale-1200 mt-1">
+ On delete: {getForeignKeyDeletionAction(column.foreignKey.deletion_action)}
+ </p>
+ )}
+ </div>
+ )}
+ </div>
+ </Tooltip.Content>
+ </Tooltip.Root>
</div>
<div className="w-[25%]">
<div className="w-[95%]">
@@ -96,7 +145,7 @@ const Column: FC<Props> = ({
size="small"
showLabel={false}
className="table-editor-column-type lg:gap-0 "
- disabled={!isUndefined(column.foreignKey)}
+ disabled={column.foreignKey !== undefined}
onOptionSelect={(format: string) => {
onUpdateColumn({ format, defaultValue: null })
}}
diff --git a/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/ColumnManagement.tsx b/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/ColumnManagement.tsx
index 86793b12e67..cf9b0c06f10 100644
--- a/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/ColumnManagement.tsx
+++ b/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/ColumnManagement.tsx
@@ -1,14 +1,9 @@
import Link from 'next/link'
-import React, { FC, useState } from 'react'
-import { partition, isEmpty, isUndefined } from 'lodash'
+import { FC, useState } from 'react'
+import { partition, isEmpty } from 'lodash'
import { Alert, Button, IconEdit, IconHelpCircle, IconKey, IconTrash, IconExternalLink } from 'ui'
-import type {
- PostgresTable,
- PostgresColumn,
- PostgresRelationship,
- PostgresType,
-} from '@supabase/postgres-meta'
+import type { PostgresTable, PostgresColumn, PostgresType } from '@supabase/postgres-meta'
import {
DragDropContext,
Droppable,
@@ -60,7 +55,7 @@ const ColumnManagement: FC<Props> = ({
column: PostgresColumn
deletionAction: string
}) => {
- if (!isUndefined(selectedColumnToEditRelation)) {
+ if (selectedColumnToEditRelation !== undefined) {
onUpdateColumn(selectedColumnToEditRelation, {
foreignKey:
foreignKeyConfiguration !== undefined
@@ -356,7 +351,7 @@ const ColumnManagement: FC<Props> = ({
</div>
<ForeignKeySelector
column={selectedColumnToEditRelation as ColumnField}
- visible={!isUndefined(selectedColumnToEditRelation)}
+ visible={selectedColumnToEditRelation !== undefined}
closePanel={() => setSelectedColumnToEditRelation(undefined)}
saveChanges={saveColumnForeignKey}
/>
diff --git a/studio/stores/pgmeta/MetaStore.ts b/studio/stores/pgmeta/MetaStore.ts
index eb83b2367a8..2695adfbe96 100644
--- a/studio/stores/pgmeta/MetaStore.ts
+++ b/studio/stores/pgmeta/MetaStore.ts
@@ -635,7 +635,6 @@ export default class MetaStore implements IMetaStore {
// Then add the foreign key constraints here
for (const column of columns) {
if (!isUndefined(column.foreignKey)) {
- console.log('Add foreign key', column)
const relationship = await this.addForeignKey(column.foreignKey)
if (relationship.error) throw relationship.error
}