import React, { useState } from 'react'; import { urlUtil } from '@grafana/data'; import { config, featureEnabled } from '@grafana/runtime'; import { ModalTabContent, Button, LinkButton, RadioButtonGroup, Field, Switch, Modal } from '@grafana/ui'; import { ShareModalTabProps } from 'app/features/dashboard/components/ShareModal'; import { getVariablesByKey } from 'app/features/variables/state/selectors'; import { ReportOrientation, ReportLayout, reportOrientations, reportLayouts } from '../types'; import { getRootPath } from '../utils/url'; import { NoRendererInfoBox } from './RenderingWarnings'; import { UnavailableFeatureInfoBox } from './UnavailableFeatureInfoBox'; import { collectVariables, variablesToCsv } from './utils/variables'; export const SharePDF = ({ dashboard, onDismiss }: ShareModalTabProps) => { const [orientation, setOrientation] = useState('landscape'); const [layout, setLayout] = useState('grid'); const [useSelectedVariables, setUseSelectedVariables] = useState(false); const buildPdfLink = () => { let pdfUrl = `${getRootPath()}/api/reports/render/pdf/${dashboard.id}`; const params: Record = { orientation, layout }; if (useSelectedVariables) { const variables = collectVariables(); params.variables = JSON.stringify(variables); } else { const variables = getVariablesByKey(dashboard.uid); if (variables.length) { params.variables = JSON.stringify(variablesToCsv(variables)); } } pdfUrl = urlUtil.appendQueryToUrl(pdfUrl, urlUtil.toUrlParams(params)); return pdfUrl; }; const onOrientationChange = (orientation: ReportOrientation) => { setOrientation(orientation); }; const onLayoutChange = (layout: ReportLayout) => { setLayout(layout); }; if (!config.rendererAvailable) { return ; } if (!featureEnabled('reports.pdf')) { return ( ); } if (dashboard.isSnapshot()) { return

Sharing a PDF from a snapshot is not supported.

; } return (

Save the dashboard as a PDF document.

{!!Object.keys(collectVariables()).length && ( setUseSelectedVariables(!useSelectedVariables)} value={useSelectedVariables} /> )} Save as PDF
); };