import React, { useState } from 'react'; import { css } from 'emotion'; import { CollapsableSection, Button, TagsInput, Select, Field, Input, Checkbox } from '@grafana/ui'; import { SelectableValue } from '@grafana/data'; import { LinkSettingsMode } from '../DashboardSettings/LinksSettings'; import { DashboardLink, DashboardModel } from '../../state/DashboardModel'; const newLink = { icon: 'external link', title: '', 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 = { mode: LinkSettingsMode; editLinkIdx: number | null; dashboard: DashboardModel; backToList: () => void; }; export const LinkSettingsEdit: React.FC = ({ mode, editLinkIdx, dashboard, backToList }) => { const [linkSettings, setLinkSettings] = useState(editLinkIdx !== null ? dashboard.links[editLinkIdx] : newLink); const onTagsChange = (tags: any[]) => { setLinkSettings((link) => ({ ...link, tags: tags })); }; const onTypeChange = (selectedItem: SelectableValue) => { setLinkSettings((link) => ({ ...link, type: selectedItem.value })); }; const onIconChange = (selectedItem: SelectableValue) => { setLinkSettings((link) => ({ ...link, icon: selectedItem.value })); }; const onChange = (ev: React.FocusEvent) => { const target = ev.currentTarget; setLinkSettings((link) => ({ ...link, [target.name]: target.type === 'checkbox' ? target.checked : target.value, })); }; const addLink = () => { dashboard.links = [...dashboard.links, linkSettings]; dashboard.updateSubmenuVisibility(); backToList(); }; const updateLink = () => { dashboard.links.splice(editLinkIdx!, 1, linkSettings); dashboard.updateSubmenuVisibility(); backToList(); }; return (
{linkSettings.type === 'dashboards' && ( <> )} {linkSettings.type === 'link' && ( <>