import React, { useEffect } from 'react'; import { Form, Input, SegmentSelection, Checkbox, Icon, } from 'UI'; import { alertConditions as conditions } from 'App/constants'; 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'; import { Button } from 'antd'; import DropdownChips from './DropdownChips'; import stl from './alertForm.module.css'; 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' }, ]; function Circle({ text }) { return (
{text}
); } function Section({ index, title, description, content, }) { return (
{title} {description &&
{description}
}
{content}
); } function AlertForm(props) { const { slackChannels, msTeamsChannels, webhooks, onDelete, style = { height: "calc('100vh - 40px')" }, } = props; const { alertsStore, metricStore } = useStore(); const { triggerOptions: allTriggerSeries, loading, } = alertsStore; const triggerOptions = metricStore.instance.series.length > 0 ? allTriggerSeries.filter((s) => metricStore.instance.series.findIndex((ms) => ms.seriesId === s.value) !== -1).map((v) => { const labelArr = v.label.split('.'); labelArr.shift(); return { ...v, label: labelArr.join('.'), }; }) : allTriggerSeries; const { instance } = alertsStore; 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);