2023-11-15 16:49:51 +01:00
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
|
|
import { sanitizeUrl } from '@grafana/data/src/text/sanitize';
|
|
|
|
|
import { selectors } from '@grafana/e2e-selectors';
|
|
|
|
|
import { DashboardLink } from '@grafana/schema';
|
|
|
|
|
import { Tooltip } from '@grafana/ui';
|
|
|
|
|
import {
|
|
|
|
|
DashboardLinkButton,
|
|
|
|
|
DashboardLinksDashboard,
|
|
|
|
|
} from 'app/features/dashboard/components/SubMenu/DashboardLinksDashboard';
|
|
|
|
|
import { getLinkSrv } from 'app/features/panel/panellinks/link_srv';
|
|
|
|
|
|
2024-01-16 12:24:54 +01:00
|
|
|
import { LINK_ICON_MAP } from '../settings/links/utils';
|
2023-11-29 15:01:40 +01:00
|
|
|
|
2024-02-20 08:43:02 +01:00
|
|
|
export interface Props {
|
|
|
|
|
links: DashboardLink[];
|
|
|
|
|
uid?: string;
|
2023-11-15 16:49:51 +01:00
|
|
|
}
|
|
|
|
|
|
2024-02-20 08:43:02 +01:00
|
|
|
export function DashboardLinksControls({ links, uid }: Props) {
|
2023-11-29 15:01:40 +01:00
|
|
|
if (!links || !uid) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-15 16:49:51 +01:00
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
{links.map((link: DashboardLink, index: number) => {
|
|
|
|
|
const linkInfo = getLinkSrv().getAnchorInfo(link);
|
|
|
|
|
const key = `${link.title}-$${index}`;
|
|
|
|
|
|
|
|
|
|
if (link.type === 'dashboards') {
|
2023-11-29 15:01:40 +01:00
|
|
|
return <DashboardLinksDashboard key={key} link={link} linkInfo={linkInfo} dashboardUID={uid} />;
|
2023-11-15 16:49:51 +01:00
|
|
|
}
|
|
|
|
|
|
2024-01-16 12:24:54 +01:00
|
|
|
const icon = LINK_ICON_MAP[link.icon];
|
2023-11-15 16:49:51 +01:00
|
|
|
|
|
|
|
|
const linkElement = (
|
|
|
|
|
<DashboardLinkButton
|
|
|
|
|
icon={icon}
|
|
|
|
|
href={sanitizeUrl(linkInfo.href)}
|
|
|
|
|
target={link.targetBlank ? '_blank' : undefined}
|
|
|
|
|
rel="noreferrer"
|
|
|
|
|
data-testid={selectors.components.DashboardLinks.link}
|
|
|
|
|
>
|
|
|
|
|
{linkInfo.title}
|
|
|
|
|
</DashboardLinkButton>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div key={key} data-testid={selectors.components.DashboardLinks.container}>
|
|
|
|
|
{link.tooltip ? <Tooltip content={linkInfo.tooltip}>{linkElement}</Tooltip> : linkElement}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|