The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Fix database tables page delete column confirmation modal
Joshen Lim4bc4496ec88b
diff --git a/studio/components/interfaces/Database/Tables/ColumnList.tsx b/studio/components/interfaces/Database/Tables/ColumnList.tsxindex 77929f2abd4..2994c995479 100644--- a/studio/components/interfaces/Database/Tables/ColumnList.tsx+++ b/studio/components/interfaces/Database/Tables/ColumnList.tsx@@ -33,7 +33,7 @@ const Header: FC<{<div>{leftComponents}</div><div><Input- size="tiny"+ size="small"placeholder={filterPlaceholder}value={filterString}onChange={(e: any) => setFilterString(e.target.value)}@@ -47,50 +47,23 @@ const Header: FC<{const ColumnList: FC<{selectedTable: any+ onSelectBack: () => voidonAddColumn: () => voidonEditColumn: (column: any) => void- onSelectBack: () => void- onColumnDeleted: () => void+ onDeleteColumn: (column: any) => void}> = ({selectedTable,+ onSelectBack = () => {},onAddColumn = () => {},onEditColumn = () => {},- onSelectBack = () => {},- onColumnDeleted = () => {},+ onDeleteColumn = () => {},}) => {- const { ui, meta } = useStore()const [filterString, setFilterString] = useState<string>('')const columns =filterString.length === 0? selectedTable.columns: selectedTable.columns.filter((column: any) => column.name.includes(filterString))- async function onDeleteColumn(column: any) {- confirmAlert({- title: 'Confirm to delete',- message: `Are you sure you want to delete the "${column.name}" column? This action cannot be undone.`,- onAsyncConfirm: async () => {- try {- const response: any = await meta.columns.del(column.id)- if (response.error) {- throw response.error- } else {- onColumnDeleted()- ui.setNotification({- category: 'success',- message: `Successfully removed ${column.name}.`,- })- }- } catch (error: any) {- ui.setNotification({- category: 'error',- message: `Failed to delete ${column.name}: ${error.message}`,- })- }- },- })- }-return (<><div className="mb-4">@@ -150,24 +123,16 @@ const ColumnList: FC<{<Table.td className="px-4 py-3 pr-2"><div className="flex gap-2 justify-end"><Button- onClick={() => onDeleteColumn(x)}- icon={<IconTrash />}+ onClick={() => onEditColumn(x)}+ icon={<IconEdit3 />}style={{ padding: 5 }}- type="outline"- // tooltip={{- // title: 'Delete column',- // position: 'top-left',- // }}+ type="text"/><Button- onClick={() => onEditColumn(x)}- icon={<IconEdit3 />}+ onClick={() => onDeleteColumn(x)}+ icon={<IconTrash />}style={{ padding: 5 }}- type="outline"- // tooltip={{- // title: 'Edit Details',- // position: 'top-left',- // }}+ type="text"/></div></Table.td>diff --git a/studio/components/interfaces/Database/Tables/TableList.tsx b/studio/components/interfaces/Database/Tables/TableList.tsxindex aa4f58c4f3c..8d6712672eb 100644--- a/studio/components/interfaces/Database/Tables/TableList.tsx+++ b/studio/components/interfaces/Database/Tables/TableList.tsx@@ -32,7 +32,7 @@ const Header: FC<{<div>{leftComponents}</div><div><Input- size="tiny"+ size="small"placeholder={filterPlaceholder}value={filterString}onChange={(e: any) => setFilterString(e.target.value)}diff --git a/studio/pages/project/[ref]/database/tables.tsx b/studio/pages/project/[ref]/database/tables.tsxindex 982c3ba97d1..62db6119850 100644--- a/studio/pages/project/[ref]/database/tables.tsx+++ b/studio/pages/project/[ref]/database/tables.tsx@@ -49,6 +49,11 @@ const DatabaseTables: NextPage = () => {setSelectedColumnToEdit(column)}+ const onDeleteColumn = (column: PostgresColumn) => {+ setIsDeleting(true)+ setSelectedColumnToDelete(column)+ }+const onColumnUpdated = async () => {const updatedTable = await meta.tables.loadById(selectedTable.id)setSelectedTable(updatedTable)@@ -80,6 +85,31 @@ const DatabaseTables: NextPage = () => {}}+ const onConfirmDeleteColumn = async () => {+ try {+ if (isUndefined(selectedColumnToDelete)) return++ const response: any = await meta.columns.del(selectedColumnToDelete.id)+ if (response.error) {+ throw response.error+ } else {+ onColumnUpdated()+ ui.setNotification({+ category: 'success',+ message: `Successfully removed ${selectedColumnToDelete.name}.`,+ })+ }+ } catch (error: any) {+ ui.setNotification({+ category: 'error',+ message: `Failed to delete ${selectedColumnToDelete?.name}: ${error.message}`,+ })+ } finally {+ setIsDeleting(false)+ setSelectedColumnToDelete(undefined)+ }+ }+return (<DatabaseLayout title="Database"><div className="p-4">@@ -95,8 +125,8 @@ const DatabaseTables: NextPage = () => {selectedTable={selectedTable}onAddColumn={onAddColumn}onEditColumn={onEditColumn}+ onDeleteColumn={onDeleteColumn}onSelectBack={() => setSelectedTable(undefined)}- onColumnDeleted={onColumnUpdated}/>)}</div>@@ -116,6 +146,22 @@ const DatabaseTables: NextPage = () => {onSelectCancel={() => setIsDeleting(false)}onSelectConfirm={onConfirmDeleteTable}/>+ <ConfirmationModal+ danger+ visible={isDeleting && !isUndefined(selectedColumnToDelete)}+ header={`Confirm deletion of column "${selectedColumnToDelete?.name}"`}+ children={+ <Modal.Content>+ <p className="py-4 text-sm text-scale-1100">+ Are you sure you want to delete the selected column? This action cannot be undone.+ </p>+ </Modal.Content>+ }+ buttonLabel="Delete"+ buttonLoadingLabel="Deleting"+ onSelectCancel={() => setIsDeleting(false)}+ onSelectConfirm={onConfirmDeleteColumn}+ /><SidePanelEditorsidePanelKey={sidePanelKey}selectedSchema="public"