2023-03-14 07:38:21 -07:00
|
|
|
import React, { useMemo } from 'react';
|
2022-04-22 14:33:13 +01:00
|
|
|
|
2024-06-12 09:40:52 +01:00
|
|
|
import { TypedVariableModel } from '@grafana/data';
|
2021-12-08 10:11:01 +01:00
|
|
|
import { reportInteraction } from '@grafana/runtime';
|
2022-04-22 14:33:13 +01:00
|
|
|
import { Button } from '@grafana/ui';
|
2021-12-08 10:11:01 +01:00
|
|
|
|
2020-11-05 09:53:27 +01:00
|
|
|
import { NetworkGraphModal } from './NetworkGraphModal';
|
2022-04-22 14:33:13 +01:00
|
|
|
import { createDependencyEdges, createDependencyNodes, filterNodesWithDependencies } from './utils';
|
2020-11-05 09:53:27 +01:00
|
|
|
|
2024-06-12 09:40:52 +01:00
|
|
|
interface Props {
|
|
|
|
|
variables: TypedVariableModel[];
|
2020-11-05 09:53:27 +01:00
|
|
|
}
|
|
|
|
|
|
2024-06-12 09:40:52 +01:00
|
|
|
export const VariablesDependenciesButton = ({ variables }: Props) => {
|
2020-11-05 09:53:27 +01:00
|
|
|
const nodes = useMemo(() => createDependencyNodes(variables), [variables]);
|
|
|
|
|
const edges = useMemo(() => createDependencyEdges(variables), [variables]);
|
|
|
|
|
|
2020-11-20 10:51:32 +01:00
|
|
|
if (!edges.length) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-05 09:53:27 +01:00
|
|
|
return (
|
|
|
|
|
<NetworkGraphModal
|
|
|
|
|
show={false}
|
|
|
|
|
title="Dependencies"
|
|
|
|
|
nodes={filterNodesWithDependencies(nodes, edges)}
|
|
|
|
|
edges={edges}
|
|
|
|
|
>
|
|
|
|
|
{({ showModal }) => {
|
|
|
|
|
return (
|
2021-12-08 10:11:01 +01:00
|
|
|
<Button
|
|
|
|
|
onClick={() => {
|
|
|
|
|
reportInteraction('Show variable dependencies');
|
|
|
|
|
showModal();
|
|
|
|
|
}}
|
|
|
|
|
icon="channel-add"
|
|
|
|
|
variant="secondary"
|
|
|
|
|
>
|
2020-11-05 09:53:27 +01:00
|
|
|
Show dependencies
|
|
|
|
|
</Button>
|
|
|
|
|
);
|
|
|
|
|
}}
|
|
|
|
|
</NetworkGraphModal>
|
|
|
|
|
);
|
|
|
|
|
};
|