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

Mounts

Configure and manage additional mount points for servers.

setSort('id')} /> setSort('name')} /> setSort('source')} /> setSort('target')} /> ))}
{mounts !== undefined && !error && !isValidating && length > 0 && mounts.items.map(mount => ( {mount.id} {mount.name} {mount.source} {mount.target} {mount.readOnly ? ( Read Only ) : ( Writable )} {mount.userMountable ? ( Mountable ) : ( Admin Only )}
{mounts === undefined || (error && isValidating) ? ( ) : length < 1 ? ( ) : null}
); }; export default () => { const hooks = useTableHooks(); return ( ); };