Skip to content

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

Reinstate link button for foreign keys in table editor side panel (#23186)

Joshen Lim44b3853cbf25
diff --git a/apps/studio/components/interfaces/Realtime/Inspector/useRealtimeMessages.ts b/apps/studio/components/interfaces/Realtime/Inspector/useRealtimeMessages.ts
index cb4c57e7e18..46ceb7e3ad1 100644
--- a/apps/studio/components/interfaces/Realtime/Inspector/useRealtimeMessages.ts
+++ b/apps/studio/components/interfaces/Realtime/Inspector/useRealtimeMessages.ts
@@ -161,7 +161,7 @@ export const useRealtimeMessages = (
}
// Finally, subscribe to the Channel we just setup
- newChannel.subscribe(async (status, error) => {
+ newChannel.subscribe(async (status) => {
if (status === 'SUBSCRIBED') {
// Let LiveView know we connected so we can update the button text
// pushMessageTo('#conn_info', 'broadcast_subscribed', { host: host })
@@ -174,8 +174,6 @@ export const useRealtimeMessages = (
payload: { name: name, t: performance.now() },
})
}
- } else if (status === 'CLOSED') {
- // console.log(`Realtime Channel status: ${status}`)
} else if (status === 'CHANNEL_ERROR') {
toast.error(
'Failed to connect to the channel: This may be due to restrictive RLS policies. Check your role and try again.'
@@ -184,9 +182,6 @@ export const useRealtimeMessages = (
newChannel.unsubscribe()
setChannel(undefined)
setRealtimeConfig({ ...config, enabled: false })
- } else {
- // console.error(`Realtime Channel error status: ${status}`)
- // console.error(`Realtime Channel error: ${error}`)
}
})
diff --git a/apps/studio/components/interfaces/SQLEditor/UtilityPanel/ChartConfig.tsx b/apps/studio/components/interfaces/SQLEditor/UtilityPanel/ChartConfig.tsx
index b996596a834..b970ac05519 100644
--- a/apps/studio/components/interfaces/SQLEditor/UtilityPanel/ChartConfig.tsx
+++ b/apps/studio/components/interfaces/SQLEditor/UtilityPanel/ChartConfig.tsx
@@ -164,10 +164,7 @@ export function ChartConfig({ results = { rows: [] }, config, onConfigChange }:
id="cumulative"
name="cumulative"
checked={config.cumulative}
- onClick={(e) => {
- console.log(e)
- onConfigChange({ ...config, cumulative: !config.cumulative })
- }}
+ onClick={() => onConfigChange({ ...config, cumulative: !config.cumulative })}
/>
<Label_Shadcn_ className="text-foreground-light p-1.5" htmlFor="cumulative">
Cumulative
diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx
index 000d0c387e9..5f3c5eca82b 100644
--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx
+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx
@@ -9,8 +9,6 @@ import {
Alert_Shadcn_,
Button,
Checkbox,
- IconAlertCircle,
- IconAlertTriangle,
IconExternalLink,
IconPlus,
Input,
@@ -32,6 +30,7 @@ import {
import { useEnumeratedTypesQuery } from 'data/enumerated-types/enumerated-types-query'
import { EXCLUDED_SCHEMAS_WITHOUT_EXTENSIONS } from 'lib/constants/schemas'
import type { Dictionary } from 'types'
+import { WarningIcon } from 'ui-patterns/Icons/StatusIcons'
import ActionBar from '../ActionBar'
import type { ForeignKey } from '../ForeignKeySelector/ForeignKeySelector.types'
import { formatForeignKeys } from '../ForeignKeySelector/ForeignKeySelector.utils'
@@ -52,7 +51,6 @@ import {
import ColumnForeignKey from './ColumnForeignKey'
import ColumnType from './ColumnType'
import HeaderTitle from './HeaderTitle'
-import toast from 'react-hot-toast'
export interface ColumnEditorProps {
column?: PostgresColumn
@@ -361,7 +359,7 @@ const ColumnEditor = ({
>
<FormSectionContent loading={false} className="lg:!col-span-8">
<Alert_Shadcn_>
- <IconAlertCircle />
+ <WarningIcon />
<AlertTitle_Shadcn_>
Column encryption has been removed from the GUI
</AlertTitle_Shadcn_>
@@ -400,7 +398,7 @@ const ColumnEditor = ({
>
<FormSectionContent loading={false} className="lg:!col-span-8">
<Alert_Shadcn_ variant="warning">
- <IconAlertTriangle strokeWidth={2} />
+ <WarningIcon strokeWidth={2} />
<AlertTitle_Shadcn_>This table uses column-privileges</AlertTitle_Shadcn_>
<AlertDescription_Shadcn_>
<p>
diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx
index 97cb7db0674..98509e4df5e 100644
--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx
+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.tsx
@@ -351,7 +351,6 @@ const SidePanelEditor = ({
})
}
} catch (error: any) {
- console.log({ error })
toast.error(`Failed to update realtime for ${table.name}: ${error.message}`)
}
}
diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.utils.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.utils.tsx
index 52550161d1e..30e94f607fa 100644
--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.utils.tsx
+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/SidePanelEditor.utils.tsx
@@ -166,8 +166,7 @@ export const getAddForeignKeySQL = ({
const onUpdateSql = getOnUpdateSql(updateAction)
return `
ALTER TABLE "${table.schema}"."${table.name}"
- ADD CONSTRAINT "${table.schema}_${table.name}_${relation.columns.map((x) => x.source).join('_')}_fkey"
- FOREIGN KEY (${relation.columns.map((column) => `"${column.source}"`).join(',')})
+ ADD FOREIGN KEY (${relation.columns.map((column) => `"${column.source}"`).join(',')})
REFERENCES "${relation.schema}"."${relation.table}" (${relation.columns.map((column) => `"${column.target}"`).join(',')})
${onUpdateSql}
${onDeleteSql}
diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/Column.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/Column.tsx
index 024687586c3..207130d3fef 100644
--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/Column.tsx
+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/Column.tsx
@@ -1,13 +1,33 @@
-import { noop } from 'lodash'
-import { Checkbox, IconMenu, IconSettings, IconX, Input, Popover } from 'ui'
+import { Link, Menu, Plus, Settings, X } from 'lucide-react'
+import {
+ Badge,
+ Button,
+ Checkbox,
+ CommandGroup_Shadcn_,
+ CommandItem_Shadcn_,
+ CommandList_Shadcn_,
+ CommandSeparator_Shadcn_,
+ Command_Shadcn_,
+ Input,
+ Popover,
+ PopoverContent_Shadcn_,
+ PopoverTrigger_Shadcn_,
+ Popover_Shadcn_,
+ cn,
+} from 'ui'
+import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
+import { useForeignKeyConstraintsQuery } from 'data/database/foreign-key-constraints-query'
import type { EnumeratedType } from 'data/enumerated-types/enumerated-types-query'
import { EMPTY_ARR, EMPTY_OBJ } from 'lib/void'
+import { useState } from 'react'
import { typeExpressionSuggestions } from '../ColumnEditor/ColumnEditor.constants'
import type { Suggestion } from '../ColumnEditor/ColumnEditor.types'
import ColumnType from '../ColumnEditor/ColumnType'
import InputWithSuggestions from '../ColumnEditor/InputWithSuggestions'
+import { ForeignKey } from '../ForeignKeySelector/ForeignKeySelector.types'
import type { ColumnField } from '../SidePanelEditor.types'
+import { checkIfRelationChanged } from './ForeignKeysManagement/ForeignKeysManagement.utils'
/**
* [Joshen] For context:
@@ -29,6 +49,7 @@ import type { ColumnField } from '../SidePanelEditor.types'
interface ColumnProps {
column: ColumnField
+ relations: ForeignKey[]
enumTypes: EnumeratedType[]
isNewRecord: boolean
hasForeignKeys: boolean
@@ -36,18 +57,23 @@ interface ColumnProps {
dragHandleProps?: any
onUpdateColumn: (changes: Partial<ColumnField>) => void
onRemoveColumn: () => void
+ onEditForeignKey: (relation?: ForeignKey) => void
}
const Column = ({
column = EMPTY_OBJ as ColumnField,
+ relations = EMPTY_ARR as ForeignKey[],
enumTypes = EMPTY_ARR as EnumeratedType[],
isNewRecord = false,
hasForeignKeys = false,
hasImportContent = false,
dragHandleProps = EMPTY_OBJ,
- onUpdateColumn = noop,
- onRemoveColumn = noop,
+ onUpdateColumn,
+ onRemoveColumn,
+ onEditForeignKey,
}: ColumnProps) => {
+ const { project } = useProjectContext()
+ const [open, setOpen] = useState(false)
const suggestions: Suggestion[] = typeExpressionSuggestions?.[column.format] ?? []
const settingsCount = [
@@ -57,26 +83,142 @@ const Column = ({
column.isArray ? 1 : 0,
].reduce((a, b) => a + b, 0)
+ const { data } = useForeignKeyConstraintsQuery({
+ projectRef: project?.ref,
+ connectionString: project?.connectionString,
+ schema: column.schema,
+ })
+
+ const getRelationStatus = (fk: ForeignKey) => {
+ const existingRelation = (data ?? []).find((x) => x.id === fk.id)
+ const stateRelation = relations.find((x) => x.id === fk.id)
+
+ if (stateRelation?.toRemove) return 'REMOVE'
+ if (existingRelation === undefined && stateRelation !== undefined) return 'ADD'
+ if (existingRelation !== undefined && stateRelation !== undefined) {
+ const hasUpdated = checkIfRelationChanged(existingRelation, stateRelation)
+ if (hasUpdated) return 'UPDATE'
+ else return undefined
+ }
+ }
+
+ const hasChangesInRelations = relations
+ .map((r) => getRelationStatus(r))
+ .some((x) => x !== undefined)
+
return (
<div className="flex w-full items-center">
<div className={`w-[5%] ${!isNewRecord ? 'hidden' : ''}`}>
<div className="cursor-drag" {...dragHandleProps}>
- <IconMenu strokeWidth={1} size={15} />
+ <Menu strokeWidth={1} size={16} />
</div>
</div>
<div className="w-[25%]">
<div className="flex w-[95%] items-center justify-between">
<Input
- value={column.name}
size="small"
+ value={column.name}
title={column.name}
disabled={hasImportContent}
placeholder="column_name"
- className={`table-editor-columns-input bg-surface-100 lg:gap-0 ${
+ className={cn(
+ '[&>div>div>div>input]:py-1.5 [&>div>div>div>input]:border-r-transparent [&>div>div>div>input]:rounded-r-none',
hasImportContent ? 'opacity-50' : ''
- } rounded-md`}
+ )}
onChange={(event: any) => onUpdateColumn({ name: event.target.value })}
/>
+ {relations.filter((r) => !r.toRemove).length === 0 ? (
+ <Button
+ type="dashed"
+ className="rounded-l-none h-[30px] py-0 px-2"
+ onClick={() => onEditForeignKey()}
+ >
+ <Link size={12} />
+ </Button>
+ ) : (
+ <Popover_Shadcn_ open={open} onOpenChange={setOpen} modal={false}>
+ <PopoverTrigger_Shadcn_ asChild>
+ <Button type="default" className="rounded-l-none h-[30px] py-0 px-2">
+ <Link size={12} />
+ </Button>
+ </PopoverTrigger_Shadcn_>
+ <PopoverContent_Shadcn_
+ className={cn('p-0', hasChangesInRelations ? 'w-96' : 'w-72')}
+ side="bottom"
+ align="end"
+ >
+ <div className="text-xs px-2 pt-2">
+ Involved in {relations.length} foreign key{relations.length > 1 ? 's' : ''}
+ </div>
+ <Command_Shadcn_>
+ <CommandList_Shadcn_>
+ <CommandGroup_Shadcn_>
+ {relations.map((relation, idx) => {
+ const key = String(relation?.id ?? `${column.id}-relation-${idx}`)
+ const status = getRelationStatus(relation)
+ if (status === 'REMOVE') return null
+
+ return (
+ <CommandItem_Shadcn_
+ key={key}
+ value={key}
+ className="cursor-pointer w-full"
+ onSelect={() => onEditForeignKey(relation)}
+ onClick={() => onEditForeignKey(relation)}
+ >
+ {status === undefined ? (
+ <div className="w-full flex items-center justify-between truncate">
+ {relation.name}
+ </div>
+ ) : (
+ <div className="flex items-center gap-x-2 truncate">
+ <Badge variant={status === 'ADD' ? 'brand' : 'warning'}>
+ {status}
+ </Badge>
+ <p className="truncate">
+ {relation.name || (
+ <>
+ To{' '}
+ {relation.columns
+ .filter((c) => c.source === column.name)
+ .map((c) => {
+ return (
+ <code key={`${c.source}-${c.target}`}>
+ {relation.schema}.{relation.table}.{c.target}
+ </code>
+ )
+ })}
+ {relation.columns.length > 1 && (
+ <>
+ and {relation.columns.length - 1} other column
+ {relation.columns.length > 2 ? 's' : ''}
+ </>
+ )}
+ </>
+ )}
+ </p>
+ </div>
+ )}
+ </CommandItem_Shadcn_>
+ )
+ })}
+ </CommandGroup_Shadcn_>
+ <CommandSeparator_Shadcn_ />
+ <CommandGroup_Shadcn_>
+ <CommandItem_Shadcn_
+ className="cursor-pointer w-full gap-x-2"
+ onSelect={() => onEditForeignKey()}
+ onClick={() => onEditForeignKey()}
+ >
+ <Plus size={14} strokeWidth={1.5} />
+ <p>Add foreign key relation</p>
+ </CommandItem_Shadcn_>
+ </CommandGroup_Shadcn_>
+ </CommandList_Shadcn_>
+ </Command_Shadcn_>
+ </PopoverContent_Shadcn_>
+ </Popover_Shadcn_>
+ )}
</div>
</div>
<div className="w-[25%]">
@@ -200,12 +342,12 @@ const Column = ({
>
<div className="group flex items-center -space-x-1">
{settingsCount > 0 && (
- <div className="rounded-full bg-foreground py-0.5 px-2 text-xs text-background">
+ <div className="rounded-full bg-foreground h-4 w-4 flex items-center justify-center text-xs text-background">
{settingsCount}
</div>
)}
<div className="text-foreground-light transition-colors group-hover:text-foreground">
- <IconSettings size={18} strokeWidth={1} />
+ <Settings size={16} strokeWidth={1} />
</div>
</div>
</Popover>
@@ -215,7 +357,7 @@ const Column = ({
{!hasImportContent && (
<div className="flex w-[5%] justify-end">
<button className="cursor-pointer" onClick={() => onRemoveColumn()}>
- <IconX strokeWidth={1} />
+ <X size={16} strokeWidth={1} />
</button>
</div>
)}
diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/ColumnManagement.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/ColumnManagement.tsx
index c0c183f9956..dedde050505 100644
--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/ColumnManagement.tsx
+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/ColumnManagement.tsx
@@ -1,5 +1,7 @@
import * as Tooltip from '@radix-ui/react-tooltip'
import { isEmpty, noop, partition } from 'lodash'
+import { HelpCircle, Key } from 'lucide-react'
+import { useState } from 'react'
import {
DragDropContext,
Draggable,
@@ -7,18 +9,29 @@ import {
Droppable,
DroppableProvided,
} from 'react-beautiful-dnd'
-import { Alert, Button, IconEdit, IconExternalLink, IconHelpCircle, IconKey, IconTrash } from 'ui'
import InformationBox from 'components/ui/InformationBox'
import type { EnumeratedType } from 'data/enumerated-types/enumerated-types-query'
+import {
+ AlertDescription_Shadcn_,
+ AlertTitle_Shadcn_,
+ Alert_Shadcn_,
+ Button,
+ IconEdit,
+ IconExternalLink,
+ IconTrash,
+} from 'ui'
+import { WarningIcon } from 'ui-patterns/Icons/StatusIcons'
import { generateColumnField } from '../ColumnEditor/ColumnEditor.utils'
+import { ForeignKeySelector } from '../ForeignKeySelector/ForeignKeySelector'
import type { ForeignKey } from '../ForeignKeySelector/ForeignKeySelector.types'
import { TEXT_TYPES } from '../SidePanelEditor.constants'
import type { ColumnField, ExtendedPostgresRelationship } from '../SidePanelEditor.types'
import Column from './Column'
-import type { ImportContent } from './TableEditor.types'
+import type { ImportContent, TableField } from './TableEditor.types'
interface ColumnManagementProps {
+ table: TableField
columns?: ColumnField[]
relations: ForeignKey[]
enumTypes: EnumeratedType[]
@@ -27,9 +40,11 @@ interface ColumnManagementProps {
onColumnsUpdated: (columns: ColumnField[]) => void
onSelectImportData: () => void
onClearImportContent: () => void
+ onUpdateFkRelations: (relations: ForeignKey[]) => void
}
const ColumnManagement = ({
+ table,
columns = [],
relations,
enumTypes = [],
@@ -38,7 +53,12 @@ const ColumnManagement = ({
onColumnsUpdated = noop,
onSelectImportData = noop,
onClearImportContent = noop,
+ onUpdateFkRelations,
}: ColumnManagementProps) => {
+ const [open, setOpen] = useState(false)
+ const [selectedColumn, setSelectedColumn] = useState<ColumnField>()
+ const [selectedFk, setSelectedFk] = useState<ForeignKey>()
+
const hasImportContent = !isEmpty(importContent)
const [primaryKeyColumns, otherColumns] = partition(
columns,
@@ -154,20 +174,22 @@ const ColumnManagement = ({
)}
{primaryKeyColumns.length === 0 && (
- <Alert title="Warning: No primary keys selected" variant="warning" withIcon>
- Tables require at least one column as a primary key in order to uniquely identify each
- row. Without a primary key, you will not be able to update or delete rows from the
- table.
- </Alert>
+ <Alert_Shadcn_ variant="warning">
+ <WarningIcon />
+ <AlertTitle_Shadcn_>Warning: No primary keys selected</AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_>
+ Tables should have at least one column as the primary key to identify each row.
+ Without a primary key, you will not be able to update or delete rows from the table.
+ </AlertDescription_Shadcn_>
+ </Alert_Shadcn_>
)}
{primaryKeyColumns.length > 1 && (
<InformationBox
block
- icon={<IconKey className="text-white" size="large" />}
+ icon={<Key size={16} />}
title="Composite primary key selected"
- description="The columns that you've selected will be grouped as a primary key, and will serve
- as the unique identifier for the rows in your table"
+ description="The columns that you've selected will be grouped as a primary key, and will serve as the unique identifier for the rows in your table"
/>
)}
@@ -181,7 +203,7 @@ const ColumnManagement = ({
<Tooltip.Root delayDuration={0}>
<Tooltip.Trigger>
<h5 className="text-xs text-foreground-lighter">
- <IconHelpCircle size={15} strokeWidth={1.5} />
+ <HelpCircle size={15} strokeWidth={1.5} />
</h5>
</Tooltip.Trigger>
<Tooltip.Portal>
@@ -211,7 +233,7 @@ const ColumnManagement = ({
<Tooltip.Root delayDuration={0}>
<Tooltip.Trigger>
<h5 className="text-xs text-foreground-lighter">
- <IconHelpCircle size={15} strokeWidth={1.5} />
+ <HelpCircle size={15} strokeWidth={1.5} />
</h5>
</Tooltip.Trigger>
<Tooltip.Portal>
@@ -262,6 +284,9 @@ const ColumnManagement = ({
>
<Column
column={column}
+ relations={relations.filter((relation) => {
+ return relation.columns.some((x) => x.source === column.name)
+ })}
enumTypes={enumTypes}
hasForeignKeys={checkIfHaveForeignKeys(column)}
isNewRecord={isNewRecord}
@@ -269,6 +294,11 @@ const ColumnManagement = ({
dragHandleProps={draggableProvided.dragHandleProps}
onUpdateColumn={(changes) => onUpdateColumn(column, changes)}
onRemoveColumn={() => onRemoveColumn(column)}
+ onEditForeignKey={(fk) => {
+ setOpen(true)
+ setSelectedColumn(column)
+ if (fk) setSelectedFk(fk)
+ }}
/>
</div>
)}
@@ -294,6 +324,9 @@ const ColumnManagement = ({
<div ref={draggableProvided.innerRef} {...draggableProvided.draggableProps}>
<Column
column={column}
+ relations={relations.filter((relation) => {
+ return relation.columns.some((x) => x.source === column.name)
+ })}
enumTypes={enumTypes}
isNewRecord={isNewRecord}
hasForeignKeys={checkIfHaveForeignKeys(column)}
@@ -301,6 +334,11 @@ const ColumnManagement = ({
dragHandleProps={draggableProvided.dragHandleProps}
onUpdateColumn={(changes) => onUpdateColumn(column, changes)}
onRemoveColumn={() => onRemoveColumn(column)}
+ onEditForeignKey={(fk) => {
+ setOpen(true)
+ setSelectedColumn(column)
+ if (fk) setSelectedFk(fk)
+ }}
/>
</div>
)}
@@ -321,6 +359,31 @@ const ColumnManagement = ({
</div>
)}
</div>
+
+ <ForeignKeySelector
+ visible={open}
+ column={selectedColumn}
+ table={{ id: table.id, name: table.name, columns: table.columns }}
+ foreignKey={selectedFk}
+ onClose={() => {
+ setOpen(false)
+ setSelectedFk(undefined)
+ setSelectedColumn(undefined)
+ }}
+ onSaveRelation={(fk) => {
+ const existingRelationIds = relations.map((x) => x.id)
+ if (fk.id !== undefined && existingRelationIds.includes(fk.id)) {
+ onUpdateFkRelations(
+ relations.map((x) => {
+ if (x.id === fk.id) return fk
+ return x
+ })
+ )
+ } else {
+ onUpdateFkRelations(relations.concat([fk]))
+ }
+ }}
+ />
</>
)
}
diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsx
index fb40e8e7a05..d45c5761e0c 100644
--- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsx
+++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableEditor.tsx
@@ -1,9 +1,8 @@
import type { PostgresTable } from '@supabase/postgres-meta'
import { isEmpty, isUndefined, noop } from 'lodash'
-import Link from 'next/link'
import { useEffect, useState } from 'react'
import toast from 'react-hot-toast'
-import { Alert, Badge, Button, Checkbox, IconBookOpen, Input, Modal, SidePanel } from 'ui'
+import { Alert, Badge, Button, Checkbox, Input, SidePanel } from 'ui'
import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
@@ -20,6 +19,7 @@ import {
import { useEnumeratedTypesQuery } from 'data/enumerated-types/enumerated-types-query'
import { useIsFeatureEnabled } from 'hooks'
import { EXCLUDED_SCHEMAS_WITHOUT_EXTENSIONS } from 'lib/constants/schemas'
+import { ExternalLink } from 'lucide-react'
import { useTableEditorStateSnapshot } from 'state/table-editor'
import { SpreadsheetImport } from '../'
import ActionBar from '../ActionBar'
@@ -306,23 +306,20 @@ const TableEditor = ({
title="Policies are required to query data"
>
<p>
- You need to write an access policy before you can query data from this table. Without
- a policy, querying this table will result in an <u>empty array</u> of results.
- </p>
- {isNewRecord && (
- <p className="mt-3">You can create policies after you create this table.</p>
- )}
- <p className="mt-4">
- <Button asChild type="default" icon={<IconBookOpen strokeWidth={1.5} />}>
- <Link
- href="https://supabase.com/docs/guides/auth/row-level-security"
- target="_blank"
- rel="noreferrer"
- >
- RLS Documentation
- </Link>
- </Button>
+ You need to create an access policy before you can query data from this table. Without
+ a policy, querying this table will return an{' '}
+ <u className="text-foreground">empty array</u> of results.{' '}
+ {isNewRecord ? 'You can create policies after saving this table.' : ''}
</p>
+ <Button asChild type="default" icon={<ExternalLink />} className="mt-4">
+ <a
+ target="_blank"
+ rel="noreferrer"
+ href="https://supabase.com/docs/guides/auth/row-level-security"
+ >
+ RLS Documentation
+ </a>
+ </Button>
</Alert>
) : (
<Alert
@@ -335,17 +332,15 @@ const TableEditor = ({
{tableFields.name ? `The table ${tableFields.name}` : 'Your table'} will be publicly
writable and readable
</p>
- <p className="mt-4">
- <Button asChild type="default" icon={<IconBookOpen strokeWidth={1.5} />}>
- <Link
- href="https://supabase.com/docs/guides/auth/row-level-security"
- target="_blank"
- rel="noreferrer"
- >
- RLS Documentation
- </Link>
- </Button>
- </p>
+ <Button asChild type="default" icon={<ExternalLink />} className="mt-4">
+ <a
+ target="_blank"
+ rel="noreferrer"
+ href="https://supabase.com/docs/guides/auth/row-level-security"
+ >
+ RLS Documentation
+ </a>
+ </Button>
</Alert>
)}
{realtimeEnabled && (
@@ -363,6 +358,7 @@ const TableEditor = ({
<SidePanel.Content className="space-y-10 py-6">
{!isDuplicating && (
<ColumnManagement
+ table={tableFields}
columns={tableFields?.columns}
relations={fkRelations}
enumTypes={enumTypes}
@@ -374,6 +370,7 @@ const TableEditor = ({
onUpdateField({ columns: DEFAULT_COLUMNS })
setImportContent(undefined)
}}
+ onUpdateFkRelations={onUpdateFkRelations}
/>
)}
{isDuplicating && (
diff --git a/apps/studio/styles/editor.scss b/apps/studio/styles/editor.scss
index 9c9236d76b3..a863b40cafc 100644
--- a/apps/studio/styles/editor.scss
+++ b/apps/studio/styles/editor.scss
@@ -2,10 +2,6 @@
gap: 0rem !important;
}
-// .table-editor-columns-input .sbui-input {
-// @apply border-none;
-// }
-
.table-editor-column-type .sbui-listbox-option-container {
width: 400px;
}