Annotations.tsx 969 B

1234567891011121314151617181920212223242526272829303132333435
  1. import React, { FunctionComponent, useEffect, useState } from 'react';
  2. import { AnnotationQuery, EventBus } from '@grafana/data';
  3. import { AnnotationPicker } from './AnnotationPicker';
  4. interface Props {
  5. events: EventBus;
  6. annotations: AnnotationQuery[];
  7. onAnnotationChanged: (annotation: any) => void;
  8. }
  9. export const Annotations: FunctionComponent<Props> = ({ annotations, onAnnotationChanged, events }) => {
  10. const [visibleAnnotations, setVisibleAnnotations] = useState<AnnotationQuery[]>([]);
  11. useEffect(() => {
  12. setVisibleAnnotations(annotations.filter((annotation) => annotation.hide !== true));
  13. }, [annotations]);
  14. if (visibleAnnotations.length === 0) {
  15. return null;
  16. }
  17. return (
  18. <>
  19. {visibleAnnotations.map((annotation) => (
  20. <AnnotationPicker
  21. events={events}
  22. annotation={annotation}
  23. onEnabledChanged={onAnnotationChanged}
  24. key={annotation.name}
  25. />
  26. ))}
  27. </>
  28. );
  29. };