mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 01:53:33 -06:00
* refactor: tooltip is required * refactor: add tooltips * refactor: add tooltips * refactor: add tooltips * refactor: add tooltips * refactor: add tooltips * refactor: add tooltips * refactor: adjust tests * refactor: apply changes from code review * refactor: adjust component for e2e test * refactor: adjust fallback * refactor: apply changes from code review * refactor: apply changes from code review * refactor: set IconButton default as type=button and remove from use cases * refactor: remove aria-labels when duplicated and type=button from use cases * refactor: clean up * refactor: fix tests * refactor: fix type errors * refactor: remove changes in order in order to add them to a separate PR * refactor: set IconButton default as type=button * refactor: remove tooltip * refactor: apply changes requested in review
45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
import React, { useMemo } from 'react';
|
|
|
|
import { reportInteraction } from '@grafana/runtime';
|
|
import { IconButton } from '@grafana/ui';
|
|
|
|
import { NetworkGraphModal } from './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) => n.variable.id === 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="Show usages"
|
|
/>
|
|
);
|
|
}}
|
|
</NetworkGraphModal>
|
|
);
|
|
};
|