refactor: filter out empty nodes before rendering a component

main
Josue 4 years ago committed by Tsu-ba-me
parent 6611d9f91b
commit 9945915f5a
  1. 9
      striker-ui/components/Servers.tsx
  2. 2
      striker-ui/lib/sanitizers/hostsSanitizer.ts

@ -68,6 +68,8 @@ const Servers = ({ anvil }: { anvil: AnvilListItem[] }): JSX.Element => {
const anvilIndex = anvil.findIndex((a) => a.anvil_uuid === uuid); const anvilIndex = anvil.findIndex((a) => a.anvil_uuid === uuid);
const filteredHosts = hostsSanitizer(anvil[anvilIndex]?.hosts);
return ( return (
<Panel> <Panel>
<div className={classes.headerPadding}> <div className={classes.headerPadding}>
@ -103,7 +105,7 @@ const Servers = ({ anvil }: { anvil: AnvilListItem[] }): JSX.Element => {
<Box display="flex" className={classes.hostsBox}> <Box display="flex" className={classes.hostsBox}>
{server.server_state !== 'shut off' && {server.server_state !== 'shut off' &&
server.server_state !== 'crashed' && server.server_state !== 'crashed' &&
hostsSanitizer(anvil[anvilIndex].hosts).map( filteredHosts.map(
( (
host: AnvilStatusHost, host: AnvilStatusHost,
index: number, index: number,
@ -122,10 +124,7 @@ const Servers = ({ anvil }: { anvil: AnvilListItem[] }): JSX.Element => {
} }
/> />
</Box> </Box>
{index !== {index !== filteredHosts.length - 1 && (
hostsSanitizer(anvil[anvilIndex].hosts)
.length -
1 && (
<Divider <Divider
className={`${classes.divider} ${classes.verticalDivider}`} className={`${classes.divider} ${classes.verticalDivider}`}
orientation="vertical" orientation="vertical"

@ -1,7 +1,7 @@
const hostsSanitizer = ( const hostsSanitizer = (
data: Array<AnvilStatusHost>, data: Array<AnvilStatusHost>,
): Array<AnvilStatusHost> => { ): Array<AnvilStatusHost> => {
return data.filter((host) => host.host_uuid); return data?.filter((host) => host.host_uuid);
}; };
export default hostsSanitizer; export default hostsSanitizer;

Loading…
Cancel
Save