VariablesDependenciesButton.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import React, { FC, useMemo } from 'react';
  2. import { Provider } from 'react-redux';
  3. import { reportInteraction } from '@grafana/runtime';
  4. import { Button } from '@grafana/ui';
  5. import { store } from '../../../store/store';
  6. import { VariableModel } from '../types';
  7. import { NetworkGraphModal } from './NetworkGraphModal';
  8. import { createDependencyEdges, createDependencyNodes, filterNodesWithDependencies } from './utils';
  9. interface OwnProps {
  10. variables: VariableModel[];
  11. }
  12. interface ConnectedProps {}
  13. interface DispatchProps {}
  14. type Props = OwnProps & ConnectedProps & DispatchProps;
  15. export const UnProvidedVariablesDependenciesButton: FC<Props> = ({ variables }) => {
  16. const nodes = useMemo(() => createDependencyNodes(variables), [variables]);
  17. const edges = useMemo(() => createDependencyEdges(variables), [variables]);
  18. if (!edges.length) {
  19. return null;
  20. }
  21. return (
  22. <NetworkGraphModal
  23. show={false}
  24. title="Dependencies"
  25. nodes={filterNodesWithDependencies(nodes, edges)}
  26. edges={edges}
  27. >
  28. {({ showModal }) => {
  29. return (
  30. <Button
  31. onClick={() => {
  32. reportInteraction('Show variable dependencies');
  33. showModal();
  34. }}
  35. icon="channel-add"
  36. variant="secondary"
  37. >
  38. Show dependencies
  39. </Button>
  40. );
  41. }}
  42. </NetworkGraphModal>
  43. );
  44. };
  45. export const VariablesDependenciesButton: FC<Props> = (props) => (
  46. <Provider store={store}>
  47. <UnProvidedVariablesDependenciesButton {...props} />
  48. </Provider>
  49. );