VariablesUnknownButton.tsx 1009 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import React, { FC, useMemo } from 'react';
  2. import { IconButton } from '@grafana/ui';
  3. import { NetworkGraphModal } from './NetworkGraphModal';
  4. import { UsagesToNetwork } from './utils';
  5. interface Props {
  6. id: string;
  7. usages: UsagesToNetwork[];
  8. }
  9. export const VariablesUnknownButton: FC<Props> = ({ id, usages }) => {
  10. const network = useMemo(() => usages.find((n) => n.variable.id === id), [id, usages]);
  11. if (!network) {
  12. return null;
  13. }
  14. const nodes = network.nodes.map((n) => {
  15. if (n.label.includes(`$${id}`)) {
  16. return { ...n, color: '#FB7E81' };
  17. }
  18. return n;
  19. });
  20. return (
  21. <NetworkGraphModal show={false} title={`Showing usages for: $${id}`} nodes={nodes} edges={network.edges}>
  22. {({ showModal }) => {
  23. return (
  24. <IconButton
  25. onClick={() => showModal()}
  26. name="code-branch"
  27. title="Show usages"
  28. data-testid="VariablesUnknownButton"
  29. />
  30. );
  31. }}
  32. </NetworkGraphModal>
  33. );
  34. };