grafana/public/app/features/variables/inspect/VariablesUnknownButton.tsx
Laura Benz 24502c4c4a
Add tooltip to instances of IconButton (#68880)
* 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
2023-06-08 10:23:28 +02:00

42 lines
1003 B
TypeScript

import React, { useMemo } from 'react';
import { IconButton } from '@grafana/ui';
import { NetworkGraphModal } from './NetworkGraphModal';
import { UsagesToNetwork } from './utils';
interface Props {
id: string;
usages: UsagesToNetwork[];
}
export const VariablesUnknownButton = ({ id, usages }: Props) => {
const network = useMemo(() => usages.find((n) => n.variable.id === id), [id, usages]);
if (!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={() => showModal()}
name="code-branch"
tooltip="Show usages"
data-testid="VariablesUnknownButton"
/>
);
}}
</NetworkGraphModal>
);
};