import React, { useState } from 'react'; import { i18n } from '@kbn/i18n'; import { FormattedMessage, I18nProvider } from '@kbn/i18n-react'; import { BrowserRouter as Router } from '@kbn/shared-ux-router'; import { EuiButton, EuiHorizontalRule, EuiPageTemplate, EuiTitle, EuiText, } from '@elastic/eui'; import type { CoreStart } from '@kbn/core/public'; import type { NavigationPublicPluginStart } from '@kbn/navigation-plugin/public'; import { PLUGIN_ID, PLUGIN_NAME } from '../../common'; interface <%= upperCamelCase(name) %>AppDeps { basename: string; notifications: CoreStart['notifications']; http: CoreStart['http']; navigation: NavigationPublicPluginStart; } export const <%= upperCamelCase(name) %>App = ({ basename, notifications, http, navigation }: <%= upperCamelCase(name) %>AppDeps) => { // Use React hooks to manage state. const [timestamp, setTimestamp] = useState(); const onClickHandler = () => { <% if (hasServer) { %> // Use the core http service to make a response to the server API. http.get('/api/<%= snakeCase(name) %>/example').then(res => { setTimestamp(res.time); // Use the core notifications service to display a success message. notifications.toasts.addSuccess(i18n.translate('<%= camelCase(name) %>.dataUpdated', { defaultMessage: 'Data updated', })); }); <% } else { %> setTimestamp(new Date().toISOString()); notifications.toasts.addSuccess(PLUGIN_NAME); <% } %> }; // Render the application DOM. // Note that `navigation.ui.TopNavMenu` is a stateful component exported on the `navigation` plugin's start contract. return ( <>

); };