2020-11-05 02:53:27 -06:00
|
|
|
import React, { FC, useMemo } from 'react';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2020-11-05 02:53:27 -06:00
|
|
|
import { IconButton } from '@grafana/ui';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2020-11-05 02:53:27 -06:00
|
|
|
import { NetworkGraphModal } from './NetworkGraphModal';
|
2022-04-22 08:33:13 -05:00
|
|
|
import { UsagesToNetwork } from './utils';
|
2020-11-05 02:53:27 -06:00
|
|
|
|
2021-03-09 05:49:05 -06:00
|
|
|
interface Props {
|
|
|
|
id: string;
|
|
|
|
usages: UsagesToNetwork[];
|
2020-11-05 02:53:27 -06:00
|
|
|
}
|
|
|
|
|
2021-03-09 05:49:05 -06:00
|
|
|
export const VariablesUnknownButton: FC<Props> = ({ id, usages }) => {
|
|
|
|
const network = useMemo(() => usages.find((n) => n.variable.id === id), [id, usages]);
|
2020-11-05 02:53:27 -06:00
|
|
|
|
2021-03-09 05:49:05 -06:00
|
|
|
if (!network) {
|
2020-11-05 02:53:27 -06:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-01-20 00:59:48 -06:00
|
|
|
const nodes = network.nodes.map((n) => {
|
2020-11-05 02:53:27 -06: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-11-22 00:38:49 -06:00
|
|
|
return (
|
|
|
|
<IconButton
|
|
|
|
onClick={() => showModal()}
|
|
|
|
name="code-branch"
|
|
|
|
title="Show usages"
|
|
|
|
data-testid="VariablesUnknownButton"
|
|
|
|
/>
|
|
|
|
);
|
2020-11-05 02:53:27 -06:00
|
|
|
}}
|
|
|
|
</NetworkGraphModal>
|
|
|
|
);
|
|
|
|
};
|