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';
import { useTranslation } from 'react-i18next';
import { TFunction } from 'i18next';
const thresholdOptions = (t: TFunction) => [
{ label: t('15 minutes'), value: 15 },
{ label: t('30 minutes'), value: 30 },
{ label: t('1 hour'), value: 60 },
{ label: t('2 hours'), value: 120 },
{ label: t('4 hours'), value: 240 },
{ label: t('1 day'), value: 1440 },
];
const changeOptions = (t: TFunction) => [
{ label: t('change'), value: 'change' },
{ label: t('% change'), value: 'percent' },
];
function Circle({ text }: { text: string }) {
return (
{text}
);
}
function Section({
index,
title,
description,
content,
}: {
index: string;
title: string;
description?: string;
content: any;
}) {
return (
{title}
{description && (
{description}
)}
{content}
);
}
function AlertForm(props) {
const { t } = useTranslation();
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 (
);
}
export default observer(AlertForm);