diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx index 3426c247772..75c8d13f774 100644 --- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx +++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/ColumnEditor.tsx @@ -18,17 +18,25 @@ import { isEmpty, noop } from 'lodash' import { ExternalLink, Plus } from 'lucide-react' import Link from 'next/link' import { useEffect, useState } from 'react' -import type { Dictionary } from 'types' import { Button, - Checkbox, - Input, + Checkbox_Shadcn_, + cn, + DialogSectionSeparator, + Sheet, + SheetContent, + SheetFooter, + SheetHeader, + SheetSection, + SheetTitle, SidePanel, - Toggle, + Switch, Tooltip, TooltipContent, TooltipTrigger, } from 'ui' +import { Input } from 'ui-patterns/DataInputs/Input' +import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout' import { ActionBar } from '../ActionBar' import type { ForeignKey } from '../ForeignKeySelector/ForeignKeySelector.types' @@ -67,7 +75,7 @@ export interface ColumnEditorProps { existingForeignKeyRelations: ForeignKeyConstraint[] createMore?: boolean }, - resolve: any + resolve: () => void ) => void updateEditorDirty: () => void } @@ -83,7 +91,7 @@ export const ColumnEditor = ({ const { ref } = useParams() const { data: project } = useSelectedProjectQuery() - const [errors, setErrors] = useState>({}) + const [errors, setErrors] = useState<{ [key: string]: string }>({}) const [columnFields, setColumnFields] = useState() const [fkRelations, setFkRelations] = useState([]) const [createMore, setCreateMore] = useState(false) @@ -135,6 +143,7 @@ export const ColumnEditor = ({ setColumnFields(columnFields) setFkRelations(formatForeignKeys(foreignKeys)) } + // eslint-disable-next-line react-hooks/exhaustive-deps }, [visible]) if (!columnFields) return null @@ -195,7 +204,7 @@ export const ColumnEditor = ({ existingForeignKeyRelations: foreignKeys, createMore, } - saveChanges(payload, isNewRecord, configuration, (err?: any) => { + saveChanges(payload, isNewRecord, configuration, (err?: string) => { resolve() if (!err && createMore && isNewRecord) { const freshColumnFields = generateColumnField({ @@ -214,234 +223,295 @@ export const ColumnEditor = ({ } return ( - void) => onSaveChanges(resolve)} - // @ts-ignore - header={} - onCancel={closePanel} - customFooter={ - void) => onSaveChanges(resolve)} - visible={visible} - > - {isNewRecord && ( -
- setCreateMore(!createMore)} - /> - -
- )} -
- } - > - General}> - - onUpdateField({ name: event.target.value })} - /> - onUpdateField({ comment: event.target.value })} - /> - - - - - - - + onUpdateField({ name: event.target.value })} + /> + {errors.name &&

{errors.name}

} + + + onUpdateField({ comment: event.target.value })} + /> + + +
+ + + + + + + + } + > + Data Type + } > - Data Type - - } - > - - onUpdateField({ format, defaultValue: null })} - /> - {columnFields.foreignKey === undefined && ( -
- {columnFields.format.includes('int') && ( -
- { - const isIdentity = !columnFields.isIdentity - const isArray = isIdentity ? false : columnFields.isArray - onUpdateField({ isIdentity, isArray }) - }} - /> + + onUpdateField({ format, defaultValue: null })} + /> + {columnFields.foreignKey === undefined && ( +
+ {columnFields.format.includes('int') && ( + + { + const isIdentity = !columnFields.isIdentity + const isArray = isIdentity ? false : columnFields.isArray + onUpdateField({ isIdentity, isArray }) + }} + /> + + )} + {!columnFields.isPrimaryKey && ( + + { + const isArray = !columnFields.isArray + const isIdentity = isArray ? false : columnFields.isIdentity + onUpdateField({ isArray, isIdentity }) + }} + /> + + )}
)} - {!columnFields.isPrimaryKey && ( -
- { - const isArray = !columnFields.isArray - const isIdentity = isArray ? false : columnFields.isIdentity - onUpdateField({ isArray, isIdentity }) - }} - /> -
- )} -
- )} - - - + + + - + - Foreign Keys} - > - - Foreign Keys} + > + + { + if (format[0] === '_') { + onUpdateField({ format: format.slice(1), isArray: true, isIdentity: false }) + } else { + onUpdateField({ format }) + } + }} + onUpdateFkRelations={setFkRelations} + /> + + + + Constraints} + > + + + + onUpdateField({ + isPrimaryKey: !columnFields?.isPrimaryKey, + isUnique: false, + isNullable: false, + }) + } + /> + + + + + + + onUpdateField({ isNullable: !columnFields.isNullable }) + } + /> + + + {columnFields.isPrimaryKey && ( + + Column is a primary key and hence cannot be NULL + + )} + + + + + + onUpdateField({ isUnique: !columnFields.isUnique })} + /> + + + {columnFields.isPrimaryKey && ( + + Column is a primary key and hence already unique + + )} + + + + onUpdateField({ check: event.target.value })} + className="[&_input]:font-mono" + /> + + + + + + + { - if (format[0] === '_') { - onUpdateField({ format: format.slice(1), isArray: true, isIdentity: false }) - } else { - onUpdateField({ format }) - } - }} - onUpdateFkRelations={setFkRelations} - /> - - - - Constraints} - > - - - onUpdateField({ - isPrimaryKey: !columnFields?.isPrimaryKey, - isUnique: false, - isNullable: false, - }) - } - /> - - - -
- onUpdateField({ isNullable: !columnFields.isNullable })} - /> + applyFunction={(resolve: () => void) => onSaveChanges(resolve)} + visible={visible} + > + {isNewRecord && ( +
+ setCreateMore(!createMore)} /> +
- - - Column is a primary key and hence cannot be NULL - - - - - -
- onUpdateField({ isUnique: !columnFields.isUnique })} - /> -
-
- - Column is a primary key and hence already unique - -
- - onUpdateField({ check: event.target.value })} - className="[&_input]:font-mono" - /> - - - + )} + + + + ) } diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/HeaderTitle.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/HeaderTitle.tsx index f7631bd5214..5bd0f76fd4c 100644 --- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/HeaderTitle.tsx +++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/ColumnEditor/HeaderTitle.tsx @@ -2,7 +2,7 @@ import type { PostgresColumn, PostgresTable } from '@supabase/postgres-meta' interface Props { table: PostgresTable - column: PostgresColumn + column?: PostgresColumn } export const HeaderTitle = ({ table, column }: Props) => { diff --git a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/HeaderTitle.tsx b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/HeaderTitle.tsx index c3c56c2063e..1c22fb3cdce 100644 --- a/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/HeaderTitle.tsx +++ b/apps/studio/components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/HeaderTitle.tsx @@ -7,21 +7,21 @@ interface HeaderTitleProps { export const HeaderTitle = ({ schema, table, isDuplicating }: HeaderTitleProps) => { if (!table) { return ( - <> + Create a new table under {schema} - + ) } if (isDuplicating) { return ( - <> + Duplicate table {table?.name} - + ) } return ( - <> + Update table {table?.name} - + ) }