2020-11-05 09:53:27 +01:00
|
|
|
import React, { FC, useMemo } from 'react';
|
2022-04-22 14:33:13 +01:00
|
|
|
|
2021-12-08 10:11:01 +01:00
|
|
|
import { reportInteraction } from '@grafana/runtime';
|
2022-04-22 14:33:13 +01:00
|
|
|
import { IconButton } from '@grafana/ui';
|
2020-11-05 09:53:27 +01:00
|
|
|
|
|
|
|
|
import { NetworkGraphModal } from './NetworkGraphModal';
|
2022-04-22 14:33:13 +01:00
|
|
|
import { UsagesToNetwork } from './utils';
|
2020-11-05 09:53:27 +01:00
|
|
|
|
2021-03-09 12:49:05 +01:00
|
|
|
interface Props {
|
|
|
|
|
id: string;
|
|
|
|
|
usages: UsagesToNetwork[];
|
|
|
|
|
isAdhoc: boolean;
|
2020-11-05 09:53:27 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-09 12:49:05 +01:00
|
|
|
export const VariableUsagesButton: FC<Props> = ({ id, usages, isAdhoc }) => {
|
|
|
|
|
const network = useMemo(() => usages.find((n) => n.variable.id === id), [usages, id]);
|
|
|
|
|
if (usages.length === 0 || isAdhoc || !network) {
|
2020-11-05 09:53:27 +01:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-20 07:59:48 +01:00
|
|
|
const nodes = network.nodes.map((n) => {
|
2020-11-05 09:53:27 +01:00
|
|
|
if (n.label.includes(`$${id}`)) {
|
|
|
|
|
return { ...n, color: '#FB7E81' };
|
|
|
|
|
}
|
|
|
|
|
return n;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<NetworkGraphModal show={false} title={`Showing usages for: $${id}`} nodes={nodes} edges={network.edges}>
|
|
|
|
|
{({ showModal }) => {
|
2021-12-08 10:11:01 +01:00
|
|
|
return (
|
|
|
|
|
<IconButton
|
|
|
|
|
onClick={() => {
|
|
|
|
|
reportInteraction('Show variable usages');
|
|
|
|
|
showModal();
|
|
|
|
|
}}
|
|
|
|
|
name="code-branch"
|
|
|
|
|
title="Show usages"
|
|
|
|
|
/>
|
|
|
|
|
);
|
2020-11-05 09:53:27 +01:00
|
|
|
}}
|
|
|
|
|
</NetworkGraphModal>
|
|
|
|
|
);
|
|
|
|
|
};
|