Alerting: Fix bug for default value in silence matcher (#38735)

This commit is contained in:
Nathan Rodman 2021-08-31 20:51:36 -07:00 committed by GitHub
parent 4f479de88e
commit ad610a1916
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,7 +5,7 @@ import { css, cx } from '@emotion/css';
import { useFormContext, useFieldArray } from 'react-hook-form';
import { SilenceFormFields } from '../../types/silence-form';
import { MatcherOperator } from 'app/plugins/datasource/alertmanager/types';
import { matcherToOperator, matcherFieldToMatcher, matcherFieldOptions } from '../../utils/alertmanager';
import { matcherFieldOptions } from '../../utils/alertmanager';
interface Props {
className?: string;
@ -49,16 +49,12 @@ const MatchersField: FC<Props> = ({ className }) => {
render={({ field: { onChange, ref, ...field } }) => (
<Select
{...field}
onChange={(value) => onChange(value.value)}
className={styles.matcherOptions}
onChange={(value) => onChange(value?.value)}
options={matcherFieldOptions}
/>
)}
defaultValue={
matcherFieldOptions.find(
(field) => field.label === matcherToOperator(matcherFieldToMatcher(matcher))
) || matcherFieldOptions[0]
}
defaultValue={matcher.operator || matcherFieldOptions[0].value}
name={`matchers.${index}.operator` as const}
rules={{ required: { value: true, message: 'Required.' } }}
/>