import type { ColumnDef } from '@tanstack/react-table'; import { useStore } from '@tanstack/react-form'; import { Link } from '@tanstack/react-router'; import { type AdminDatabaseHost, deleteAdminDatabaseHostInput, useDeleteAdminDatabaseHost, } from '@/api/admin/database-hosts/queries'; import Button from '@/components/elements/Button'; import { Dialog } from '@/components/elements/dialog'; import SpinnerOverlay from '@/components/elements/SpinnerOverlay'; import DataTableColumnHeader from '@/components/elements/table/DataTableColumnHeader'; import { actionsColumn, DeleteAction, EditLinkAction, RowActions } from '@/components/elements/table/RowActions'; import { Form, useAppForm } from '@/components/form'; import dayjs from '@/lib/dayjs'; import { relationshipAttributes } from '@/api/relationships'; interface DatabaseHostDialogProps { host: AdminDatabaseHost; open: boolean; onClose: () => void; } function DeleteDatabaseHostDialog({ host, open, onClose }: DatabaseHostDialogProps) { const deleteDatabaseHost = useDeleteAdminDatabaseHost(); const deleteForm = useAppForm({ defaultValues: { confirm: '' }, onSubmit: async () => { try { await deleteDatabaseHost.mutateAsync( deleteAdminDatabaseHostInput(host.attributes.id, host.attributes.name) ); onClose(); } catch { // Error toast is handled by the mutation. } }, }); const isSubmitting = useStore(deleteForm.store, (state) => state.isSubmitting); return (

Deleting a database host is permanent. This will permanently delete{' '} {host.attributes.name}.

value === host.attributes.name ? undefined : 'The host name must be provided.', }} > {(field) => ( )}
Cancel Delete host
); } const HostIdentityCell = ({ host }: { host: AdminDatabaseHost }) => { const { name, username, host: address, port } = host.attributes; const connection = `${username}@${address}:${port}`; return (
{name}

{connection}

); }; const HostNodeCell = ({ host }: { host: AdminDatabaseHost }) => { const node = relationshipAttributes(host.attributes.relationships?.node); if (node) return ( {node.name} ); return ( {host.attributes.node_id === null ? 'Global host' : `Node #${host.attributes.node_id}`} ); }; const HostActionsCell = ({ host }: { host: AdminDatabaseHost }) => ( } > {({ open, onClose }) => } ); export const databaseHostColumns = [ { id: 'name', accessorFn: (host) => host.attributes.name, header: ({ column }) => , cell: ({ row }) => , enableSorting: true, meta: { headerClassName: 'min-w-48', cellClassName: 'min-w-48' }, }, { id: 'node', header: 'Node', cell: ({ row }) => , enableSorting: false, meta: { headerClassName: 'hidden w-36 @lg:table-cell', cellClassName: 'hidden w-36 @lg:table-cell' }, }, { id: 'databases_count', header: 'Databases', cell: ({ row }) => {row.original.attributes.databases_count}, enableSorting: false, meta: { headerClassName: 'hidden w-28 @xl:table-cell', cellClassName: 'hidden w-28 @xl:table-cell' }, }, { id: 'created_at', accessorFn: (host) => host.attributes.created_at, header: ({ column }) => , cell: ({ row }) => ( ), enableSorting: true, sortDescFirst: true, meta: { headerClassName: 'hidden w-28 @2xl:table-cell', cellClassName: 'hidden w-28 @2xl:table-cell' }, }, actionsColumn(2, (host) => ), ] satisfies ColumnDef[];