import { useContext, useEffect } from 'react'; import { NavLink } from 'react-router-dom'; import tw from 'twin.macro'; import type { Filters } from '@/api/admin/databases/getDatabases'; import getDatabases, { Context as DatabasesContext } from '@/api/admin/databases/getDatabases'; import useFlash from '@/plugins/useFlash'; import { AdminContext } from '@/state/admin'; import FlashMessageRender from '@/components/FlashMessageRender'; import AdminCheckbox from '@/components/admin/AdminCheckbox'; import AdminContentBlock from '@/components/admin/AdminContentBlock'; import AdminTable, { ContentWrapper, Loading, NoItems, Pagination, TableBody, TableHead, TableHeader, TableRow, useTableHooks, } from '@/components/admin/AdminTable'; import { Button } from '@/components/elements/button'; import { Size } from '@/components/elements/button/types'; import CopyOnClick from '@/components/elements/CopyOnClick'; const RowCheckbox = ({ id }: { id: number }) => { const isChecked = AdminContext.useStoreState(state => state.databases.selectedDatabases.indexOf(id) >= 0); const appendSelectedDatabase = AdminContext.useStoreActions(actions => actions.databases.appendSelectedDatabase); const removeSelectedDatabase = AdminContext.useStoreActions(actions => actions.databases.removeSelectedDatabase); return ( ) => { if (e.currentTarget.checked) { appendSelectedDatabase(id); } else { removeSelectedDatabase(id); } }} /> ); }; const DatabasesContainer = () => { const { page, setPage, setFilters, sort, setSort, sortDirection } = useContext(DatabasesContext); const { clearFlashes, clearAndAddHttpError } = useFlash(); const { data: databases, error, isValidating } = getDatabases(); useEffect(() => { if (!error) { clearFlashes('databases'); return; } clearAndAddHttpError({ key: 'databases', error }); }, [error]); const length = databases?.items?.length || 0; const setSelectedDatabases = AdminContext.useStoreActions(actions => actions.databases.setSelectedDatabases); const selectedDatabasesLength = AdminContext.useStoreState(state => state.databases.selectedDatabases.length); const onSelectAllClick = (e: React.ChangeEvent) => { setSelectedDatabases(e.currentTarget.checked ? databases?.items?.map(database => database.id) || [] : []); }; const onSearch = (query: string): Promise => { return new Promise(resolve => { if (query.length < 2) { setFilters(null); } else { setFilters({ name: query }); } return resolve(); }); }; useEffect(() => { setSelectedDatabases([]); }, [page]); return (

Database Hosts

Database hosts that servers can have databases created on.

setSort('id')} /> setSort('name')} /> {databases !== undefined && !error && !isValidating && length > 0 && databases.items.map(database => ( ))}
{database.id} {database.name} {database.getAddress()} {database.username}
{databases === undefined || (error && isValidating) ? ( ) : length < 1 ? ( ) : null}
); }; export default () => { const hooks = useTableHooks(); return ( ); };