import React, { PureComponent } from 'react'; import { selectors as e2eSelectors } from '@grafana/e2e-selectors'; import { LegacyForms, ClipboardButton, Icon, InfoBox } from '@grafana/ui'; const { Select, Switch } = LegacyForms; import { SelectableValue, PanelModel, AppEvents } from '@grafana/data'; import { DashboardModel } from 'app/features/dashboard/state'; import { buildImageUrl, buildShareUrl } from './utils'; import { appEvents } from 'app/core/core'; import config from 'app/core/config'; const themeOptions: Array> = [ { label: 'current', value: 'current' }, { label: 'dark', value: 'dark' }, { label: 'light', value: 'light' }, ]; export interface Props { dashboard: DashboardModel; panel?: PanelModel; } export interface State { useCurrentTimeRange: boolean; includeTemplateVars: boolean; selectedTheme: SelectableValue; shareUrl: string; imageUrl: string; } export class ShareLink extends PureComponent { constructor(props: Props) { super(props); this.state = { useCurrentTimeRange: true, includeTemplateVars: true, selectedTheme: themeOptions[0], shareUrl: '', imageUrl: '', }; } componentDidMount() { this.buildUrl(); } componentDidUpdate(prevProps: Props, prevState: State) { const { useCurrentTimeRange, includeTemplateVars, selectedTheme } = this.state; if ( prevState.useCurrentTimeRange !== useCurrentTimeRange || prevState.includeTemplateVars !== includeTemplateVars || prevState.selectedTheme.value !== selectedTheme.value ) { this.buildUrl(); } } buildUrl = () => { const { panel } = this.props; const { useCurrentTimeRange, includeTemplateVars, selectedTheme } = this.state; const shareUrl = buildShareUrl(useCurrentTimeRange, includeTemplateVars, selectedTheme.value, panel); const imageUrl = buildImageUrl(useCurrentTimeRange, includeTemplateVars, selectedTheme.value, panel); this.setState({ shareUrl, imageUrl }); }; onUseCurrentTimeRangeChange = () => { this.setState({ useCurrentTimeRange: !this.state.useCurrentTimeRange }); }; onIncludeTemplateVarsChange = () => { this.setState({ includeTemplateVars: !this.state.includeTemplateVars }); }; onThemeChange = (value: SelectableValue) => { this.setState({ selectedTheme: value }); }; onShareUrlCopy = () => { appEvents.emit(AppEvents.alertSuccess, ['Content copied to clipboard']); }; getShareUrl = () => { return this.state.shareUrl; }; render() { const { panel } = this.props; const { useCurrentTimeRange, includeTemplateVars, selectedTheme, shareUrl, imageUrl } = this.state; const selectors = e2eSelectors.pages.SharePanelModal; return (

Create a direct link to this dashboard or panel, customized with the options below.

Copy
{panel && config.rendererAvailable && ( )} {panel && !config.rendererAvailable && (

<>To render a panel image, you must install the Grafana Image Renderer plugin . Please contact your Grafana administrator to install the plugin.

)}
); } }