2023-01-11 14:39:06 +05:30
|
|
|
import { Form, Select } from 'antd';
|
2022-07-14 13:23:15 +05:30
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
|
import { AlertDef, Labels } from 'types/api/alerts/def';
|
2023-06-14 12:53:50 +05:30
|
|
|
import { requireErrorMessage } from 'utils/form/requireErrorMessage';
|
2023-11-01 22:47:27 +05:30
|
|
|
import { popupContainer } from 'utils/selectPopupContainer';
|
2022-07-14 13:23:15 +05:30
|
|
|
|
2022-08-02 09:54:24 +05:30
|
|
|
import ChannelSelect from './ChannelSelect';
|
2022-07-14 13:23:15 +05:30
|
|
|
import LabelSelect from './labels';
|
|
|
|
|
import {
|
2022-08-02 09:54:24 +05:30
|
|
|
ChannelSelectTip,
|
2022-07-14 13:23:15 +05:30
|
|
|
FormContainer,
|
2022-08-02 09:54:24 +05:30
|
|
|
FormItemMedium,
|
2022-07-14 13:23:15 +05:30
|
|
|
InputSmall,
|
|
|
|
|
SeveritySelect,
|
|
|
|
|
StepHeading,
|
|
|
|
|
TextareaMedium,
|
|
|
|
|
} from './styles';
|
|
|
|
|
|
|
|
|
|
const { Option } = Select;
|
|
|
|
|
|
|
|
|
|
interface BasicInfoProps {
|
|
|
|
|
alertDef: AlertDef;
|
|
|
|
|
setAlertDef: (a: AlertDef) => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function BasicInfo({ alertDef, setAlertDef }: BasicInfoProps): JSX.Element {
|
|
|
|
|
// init namespace for translations
|
2022-07-15 21:33:30 +05:30
|
|
|
const { t } = useTranslation('alerts');
|
2022-07-14 13:23:15 +05:30
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<StepHeading> {t('alert_form_step3')} </StepHeading>
|
|
|
|
|
<FormContainer>
|
2023-01-11 14:39:06 +05:30
|
|
|
<Form.Item
|
2022-07-14 13:23:15 +05:30
|
|
|
label={t('field_severity')}
|
|
|
|
|
labelAlign="left"
|
|
|
|
|
name={['labels', 'severity']}
|
|
|
|
|
>
|
|
|
|
|
<SeveritySelect
|
2023-11-01 22:47:27 +05:30
|
|
|
getPopupContainer={popupContainer}
|
2022-07-14 13:23:15 +05:30
|
|
|
defaultValue="critical"
|
|
|
|
|
onChange={(value: unknown | string): void => {
|
|
|
|
|
const s = (value as string) || 'critical';
|
|
|
|
|
setAlertDef({
|
|
|
|
|
...alertDef,
|
|
|
|
|
labels: {
|
|
|
|
|
...alertDef.labels,
|
|
|
|
|
severity: s,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Option value="critical">{t('option_critical')}</Option>
|
|
|
|
|
<Option value="error">{t('option_error')}</Option>
|
|
|
|
|
<Option value="warning">{t('option_warning')}</Option>
|
|
|
|
|
<Option value="info">{t('option_info')}</Option>
|
|
|
|
|
</SeveritySelect>
|
2023-01-11 14:39:06 +05:30
|
|
|
</Form.Item>
|
2022-07-14 13:23:15 +05:30
|
|
|
|
2023-06-14 12:53:50 +05:30
|
|
|
<Form.Item
|
|
|
|
|
required
|
|
|
|
|
name="alert"
|
|
|
|
|
labelAlign="left"
|
|
|
|
|
label={t('field_alert_name')}
|
|
|
|
|
rules={[
|
|
|
|
|
{ required: true, message: requireErrorMessage(t('field_alert_name')) },
|
|
|
|
|
]}
|
|
|
|
|
>
|
2022-07-14 13:23:15 +05:30
|
|
|
<InputSmall
|
|
|
|
|
onChange={(e): void => {
|
|
|
|
|
setAlertDef({
|
|
|
|
|
...alertDef,
|
|
|
|
|
alert: e.target.value,
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2023-01-11 14:39:06 +05:30
|
|
|
</Form.Item>
|
|
|
|
|
<Form.Item
|
2022-07-14 13:23:15 +05:30
|
|
|
label={t('field_alert_desc')}
|
|
|
|
|
labelAlign="left"
|
|
|
|
|
name={['annotations', 'description']}
|
|
|
|
|
>
|
|
|
|
|
<TextareaMedium
|
|
|
|
|
onChange={(e): void => {
|
|
|
|
|
setAlertDef({
|
|
|
|
|
...alertDef,
|
|
|
|
|
annotations: {
|
|
|
|
|
...alertDef.annotations,
|
|
|
|
|
description: e.target.value,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2023-01-11 14:39:06 +05:30
|
|
|
</Form.Item>
|
2022-08-02 09:54:24 +05:30
|
|
|
<FormItemMedium label={t('field_labels')}>
|
2022-07-14 13:23:15 +05:30
|
|
|
<LabelSelect
|
|
|
|
|
onSetLabels={(l: Labels): void => {
|
|
|
|
|
setAlertDef({
|
|
|
|
|
...alertDef,
|
|
|
|
|
labels: {
|
|
|
|
|
...l,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
initialValues={alertDef.labels}
|
|
|
|
|
/>
|
2022-08-02 09:54:24 +05:30
|
|
|
</FormItemMedium>
|
|
|
|
|
<FormItemMedium label="Notification Channels">
|
|
|
|
|
<ChannelSelect
|
|
|
|
|
currentValue={alertDef.preferredChannels}
|
2023-06-14 12:53:50 +05:30
|
|
|
onSelectChannels={(preferredChannels): void => {
|
2022-08-02 09:54:24 +05:30
|
|
|
setAlertDef({
|
|
|
|
|
...alertDef,
|
2023-06-14 12:53:50 +05:30
|
|
|
preferredChannels,
|
2022-08-02 09:54:24 +05:30
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<ChannelSelectTip> {t('channel_select_tooltip')}</ChannelSelectTip>
|
|
|
|
|
</FormItemMedium>
|
2022-07-14 13:23:15 +05:30
|
|
|
</FormContainer>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default BasicInfo;
|