123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- import {Component, Fragment} from 'react';
- import styled from '@emotion/styled';
- import SelectControl from 'sentry/components/forms/controls/selectControl';
- import FieldGroup from 'sentry/components/forms/fieldGroup';
- import {
- AlertRuleSensitivity,
- AlertRuleThresholdType,
- type UnsavedMetricRule,
- } from 'sentry/views/alerts/rules/metric/types';
- type Props = {
- disabled: boolean;
- onSensitivityChange: (sensitivity: AlertRuleSensitivity) => void;
- onThresholdTypeChange: (thresholdType: AlertRuleThresholdType) => void;
- sensitivity: UnsavedMetricRule['sensitivity'];
- thresholdType: UnsavedMetricRule['thresholdType'];
- /**
- * Map of fieldName -> errorMessage
- */
- error?: {[fieldName: string]: string};
- hideControl?: boolean;
- };
- type SensitivityFormItemProps = {
- onSensitivityChange: (sensitivity: AlertRuleSensitivity) => void;
- sensitivity: UnsavedMetricRule['sensitivity'];
- };
- type DirectionFormItemProps = {
- onThresholdTypeChange: (thresholdType: AlertRuleThresholdType) => void;
- thresholdType: UnsavedMetricRule['thresholdType'];
- };
- function SensitivityFormItem({
- sensitivity,
- onSensitivityChange,
- }: SensitivityFormItemProps) {
- return (
- <StyledField
- label={'Level of responsiveness'}
- id={'sensitivity'}
- help={
- 'Choose your level of anomaly responsiveness. Higher thresholds means alerts for most anomalies. Lower thresholds means alerts only for larger ones.'
- }
- required
- >
- <SelectContainer>
- <SelectControl
- name="sensitivity"
- inputId={'sensitivity'}
- value={sensitivity}
- options={[
- {
- value: AlertRuleSensitivity.LOW,
- label: 'Low (alert less often)',
- },
- {
- value: AlertRuleSensitivity.MEDIUM,
- label: 'Medium',
- },
- {
- value: AlertRuleSensitivity.HIGH,
- label: 'High (alert more often)',
- },
- ]}
- onChange={({value}) => {
- onSensitivityChange(value);
- }}
- />
- </SelectContainer>
- </StyledField>
- );
- }
- function DirectionFormItem({
- thresholdType,
- onThresholdTypeChange,
- }: DirectionFormItemProps) {
- return (
- <StyledField
- label={'Direction of anomaly movement'}
- help={
- 'Decide if you want to be alerted to anomalies that are moving above, below, or in both directions in relation to your threshold.'
- }
- required
- >
- <SelectContainer>
- <SelectControl
- name="sensitivity"
- value={thresholdType}
- options={[
- {
- value: AlertRuleThresholdType.ABOVE_AND_BELOW,
- label: 'Above and below bounds',
- },
- {
- value: AlertRuleThresholdType.ABOVE,
- label: 'Above bounds only',
- },
- {
- value: AlertRuleThresholdType.BELOW,
- label: 'Below bounds only',
- },
- ]}
- onChange={({value}) => {
- onThresholdTypeChange(value);
- }}
- />
- </SelectContainer>
- </StyledField>
- );
- }
- class AnomalyDetectionFormField extends Component<Props> {
- render() {
- const {sensitivity, onSensitivityChange, thresholdType, onThresholdTypeChange} =
- this.props;
- return (
- <Fragment>
- <SensitivityFormItem
- sensitivity={sensitivity}
- onSensitivityChange={onSensitivityChange}
- />
- <DirectionFormItem
- thresholdType={thresholdType}
- onThresholdTypeChange={onThresholdTypeChange}
- />
- </Fragment>
- );
- }
- }
- const StyledField = styled(FieldGroup)`
- & > label > div:first-child > span {
- display: flex;
- flex-direction: row;
- }
- `;
- const SelectContainer = styled('div')`
- flex: 1;
- `;
- export default AnomalyDetectionFormField;
|