The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/public/app/features/dashboard/components/LinksSettings/LinkSettingsEdit.tsx

154 lines
4.4 KiB

import React, { useState } from 'react';
import { SelectableValue } from '@grafana/data';
import { CollapsableSection, TagsInput, Select, Field, Input, Checkbox } 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<LinkSettingsEditProps> = ({ editLinkIdx, dashboard }) => {
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<HTMLInputElement>) => {
const target = ev.currentTarget;
onUpdate({
...linkSettings,
[target.name]: target.type === 'checkbox' ? target.checked : target.value,
});
};
const isNew = linkSettings.title === newLink.title;
return (
<div style={{ maxWidth: '600px' }}>
<Field label="Title">
<Input name="title" id="title" value={linkSettings.title} onChange={onChange} autoFocus={isNew} />
</Field>
<Field label="Type">
<Select
inputId="link-type-input"
value={linkSettings.type}
options={linkTypeOptions}
onChange={onTypeChange}
menuShouldPortal
/>
</Field>
{linkSettings.type === 'dashboards' && (
<>
<Field label="With tags">
<TagsInput tags={linkSettings.tags} placeholder="add tags" onChange={onTagsChange} />
</Field>
</>
)}
{linkSettings.type === 'link' && (
<>
<Field label="URL">
<Input name="url" value={linkSettings.url} onChange={onChange} />
</Field>
<Field label="Tooltip">
<Input name="tooltip" value={linkSettings.tooltip} onChange={onChange} placeholder="Open dashboard" />
</Field>
<Field label="Icon">
Select: Make portalling the menu opt-in, but opt-in *everywhere* (#37501) * Select: Don't portal by default * Select: Portal all the Selects * Fix indendentation in this comment * Select: Remove @example docs until formatting is correct * Docs: Add some documentation for the Select changes * Update docs/sources/whatsnew/whats-new-in-v8-1.md Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> * Update docs/sources/whatsnew/whats-new-in-v8-1.md Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> * Update packages/grafana-ui/src/components/Select/types.ts Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> * Update public/app/core/components/TransformersUI/configFromQuery/ConfigFromQueryTransformerEditor.tsx Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> * Update public/app/core/components/TransformersUI/configFromQuery/ConfigFromQueryTransformerEditor.tsx Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> * Update public/app/core/components/TransformersUI/configFromQuery/ConfigFromQueryTransformerEditor.tsx Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> * Update public/app/core/components/TransformersUI/prepareTimeSeries/PrepareTimeSeriesEditor.tsx Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> * Docs: Variants instead of varients * Update public/app/core/components/TransformersUI/configFromQuery/ConfigFromQueryTransformerEditor.tsx Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com> Co-authored-by: Ursula Kallio <73951760+osg-grafana@users.noreply.github.com>
4 years ago
<Select menuShouldPortal value={linkSettings.icon} options={linkIconOptions} onChange={onIconChange} />
</Field>
</>
)}
<CollapsableSection label="Options" isOpen={true}>
{linkSettings.type === 'dashboards' && (
<Field>
<Checkbox label="Show as dropdown" name="asDropdown" value={linkSettings.asDropdown} onChange={onChange} />
</Field>
)}
<Field>
<Checkbox
label="Include current time range"
name="keepTime"
value={linkSettings.keepTime}
onChange={onChange}
/>
</Field>
<Field>
<Checkbox
label="Include current template variable values"
name="includeVars"
value={linkSettings.includeVars}
onChange={onChange}
/>
</Field>
<Field>
<Checkbox
label="Open link in new tab"
name="targetBlank"
value={linkSettings.targetBlank}
onChange={onChange}
/>
</Field>
</CollapsableSection>
</div>
);
};