The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/dashboard-scene/variables/VariableUsagesButton.tsx

48 lines
1.3 KiB

import { useMemo } from 'react';
import { reportInteraction } from '@grafana/runtime';
import { IconButton } from '@grafana/ui';
import { t } from 'app/core/internationalization';
import { NetworkGraphModal } from 'app/features/variables/inspect/NetworkGraphModal';
import { UsagesToNetwork } from './utils';
interface Props {
id: string;
usages: UsagesToNetwork[];
isAdhoc: boolean;
}
export const VariableUsagesButton = ({ id, usages, isAdhoc }: Props) => {
const network = useMemo(
() => usages.find((n) => (typeof n.variable === 'string' ? n.variable : n.variable.state.name) === id),
[usages, id]
);
if (usages.length === 0 || isAdhoc || !network) {
return null;
}
const nodes = network.nodes.map((n) => {
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 }) => {
return (
<IconButton
onClick={() => {
reportInteraction('Show variable usages');
showModal();
}}
name="code-branch"
tooltip={t('dashboard-scene.variable-usages-button.tooltip-show-usages', 'Show usages')}
/>
);
}}
</NetworkGraphModal>
);
};