grafana/public/app/features/dashboard/components/SubMenu/Annotations.tsx
Ashley Harrison 3cf95d7eee
Chore: fix some anys pt.2 (#53928)
* correctly type some more any's

* undo this change for now...
2022-08-22 16:51:33 +01:00

36 lines
1003 B
TypeScript

import React, { FunctionComponent, useEffect, useState } from 'react';
import { AnnotationQuery, DataQuery, EventBus } from '@grafana/data';
import { AnnotationPicker } from './AnnotationPicker';
interface Props {
events: EventBus;
annotations: AnnotationQuery[];
onAnnotationChanged: (annotation: AnnotationQuery<DataQuery>) => void;
}
export const Annotations: FunctionComponent<Props> = ({ annotations, onAnnotationChanged, events }) => {
const [visibleAnnotations, setVisibleAnnotations] = useState<AnnotationQuery[]>([]);
useEffect(() => {
setVisibleAnnotations(annotations.filter((annotation) => annotation.hide !== true));
}, [annotations]);
if (visibleAnnotations.length === 0) {
return null;
}
return (
<>
{visibleAnnotations.map((annotation) => (
<AnnotationPicker
events={events}
annotation={annotation}
onEnabledChanged={onAnnotationChanged}
key={annotation.name}
/>
))}
</>
);
};