import { Select, Typography } from 'antd'; import FormItem from 'antd/lib/form/FormItem'; import React from 'react'; import { useTranslation } from 'react-i18next'; import { AlertDef, defaultCompareOp, defaultEvalWindow, defaultMatchType, } from 'types/api/alerts/def'; import { EQueryType } from 'types/common/dashboard'; import { FormContainer, InlineSelect, StepHeading, ThresholdInput, } from './styles'; const { Option } = Select; function RuleOptions({ alertDef, setAlertDef, queryCategory, }: RuleOptionsProps): JSX.Element { // init namespace for translations const { t } = useTranslation('alerts'); const handleMatchOptChange = (value: string | unknown): void => { const m = (value as string) || alertDef.condition?.matchType; setAlertDef({ ...alertDef, condition: { ...alertDef.condition, matchType: m, }, }); }; const renderCompareOps = (): JSX.Element => { return ( { const newOp = (value as string) || ''; setAlertDef({ ...alertDef, condition: { ...alertDef.condition, op: newOp, }, }); }} > ); }; const renderThresholdMatchOpts = (): JSX.Element => { return ( handleMatchOptChange(value)} > ); }; const renderPromMatchOpts = (): JSX.Element => { return ( handleMatchOptChange(value)} > ); }; const renderEvalWindows = (): JSX.Element => { return ( { const ew = (value as string) || alertDef.evalWindow; setAlertDef({ ...alertDef, evalWindow: ew, }); }} > {' '} ); }; const renderThresholdRuleOpts = (): JSX.Element => { return ( {t('text_condition1')} {renderCompareOps()} {t('text_condition2')}{' '} {renderThresholdMatchOpts()} {t('text_condition3')} {renderEvalWindows()} ); }; const renderPromRuleOptions = (): JSX.Element => { return ( {t('text_condition1')} {renderCompareOps()} {t('text_condition2')}{' '} {renderPromMatchOpts()} ); }; return ( <> {t('alert_form_step2')} {queryCategory === EQueryType.PROM ? renderPromRuleOptions() : renderThresholdRuleOpts()}
{ setAlertDef({ ...alertDef, condition: { ...alertDef.condition, target: (value as number) || undefined, }, }); }} />
); } interface RuleOptionsProps { alertDef: AlertDef; setAlertDef: (a: AlertDef) => void; queryCategory: EQueryType; } export default RuleOptions;