import { Grid } from '@mui/material'; import { FC, useMemo } from 'react'; import { v4 as uuidv4 } from 'uuid'; import Autocomplete from '../Autocomplete'; import FlexBox from '../FlexBox'; import IconButton from '../IconButton'; import SelectWithLabel from '../SelectWithLabel'; import { BodyText, SmallText } from '../Text'; import UncontrolledInput from '../UncontrolledInput'; const LEVEL_OPTIONS: SelectItem[] = [ { displayValue: 'Ignore', value: 0 }, { displayValue: 'Critical', value: 1 }, { displayValue: 'Warning', value: 2 }, { displayValue: 'Notice', value: 3 }, { displayValue: 'Info', value: 4 }, ]; const AlertOverrideInputGroup: FC = (props) => { const { alertOverrideTargetOptions, alertOverrideValueId, mailRecipientUuid: mrUuid, formikUtils, } = props; /** * This is the alert override formik value identifier; not to be confused * with the alert override UUID. */ const aoVid = useMemo( () => alertOverrideValueId ?? uuidv4(), [alertOverrideValueId], ); const { formik } = formikUtils; const { values: { [mrUuid]: mailRecipient }, } = formik; const { alertOverrides: { [aoVid]: alertOverride }, } = mailRecipient; const overrideChain = useMemo( () => `${mrUuid}.alertOverrides.${aoVid}`, [aoVid, mrUuid], ); const removeChain = useMemo( () => `${overrideChain}.remove`, [overrideChain], ); const targetChain = useMemo( () => `${overrideChain}.target`, [overrideChain], ); const levelChain = useMemo( () => `${overrideChain}.level`, [overrideChain], ); return ( option.name} id={targetChain} isOptionEqualToValue={(option, value) => option.uuid === value.uuid} label="Target" noOptionsText="No node or subnode found." onChange={(event, value) => formik.setFieldValue(targetChain, value, true) } openOnFocus options={alertOverrideTargetOptions} renderOption={(optionProps, option) => (
  • {option.type === 'node' ? ( {option.name} {option.description} ) : ( {option.name} )}
  • )} value={alertOverride.target} />
    } /> { if (alertOverride.uuids) { formik.setFieldValue(removeChain, true, true); } else { formik.setValues((previous: MailRecipientFormikValues) => { const shallow = { ...previous }; const { [mrUuid]: mr } = shallow; const { [aoVid]: remove, ...keep } = mr.alertOverrides; mr.alertOverrides = { ...keep }; return shallow; }); } }} size="small" />
    ); }; export default AlertOverrideInputGroup;