import React, { FormEvent, PureComponent } from 'react'; import { AppEvents, SelectableValue } from '@grafana/data'; import { ClipboardButton, Field, Modal, RadioButtonGroup, Switch, TextArea } from '@grafana/ui'; import { appEvents } from 'app/core/core'; import { ShareModalTabProps } from './types'; import { buildIframeHtml } from './utils'; const themeOptions: Array> = [ { label: 'Current', value: 'current' }, { label: 'Dark', value: 'dark' }, { label: 'Light', value: 'light' }, ]; interface Props extends ShareModalTabProps {} interface State { useCurrentTimeRange: boolean; selectedTheme: string; iframeHtml: string; } export class ShareEmbed extends PureComponent { constructor(props: Props) { super(props); this.state = { useCurrentTimeRange: true, selectedTheme: 'current', iframeHtml: '', }; } componentDidMount() { this.buildIframeHtml(); } buildIframeHtml = () => { const { panel, dashboard } = this.props; const { useCurrentTimeRange, selectedTheme } = this.state; const iframeHtml = buildIframeHtml(useCurrentTimeRange, dashboard.uid, selectedTheme, panel); this.setState({ iframeHtml }); }; onIframeHtmlChange = (event: FormEvent) => { this.setState({ iframeHtml: event.currentTarget.value }); }; onUseCurrentTimeRangeChange = () => { this.setState( { useCurrentTimeRange: !this.state.useCurrentTimeRange, }, this.buildIframeHtml ); }; onThemeChange = (value: string) => { this.setState({ selectedTheme: value }, this.buildIframeHtml); }; onIframeHtmlCopy = () => { appEvents.emit(AppEvents.alertSuccess, ['Content copied to clipboard']); }; getIframeHtml = () => { return this.state.iframeHtml; }; render() { const { useCurrentTimeRange, selectedTheme, iframeHtml } = this.state; const isRelativeTime = this.props.dashboard ? this.props.dashboard.time.to === 'now' : false; return ( <>

Generate HTML for embedding an iframe with this panel.