import React, { useEffect } from 'react'; import { Button, Form, Input, SegmentSelection, Checkbox, Icon } from 'UI'; import { alertConditions as conditions } from 'App/constants'; import stl from './alertForm.module.css'; import DropdownChips from './DropdownChips'; import { validateEmail } from 'App/validate'; import cn from 'classnames'; import { useStore } from 'App/mstore' import { observer } from 'mobx-react-lite' import Select from 'Shared/Select'; const thresholdOptions = [ { label: '15 minutes', value: 15 }, { label: '30 minutes', value: 30 }, { label: '1 hour', value: 60 }, { label: '2 hours', value: 120 }, { label: '4 hours', value: 240 }, { label: '1 day', value: 1440 }, ]; const changeOptions = [ { label: 'change', value: 'change' }, { label: '% change', value: 'percent' }, ]; const Circle = ({ text }) => (
{text}
); const Section = ({ index, title, description, content }) => (
{title} {description &&
{description}
}
{content}
); function AlertForm(props) { const { slackChannels, msTeamsChannels, webhooks, onDelete, style = { width: '580px', height: '100vh' }, } = props; const { alertsStore } = useStore() const { triggerOptions, loading, } = alertsStore const instance = alertsStore.instance const deleting = loading const write = ({ target: { value, name } }) => alertsStore.edit({ [name]: value }); const writeOption = (e, { name, value }) => alertsStore.edit({ [name]: value.value }); const onChangeCheck = ({ target: { checked, name } }) => alertsStore.edit({ [name]: checked }); useEffect(() => { void alertsStore.fetchTriggerOptions(); }, []); const writeQueryOption = (e, { name, value }) => { const { query } = instance; alertsStore.edit({ query: { ...query, [name]: value } }); }; const writeQuery = ({ target: { value, name } }) => { const { query } = instance; alertsStore.edit({ query: { ...query, [name]: value } }); }; const metric = instance && instance.query.left ? triggerOptions.find((i) => i.value === instance.query.left) : null; const unit = metric ? metric.unit : ''; const isThreshold = instance.detectionMethod === 'threshold'; return (
props.onSubmit(instance)} id="alert-form" >
alertsStore.edit({ [name]: value })} value={{ value: instance.detectionMethod }} list={[ { name: 'Threshold', value: 'threshold' }, { name: 'Change', value: 'change' }, ]} />
{isThreshold && 'Eg. Alert me if memory.avg is greater than 500mb over the past 4 hours.'} {!isThreshold && 'Eg. Alert me if % change of memory.avg is greater than 10% over the past 4 hours compared to the previous 4 hours.'}
} />
{!isThreshold && (
i.value === instance.query.left)} // onChange={ writeQueryOption } onChange={({ value }) => writeQueryOption(null, { name: 'left', value: value.value }) } />
{'test'} )} {!unit && ( )}
writeOption(null, { name: 'previousPeriod', value })} />
)}
} />
{instance.slack && (
alertsStore.edit({ slackInput: selected })} />
)} {instance.msteams && (
alertsStore.edit({ msteamsInput: selected })} />
)} {instance.email && (
alertsStore.edit({ emailInput: selected })} />
)} {instance.webhook && (
alertsStore.edit({ webhookInput: selected })} />
)}
} />
{instance.exists() && ( )}
); }; export default observer(AlertForm);