The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/alerting/unified/components/rule-editor/AnnotationHeaderField.tsx

68 lines
2.0 KiB

import { FieldArrayWithId, useFormContext, Controller } from 'react-hook-form';
import { Text, Stack } from '@grafana/ui';
import { RuleFormValues } from '../../types/rule-form';
import { Annotation, annotationDescriptions, annotationLabels } from '../../utils/constants';
import CustomAnnotationHeaderField from './CustomAnnotationHeaderField';
const AnnotationHeaderField = ({
annotationField,
annotations,
annotation,
index,
}: {
annotationField: FieldArrayWithId<RuleFormValues, 'annotations', 'id'>;
annotations: Array<{ key: string; value: string }>;
annotation: Annotation;
index: number;
}) => {
const { control } = useFormContext<RuleFormValues>();
return (
<Stack direction="column" gap={0}>
<label>
{
<Controller
name={`annotations.${index}.key`}
defaultValue={annotationField.key}
render={({ field: { ref, ...field } }) => {
if (!annotationLabels[annotation]) {
return <CustomAnnotationHeaderField field={field} />;
}
let label;
switch (annotationField.key) {
case Annotation.dashboardUID:
label = 'Dashboard and panel';
break;
case Annotation.panelID:
label = '';
break;
default:
label = annotationLabels[annotation] && annotationLabels[annotation] + ' (optional)';
}
return (
<span data-testid={`annotation-key-${index}`}>
<Text color="primary" variant="bodySmall">
{label}
</Text>
</span>
);
}}
control={control}
rules={{ required: { value: !!annotations[index]?.value, message: 'Required.' } }}
/>
}
</label>
<Text variant="bodySmall" color="secondary">
{annotationDescriptions[annotation]}
</Text>
</Stack>
);
};
export default AnnotationHeaderField;