import * as React from 'react'; import { SelectableValue } from '@grafana/data'; import { DashboardLink } from '@grafana/schema'; import { CollapsableSection, TagsInput, Select, Field, Input, Checkbox, Button } from '@grafana/ui'; import { LINK_ICON_MAP, NEW_LINK } from './utils'; const linkTypeOptions = [ { value: 'dashboards', label: 'Dashboards' }, { value: 'link', label: 'Link' }, ]; const linkIconOptions = Object.keys(LINK_ICON_MAP).map((key) => ({ label: key, value: key })); interface DashboardLinkFormProps { link: DashboardLink; onUpdate: (link: DashboardLink) => void; onGoBack: () => void; } export function DashboardLinkForm({ link, onUpdate, onGoBack }: DashboardLinkFormProps) { const onTagsChange = (tags: string[]) => { onUpdate({ ...link, tags: tags }); }; const onTypeChange = (selectedItem: SelectableValue) => { const update = { ...link, 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({ ...link, icon: selectedItem.value }); }; const onChange = (ev: React.FocusEvent) => { const target = ev.currentTarget; onUpdate({ ...link, [target.name]: target.type === 'checkbox' ? target.checked : target.value, }); }; const isNew = link.title === NEW_LINK.title; return (