import React, { useState } from 'react'; import { SelectableValue } from '@grafana/data'; import { CollapsableSection, TagsInput, Select, Field, Input, Checkbox, Button } from '@grafana/ui'; import { DashboardLink, DashboardModel } from '../../state/DashboardModel'; export const newLink = { icon: 'external link', title: 'New link', tooltip: '', type: 'dashboards', url: '', asDropdown: false, tags: [], targetBlank: false, keepTime: false, includeVars: false, } as DashboardLink; const linkTypeOptions = [ { value: 'dashboards', label: 'Dashboards' }, { value: 'link', label: 'Link' }, ]; export const linkIconMap: { [key: string]: string } = { 'external link': 'external-link-alt', dashboard: 'apps', question: 'question-circle', info: 'info-circle', bolt: 'bolt', doc: 'file-alt', cloud: 'cloud', }; const linkIconOptions = Object.keys(linkIconMap).map((key) => ({ label: key, value: key })); type LinkSettingsEditProps = { editLinkIdx: number; dashboard: DashboardModel; onGoBack: () => void; }; export const LinkSettingsEdit: React.FC = ({ editLinkIdx, dashboard, onGoBack }) => { const [linkSettings, setLinkSettings] = useState(editLinkIdx !== null ? dashboard.links[editLinkIdx] : newLink); const onUpdate = (link: DashboardLink) => { const links = [...dashboard.links]; links.splice(editLinkIdx, 1, link); dashboard.links = links; setLinkSettings(link); }; const onTagsChange = (tags: any[]) => { onUpdate({ ...linkSettings, tags: tags }); }; const onTypeChange = (selectedItem: SelectableValue) => { const update = { ...linkSettings, type: selectedItem.value }; // clear props that are no longe revant for this type if (update.type === 'dashboards') { update.url = ''; update.tooltip = ''; } else { update.tags = []; } onUpdate(update); }; const onIconChange = (selectedItem: SelectableValue) => { onUpdate({ ...linkSettings, icon: selectedItem.value }); }; const onChange = (ev: React.FocusEvent) => { const target = ev.currentTarget; onUpdate({ ...linkSettings, [target.name]: target.type === 'checkbox' ? target.checked : target.value, }); }; const isNew = linkSettings.title === newLink.title; return (