2021-04-14 15:57:36 +03:00
|
|
|
import { SelectableValue } from '@grafana/data';
|
2021-04-16 14:57:33 +03:00
|
|
|
import React, { FC, useMemo } from 'react';
|
|
|
|
|
import { SelectWithAdd } from './SelectWIthAdd';
|
2021-04-14 15:57:36 +03:00
|
|
|
|
|
|
|
|
enum AnnotationOptions {
|
|
|
|
|
description = 'Description',
|
|
|
|
|
dashboard = 'Dashboard',
|
|
|
|
|
summary = 'Summary',
|
|
|
|
|
runbook = 'Runbook URL',
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
|
onChange: (value: string) => void;
|
|
|
|
|
existingKeys: string[];
|
|
|
|
|
|
|
|
|
|
value?: string;
|
|
|
|
|
width?: number;
|
|
|
|
|
className?: string;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-16 14:57:33 +03:00
|
|
|
export const AnnotationKeyInput: FC<Props> = ({ value, existingKeys, ...rest }) => {
|
2021-04-14 15:57:36 +03:00
|
|
|
const annotationOptions = useMemo(
|
2021-04-16 14:57:33 +03:00
|
|
|
(): SelectableValue[] =>
|
|
|
|
|
Object.entries(AnnotationOptions)
|
2021-04-14 15:57:36 +03:00
|
|
|
.filter(([optKey]) => !existingKeys.includes(optKey)) // remove keys already taken in other annotations
|
|
|
|
|
.map(([key, value]) => ({ value: key, label: value })),
|
|
|
|
|
[existingKeys]
|
|
|
|
|
);
|
|
|
|
|
|
2021-04-16 14:57:33 +03:00
|
|
|
return (
|
|
|
|
|
<SelectWithAdd
|
|
|
|
|
value={value}
|
|
|
|
|
options={annotationOptions}
|
|
|
|
|
custom={!!value && !Object.keys(AnnotationOptions).includes(value)}
|
|
|
|
|
{...rest}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2021-04-14 15:57:36 +03:00
|
|
|
};
|