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/AnnotationKeyInput.tsx

37 lines
1004 B

import { useMemo } from 'react';
import { SelectableValue } from '@grafana/data';
import { Annotation, annotationLabels } from '../../utils/constants';
import { SelectWithAdd } from './SelectWIthAdd';
interface Props {
onChange: (value: string) => void;
existingKeys: string[];
value?: string;
width?: number;
className?: string;
'aria-label'?: string;
}
export const AnnotationKeyInput = ({ value, existingKeys, 'aria-label': ariaLabel, ...rest }: Props) => {
const annotationOptions = useMemo(
(): SelectableValue[] =>
Object.values(Annotation)
.filter((key) => !existingKeys.includes(key)) // remove keys already taken in other annotations
.map((key) => ({ value: key, label: annotationLabels[key] })),
[existingKeys]
);
return (
<SelectWithAdd
aria-label={ariaLabel}
value={value}
options={annotationOptions}
custom={!!value && !(Object.values(Annotation) as string[]).includes(value)}
{...rest}
/>
);
};