import CopyOnClick from '@/components/elements/CopyOnClick'; import React, { useContext, useEffect, useState } from 'react'; import getDatabases, { Context as DatabasesContext } from '@/api/admin/databases/getDatabases'; import FlashMessageRender from '@/components/FlashMessageRender'; import useFlash from '@/plugins/useFlash'; import { AdminContext } from '@/state/admin'; import { NavLink, useRouteMatch } from 'react-router-dom'; import tw from 'twin.macro'; import AdminContentBlock from '@/components/admin/AdminContentBlock'; import AdminCheckbox from '@/components/admin/AdminCheckbox'; import AdminTable, { TableBody, TableHead, TableHeader, TableRow, Pagination, Loading, NoItems, ContentWrapper } from '@/components/admin/AdminTable'; import Button from '@/components/elements/Button'; 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 match = useRouteMatch(); const { page, setPage } = useContext(DatabasesContext); const { clearFlashes, clearAndAddHttpError } = useFlash(); const { data: databases, error, isValidating } = getDatabases(); useEffect(() => { if (!error) { clearFlashes('databases'); return; } clearAndAddHttpError({ error, key: 'databases' }); }, [ 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) || []) : []); }; useEffect(() => { setSelectedDatabases([]); }, [ page ]); return (

Databases

Database hosts that servers can have databases created on.

{ databases === undefined || (error && isValidating) ? : length < 1 ? :
{ databases.items.map(database => ( )) }
{database.id} {database.name} {database.getAddress()} {database.username}
}
); }; export default () => { const [ page, setPage ] = useState(1); return ( ); };