import { Select, Typography } from 'antd'; import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder'; import { useAppContext } from 'providers/App/App'; import { useMemo } from 'react'; import { useCreateAlertState } from '../context'; import { ANOMALY_ALGORITHM_OPTIONS, ANOMALY_SEASONALITY_OPTIONS, ANOMALY_THRESHOLD_MATCH_TYPE_OPTIONS, ANOMALY_THRESHOLD_OPERATOR_OPTIONS, ANOMALY_TIME_DURATION_OPTIONS, } from '../context/constants'; import { AnomalyAndThresholdProps } from './types'; import { getQueryNames, NotificationChannelsNotFoundContent, RoutingPolicyBanner, } from './utils'; function AnomalyThreshold({ channels, isLoadingChannels, isErrorChannels, refreshChannels, }: AnomalyAndThresholdProps): JSX.Element { const { user } = useAppContext(); const { thresholdState, setThresholdState, notificationSettings, setNotificationSettings, } = useCreateAlertState(); const { currentQuery } = useQueryBuilder(); const queryNames = getQueryNames(currentQuery); const deviationOptions = useMemo(() => { const options = []; for (let i = 1; i <= 7; i++) { options.push({ label: i.toString(), value: i }); } return options; }, []); const updateThreshold = ( id: string, field: string, value: string | string[], ): void => { setThresholdState({ type: 'SET_THRESHOLDS', payload: thresholdState.thresholds.map((t) => t.id === id ? { ...t, [field]: value } : t, ), }); }; return (
{/* Sentence 1 */}
Send notification when the observed value for { setThresholdState({ type: 'SET_EVALUATION_WINDOW', payload: value, }); }} options={ANOMALY_TIME_DURATION_OPTIONS} />
{/* Sentence 2 */} is { setThresholdState({ type: 'SET_OPERATOR', payload: value, }); }} options={ANOMALY_THRESHOLD_OPERATOR_OPTIONS} /> the predicted data { setThresholdState({ type: 'SET_ALGORITHM', payload: value, }); }} options={ANOMALY_ALGORITHM_OPTIONS} /> algorithm with updateThreshold(thresholdState.thresholds[0].id, 'channels', value) } style={{ width: 350 }} options={channels.map((channel) => ({ value: channel.id, label: channel.name, }))} mode="multiple" placeholder="Select notification channels" showSearch maxTagCount={2} maxTagPlaceholder={(omittedValues): string => `+${omittedValues.length} more` } maxTagTextLength={10} filterOption={(input, option): boolean => option?.label?.toLowerCase().includes(input.toLowerCase()) || false } status={isErrorChannels ? 'error' : undefined} disabled={isLoadingChannels} notFoundContent={ } /> ) : ( seasonality )}
); } export default AnomalyThreshold;