mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 00:41:50 +08:00

* refactor(frontend): rename all @grafana/data/src imports to @grafana/data * feat(grafana-data): introduce internal entrypoint for sharing code only with grafana * feat(grafana-data): add test entrypoint for data test utils usage in core * refactor(frontend): update import paths to use grafana/data exports entrypoints * docs(grafana-data): update comment in internal/index.ts * refactor(frontend): prefer public namespaced exports over re-exporting via internal * chore(frontend): fix a couple more weird paths that typescript complains about
65 lines
2.0 KiB
TypeScript
65 lines
2.0 KiB
TypeScript
import { useEffectOnce } from 'react-use';
|
|
|
|
import { sanitizeUrl } from '@grafana/data/internal';
|
|
import { selectors } from '@grafana/e2e-selectors';
|
|
import { TimeRangeUpdatedEvent } from '@grafana/runtime';
|
|
import { DashboardLink } from '@grafana/schema';
|
|
import { Tooltip, useForceUpdate } from '@grafana/ui';
|
|
import { LINK_ICON_MAP } from 'app/features/dashboard-scene/settings/links/utils';
|
|
|
|
import { getLinkSrv } from '../../../panel/panellinks/link_srv';
|
|
import { DashboardModel } from '../../state/DashboardModel';
|
|
|
|
import { DashboardLinkButton, DashboardLinksDashboard } from './DashboardLinksDashboard';
|
|
|
|
export interface Props {
|
|
dashboard: DashboardModel;
|
|
links: DashboardLink[];
|
|
}
|
|
|
|
export const DashboardLinks = ({ dashboard, links }: Props) => {
|
|
const forceUpdate = useForceUpdate();
|
|
|
|
useEffectOnce(() => {
|
|
const sub = dashboard.events.subscribe(TimeRangeUpdatedEvent, forceUpdate);
|
|
return () => sub.unsubscribe();
|
|
});
|
|
|
|
if (!links.length) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<>
|
|
{links.map((link: DashboardLink, index: number) => {
|
|
const linkInfo = getLinkSrv().getAnchorInfo(link);
|
|
const key = `${link.title}-$${index}`;
|
|
|
|
if (link.type === 'dashboards') {
|
|
return <DashboardLinksDashboard key={key} link={link} linkInfo={linkInfo} dashboardUID={dashboard.uid} />;
|
|
}
|
|
|
|
const icon = LINK_ICON_MAP[link.icon];
|
|
|
|
const linkElement = (
|
|
<DashboardLinkButton
|
|
href={sanitizeUrl(linkInfo.href)}
|
|
target={link.targetBlank ? '_blank' : undefined}
|
|
rel="noreferrer"
|
|
data-testid={selectors.components.DashboardLinks.link}
|
|
icon={icon}
|
|
>
|
|
{linkInfo.title}
|
|
</DashboardLinkButton>
|
|
);
|
|
|
|
return (
|
|
<div key={key} data-testid={selectors.components.DashboardLinks.container}>
|
|
{link.tooltip ? <Tooltip content={linkInfo.tooltip}>{linkElement}</Tooltip> : linkElement}
|
|
</div>
|
|
);
|
|
})}
|
|
</>
|
|
);
|
|
};
|