|
| 1 | +import React, { useState } from 'react'; |
| 2 | +import { i18n } from '@osd/i18n'; |
| 3 | +import { FormattedMessage, I18nProvider } from '@osd/i18n/react'; |
| 4 | +import { BrowserRouter as Router } from 'react-router-dom'; |
| 5 | + |
| 6 | +import { |
| 7 | + EuiButton, |
| 8 | + EuiHorizontalRule, |
| 9 | + EuiPage, |
| 10 | + EuiPageBody, |
| 11 | + EuiPageContent, |
| 12 | + EuiPageContentBody, |
| 13 | + EuiPageContentHeader, |
| 14 | + EuiPageHeader, |
| 15 | + EuiTitle, |
| 16 | + EuiText, |
| 17 | +} from '@elastic/eui'; |
| 18 | + |
| 19 | +import { CoreStart } from '../../../../core/public'; |
| 20 | +import { NavigationPublicPluginStart } from '../../../navigation/public'; |
| 21 | + |
| 22 | +import { PLUGIN_ID, PLUGIN_NAME } from '../../common'; |
| 23 | + |
| 24 | +interface GoogleAnalyticAppDeps { |
| 25 | + basename: string; |
| 26 | + notifications: CoreStart['notifications']; |
| 27 | + http: CoreStart['http']; |
| 28 | + navigation: NavigationPublicPluginStart; |
| 29 | +} |
| 30 | + |
| 31 | +export const GoogleAnalyticApp = ({ |
| 32 | + basename, |
| 33 | + notifications, |
| 34 | + http, |
| 35 | + navigation, |
| 36 | +}: GoogleAnalyticAppDeps) => { |
| 37 | + // Use React hooks to manage state. |
| 38 | + const [timestamp, setTimestamp] = useState<string | undefined>(); |
| 39 | + |
| 40 | + const onClickHandler = () => { |
| 41 | + setTimestamp(new Date().toISOString()); |
| 42 | + notifications.toasts.addSuccess(PLUGIN_NAME); |
| 43 | + }; |
| 44 | + |
| 45 | + // Render the application DOM. |
| 46 | + // Note that `navigation.ui.TopNavMenu` is a stateful component exported on the `navigation` plugin's start contract. |
| 47 | + return ( |
| 48 | + <Router basename={basename}> |
| 49 | + <I18nProvider> |
| 50 | + <> |
| 51 | + <navigation.ui.TopNavMenu |
| 52 | + appName={PLUGIN_ID} |
| 53 | + showSearchBar={true} |
| 54 | + useDefaultBehaviors={true} |
| 55 | + /> |
| 56 | + <EuiPage restrictWidth="1000px"> |
| 57 | + <EuiPageBody component="main"> |
| 58 | + <EuiPageHeader> |
| 59 | + <EuiTitle size="l"> |
| 60 | + <h1> |
| 61 | + <FormattedMessage |
| 62 | + id="googleAnalytic.helloWorldText" |
| 63 | + defaultMessage="{name}" |
| 64 | + values={{ name: PLUGIN_NAME }} |
| 65 | + /> |
| 66 | + </h1> |
| 67 | + </EuiTitle> |
| 68 | + </EuiPageHeader> |
| 69 | + <EuiPageContent> |
| 70 | + <EuiPageContentHeader> |
| 71 | + <EuiTitle> |
| 72 | + <h2> |
| 73 | + <FormattedMessage |
| 74 | + id="googleAnalytic.congratulationsTitle" |
| 75 | + defaultMessage="Congratulations, you have successfully created a new OpenSearch Dashboards Plugin!" |
| 76 | + /> |
| 77 | + </h2> |
| 78 | + </EuiTitle> |
| 79 | + </EuiPageContentHeader> |
| 80 | + <EuiPageContentBody> |
| 81 | + <EuiText> |
| 82 | + <p> |
| 83 | + <FormattedMessage |
| 84 | + id="googleAnalytic.content" |
| 85 | + defaultMessage="Look through the generated code and check out the plugin development documentation." |
| 86 | + /> |
| 87 | + </p> |
| 88 | + <EuiHorizontalRule /> |
| 89 | + <p> |
| 90 | + <FormattedMessage |
| 91 | + id="googleAnalytic.timestampText" |
| 92 | + defaultMessage="Last timestamp: {time}" |
| 93 | + values={{ time: timestamp ? timestamp : 'Unknown' }} |
| 94 | + /> |
| 95 | + </p> |
| 96 | + <EuiButton type="primary" size="s" onClick={onClickHandler}> |
| 97 | + <FormattedMessage id="googleAnalytic.buttonText" defaultMessage="Click me" /> |
| 98 | + </EuiButton> |
| 99 | + </EuiText> |
| 100 | + </EuiPageContentBody> |
| 101 | + </EuiPageContent> |
| 102 | + </EuiPageBody> |
| 103 | + </EuiPage> |
| 104 | + </> |
| 105 | + </I18nProvider> |
| 106 | + </Router> |
| 107 | + ); |
| 108 | +}; |
0 commit comments