import React, { useContext, useEffect, useState } from 'react'; import getMounts, { Context as MountsContext } from '@/api/admin/mounts/getMounts'; 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'; import CopyOnClick from '@/components/elements/CopyOnClick'; 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 match = useRouteMatch(); const { page, setPage } = 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: React.ChangeEvent) => { setSelectedMounts(e.currentTarget.checked ? (mounts?.items?.map(mount => mount.id) || []) : []); }; useEffect(() => { setSelectedMounts([]); }, [ page ]); return (

Mounts

Configure and manage additional mount points for servers.

{ mounts === undefined || (error && isValidating) ? : length < 1 ? :
)) }
{ mounts.items.map(mount => ( {mount.id} {mount.name} {mount.source} {mount.target} { mount.readOnly ? Read Only : Writable } { mount.userMountable ? Mountable : Admin Only }
}
); }; export default () => { const [ page, setPage ] = useState(1); return ( ); };