import { css, cx } from '@emotion/css'; import React, { FC } from 'react'; import { useFormContext, useFieldArray } from 'react-hook-form'; import { GrafanaTheme2 } from '@grafana/data'; import { Button, Field, Input, IconButton, InputControl, useStyles2, Select } from '@grafana/ui'; import { MatcherOperator } from 'app/plugins/datasource/alertmanager/types'; import { SilenceFormFields } from '../../types/silence-form'; import { matcherFieldOptions } from '../../utils/alertmanager'; interface Props { className?: string; } const MatchersField: FC = ({ className }) => { const styles = useStyles2(getStyles); const formApi = useFormContext(); const { control, register, formState: { errors }, } = formApi; const { fields: matchers = [], append, remove } = useFieldArray({ name: 'matchers' }); return (
{matchers.map((matcher, index) => { return (
( {matchers.length > 1 && ( remove(index)} > Remove )}
); })}
); }; const getStyles = (theme: GrafanaTheme2) => { return { wrapper: css` margin-top: ${theme.spacing(2)}; `, row: css` display: flex; align-items: flex-start; flex-direction: row; background-color: ${theme.colors.background.secondary}; padding: ${theme.spacing(1)} ${theme.spacing(1)} 0 ${theme.spacing(1)}; & > * + * { margin-left: ${theme.spacing(2)}; } `, removeButton: css` margin-left: ${theme.spacing(1)}; margin-top: ${theme.spacing(2.5)}; `, matcherOptions: css` min-width: 140px; `, matchers: css` max-width: ${theme.breakpoints.values.sm}px; margin: ${theme.spacing(1)} 0; padding-top: ${theme.spacing(0.5)}; `, }; }; export default MatchersField;