NetworkGraphModal.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import React, { useCallback, useState } from 'react';
  2. import { Modal } from '@grafana/ui';
  3. import { NetworkGraph, Props as NetWorkGraphProps } from './NetworkGraph';
  4. import { GraphEdge, GraphNode } from './utils';
  5. interface NetworkGraphModalApi {
  6. showModal: () => void;
  7. }
  8. interface OwnProps extends Pick<NetWorkGraphProps, 'direction'> {
  9. show: boolean;
  10. title: string;
  11. nodes: GraphNode[];
  12. edges: GraphEdge[];
  13. children: (api: NetworkGraphModalApi) => JSX.Element;
  14. }
  15. interface ConnectedProps {}
  16. interface DispatchProps {}
  17. type Props = OwnProps & ConnectedProps & DispatchProps;
  18. export function NetworkGraphModal({ edges, nodes, show: propsShow, title, children }: Props): JSX.Element {
  19. const [show, setShow] = useState(propsShow);
  20. const showModal = useCallback(() => setShow(true), [setShow]);
  21. const onClose = useCallback(() => setShow(false), [setShow]);
  22. return (
  23. <>
  24. <Modal
  25. isOpen={show}
  26. title={title}
  27. icon="info-circle"
  28. iconTooltip="The graph can be moved, zoomed in, and zoomed out."
  29. onClickBackdrop={onClose}
  30. onDismiss={onClose}
  31. >
  32. <NetworkGraph nodes={nodes} edges={edges} />
  33. </Modal>
  34. {children({ showModal })}
  35. </>
  36. );
  37. }