import { useQuery, gql } from '@apollo/client' import Button from '@mui/material/Button' import classnames from 'classnames' import * as R from 'ramda' import React from 'react' import { cardState } from '../../../components/CollapsibleCard' import { Label1, H4 } from '../../../components/typography' import AlertsTable from './AlertsTable' const NUM_TO_RENDER = 3 const GET_ALERTS = gql` query getAlerts { alerts { id type detail message created read valid } machines { deviceId name } } ` const Alerts = ({ onReset, onExpand, size }) => { const showAllItems = size === cardState.EXPANDED const { data } = useQuery(GET_ALERTS) const alerts = R.path(['alerts'])(data) ?? [] const machines = R.compose( R.map(R.prop('name')), R.indexBy(R.prop('deviceId')), )(data?.machines ?? []) const alertsLength = alerts.length return ( <>

{`Alerts (${alertsLength})`}

{showAllItems && ( )}
{!alerts.length && ( No new alerts. Your system is running smoothly. )}
{!showAllItems && alertsLength > NUM_TO_RENDER && (
)} ) } export default Alerts