|
| 1 | +import { |
| 2 | + EuiCard, |
| 3 | + EuiCode, |
| 4 | + EuiFlexGroup, |
| 5 | + EuiFlexItem, |
| 6 | + EuiHorizontalRule, |
| 7 | + EuiIcon, |
| 8 | + EuiPage, |
| 9 | + EuiPageBody, |
| 10 | + EuiPageContent, |
| 11 | + EuiPageContentBody, |
| 12 | + EuiPageHeader, |
| 13 | + EuiPanel, |
| 14 | + EuiText, |
| 15 | + EuiTitle, |
| 16 | +} from '@elastic/eui'; |
| 17 | +import { I18nProvider } from '@kbn/i18n/react'; |
| 18 | +import React, { useEffect, useState } from 'react'; |
| 19 | +import { BrowserRouter as Router } from 'react-router-dom'; |
| 20 | +import * as Rx from 'rxjs'; |
| 21 | +import { takeWhile } from 'rxjs/operators'; |
| 22 | +import { CoreStart } from '../../../../../src/core/public'; |
| 23 | +import { NavigationPublicPluginStart } from '../../../../../src/plugins/navigation/public'; |
| 24 | +import { constants, ReportingStart } from '../../../../../x-pack/plugins/reporting/public'; |
| 25 | +import { JobParamsPDF } from '../../../../plugins/reporting/server/export_types/printable_pdf/types'; |
| 26 | + |
| 27 | +interface ReportingExampleAppDeps { |
| 28 | + basename: string; |
| 29 | + notifications: CoreStart['notifications']; |
| 30 | + http: CoreStart['http']; |
| 31 | + navigation: NavigationPublicPluginStart; |
| 32 | + reporting: ReportingStart; |
| 33 | +} |
| 34 | + |
| 35 | +const sourceLogos = ['Beats', 'Cloud', 'Logging', 'Kibana']; |
| 36 | + |
| 37 | +export const ReportingExampleApp = ({ |
| 38 | + basename, |
| 39 | + notifications, |
| 40 | + http, |
| 41 | + reporting, |
| 42 | +}: ReportingExampleAppDeps) => { |
| 43 | + const { getDefaultLayoutSelectors, ReportingAPIClient } = reporting; |
| 44 | + const [logos, setLogos] = useState<string[]>([]); |
| 45 | + |
| 46 | + useEffect(() => { |
| 47 | + Rx.timer(2200) |
| 48 | + .pipe(takeWhile(() => logos.length < sourceLogos.length)) |
| 49 | + .subscribe(() => { |
| 50 | + setLogos([...sourceLogos.slice(0, logos.length + 1)]); |
| 51 | + }); |
| 52 | + }); |
| 53 | + |
| 54 | + const getPDFJobParams = (): JobParamsPDF => { |
| 55 | + return { |
| 56 | + layout: { |
| 57 | + id: constants.LAYOUT_TYPES.PRESERVE_LAYOUT, |
| 58 | + selectors: getDefaultLayoutSelectors(), |
| 59 | + }, |
| 60 | + relativeUrls: ['/app/reportingExample#/intended-visualization'], |
| 61 | + objectType: 'develeloperExample', |
| 62 | + title: 'Reporting Developer Example', |
| 63 | + }; |
| 64 | + }; |
| 65 | + |
| 66 | + // Render the application DOM. |
| 67 | + return ( |
| 68 | + <Router basename={basename}> |
| 69 | + <I18nProvider> |
| 70 | + <EuiPage> |
| 71 | + <EuiPageBody> |
| 72 | + <EuiPageHeader> |
| 73 | + <EuiTitle size="l"> |
| 74 | + <h1>Reporting Example</h1> |
| 75 | + </EuiTitle> |
| 76 | + </EuiPageHeader> |
| 77 | + <EuiPageContent> |
| 78 | + <EuiPageContentBody> |
| 79 | + <EuiText> |
| 80 | + <p> |
| 81 | + Use the <EuiCode>ReportingStart.components.ScreenCapturePanel</EuiCode>{' '} |
| 82 | + component to add the Reporting panel to your page. |
| 83 | + </p> |
| 84 | + |
| 85 | + <EuiHorizontalRule /> |
| 86 | + |
| 87 | + <EuiFlexGroup> |
| 88 | + <EuiFlexItem grow={false}> |
| 89 | + <EuiPanel> |
| 90 | + <reporting.components.ScreenCapturePanel |
| 91 | + apiClient={new ReportingAPIClient(http)} |
| 92 | + toasts={notifications.toasts} |
| 93 | + reportType={constants.PDF_REPORT_TYPE} |
| 94 | + getJobParams={getPDFJobParams} |
| 95 | + objectId="Visualization:Id:ToEnsure:Visualization:IsSaved" |
| 96 | + /> |
| 97 | + </EuiPanel> |
| 98 | + </EuiFlexItem> |
| 99 | + </EuiFlexGroup> |
| 100 | + |
| 101 | + <EuiHorizontalRule /> |
| 102 | + |
| 103 | + <p> |
| 104 | + The logos below are in a <EuiCode>data-shared-items-container</EuiCode> element |
| 105 | + for Reporting. |
| 106 | + </p> |
| 107 | + |
| 108 | + <div data-shared-items-container data-shared-items-count="4"> |
| 109 | + <EuiFlexGroup gutterSize="l"> |
| 110 | + {logos.map((item, index) => ( |
| 111 | + <EuiFlexItem key={index} data-shared-item> |
| 112 | + <EuiCard |
| 113 | + icon={<EuiIcon size="xxl" type={`logo${item}`} />} |
| 114 | + title={`Elastic ${item}`} |
| 115 | + description="Example of a card's description. Stick to one or two sentences." |
| 116 | + onClick={() => {}} |
| 117 | + /> |
| 118 | + </EuiFlexItem> |
| 119 | + ))} |
| 120 | + </EuiFlexGroup> |
| 121 | + </div> |
| 122 | + </EuiText> |
| 123 | + </EuiPageContentBody> |
| 124 | + </EuiPageContent> |
| 125 | + </EuiPageBody> |
| 126 | + </EuiPage> |
| 127 | + </I18nProvider> |
| 128 | + </Router> |
| 129 | + ); |
| 130 | +}; |
0 commit comments