import { gridClasses } from '@mui/material'; import { FC, ReactNode, useMemo } from 'react'; import AnvilSummary from './AnvilSummary'; import { toAnvilOverviewList } from '../../lib/api_converters'; import Grid from '../Grid'; import { InnerPanel, InnerPanelBody, InnerPanelHeader, Panel, PanelHeader, } from '../Panels'; import Spinner from '../Spinner'; import { BodyText, HeaderText } from '../Text'; import useFetch from '../../hooks/useFetch'; const AnvilSummaryList: FC = (props) => { const { refreshInterval = 5000 } = props; const { data: rawAnvils, loading: loadingAnvils } = useFetch('/anvil', { refreshInterval }); const anvils = useMemo( () => rawAnvils && toAnvilOverviewList(rawAnvils), [rawAnvils], ); const grid = useMemo( () => anvils && ( ( (previous, current) => { const { description, name, uuid } = current; const key = `anvil-${uuid}`; previous[key] = { children: ( {name}: {description} ), }; return previous; }, {}, )} spacing="1em" sx={{ alignContent: 'stretch', [`& > .${gridClasses.item}`]: { minWidth: '20em', }, }} /> ), [anvils, refreshInterval], ); return ( Nodes {loadingAnvils ? : grid} ); }; export default AnvilSummaryList;