import React, { useState } from 'react'; import { arrayUtils } from '@grafana/data'; import { DeleteButton, HorizontalGroup, Icon, IconButton, TagList } from '@grafana/ui'; import EmptyListCTA from 'app/core/components/EmptyListCTA/EmptyListCTA'; import { DashboardModel, DashboardLink } from '../../state/DashboardModel'; import { ListNewButton } from '../DashboardSettings/ListNewButton'; type LinkSettingsListProps = { dashboard: DashboardModel; onNew: () => void; onEdit: (idx: number) => void; }; export const LinkSettingsList: React.FC = ({ dashboard, onNew, onEdit }) => { const [links, setLinks] = useState(dashboard.links); const moveLink = (idx: number, direction: number) => { dashboard.links = arrayUtils.moveItemImmutably(links, idx, idx + direction); setLinks(dashboard.links); }; const duplicateLink = (link: DashboardLink, idx: number) => { dashboard.links = [...links, { ...link }]; setLinks(dashboard.links); }; const deleteLink = (idx: number) => { dashboard.links = [...links.slice(0, idx), ...links.slice(idx + 1)]; setLinks(dashboard.links); }; const isEmptyList = dashboard.links.length === 0; if (isEmptyList) { return (
Dashboard Links allow you to place links to other dashboards and web sites directly below the dashboard header.

', }} />
); } return ( <> {links.map((link, idx) => ( ))}
Type Info
onEdit(idx)}>   {link.type} {link.title && {link.title}} {link.type === 'link' && {link.url}} {link.type === 'dashboards' && } {idx !== 0 && moveLink(idx, -1)} />} {links.length > 1 && idx !== links.length - 1 ? ( moveLink(idx, 1)} /> ) : null} duplicateLink(link, idx)} /> deleteLink(idx)} />
New link ); };