mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 10:40:07 -04:00
## Summary Fix https://github.com/elastic/kibana/issues/161424 Migrate away from deprecated EUI components for Core-owned code. Note: I only tested the production (and examples) pages properly, I didn't make sure the test plugins where displayed correctly, as long as the data structure was still here for the tests to pass. ### Screenshots #### Status page <img width="1388" alt="Screenshot 2023-07-10 at 17 14 24" src="d15adffa
-d4fb-4dab-ad91-691a4c103541"> #### AppNotFound page <img width="1352" alt="Screenshot 2023-07-10 at 17 14 40" src="77dcc958
-db53-4ec8-9a7f-af4ea0804a96"> #### Generated plugin landing page <img width="1906" alt="Screenshot 2023-07-10 at 17 15 44" src="7a45d1a3
-181d-44c5-a4a1-d3bdb2ba6ee9"> --------- Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
100 lines
3.7 KiB
Text
100 lines
3.7 KiB
Text
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<string | undefined>();
|
|
|
|
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 (
|
|
<Router basename={basename}>
|
|
<I18nProvider>
|
|
<>
|
|
<navigation.ui.TopNavMenu appName={ PLUGIN_ID } showSearchBar={true} useDefaultBehaviors={true}/>
|
|
<EuiPageTemplate restrictWidth="1000px">
|
|
<EuiPageTemplate.Header>
|
|
<EuiTitle size="l">
|
|
<h1>
|
|
<FormattedMessage
|
|
id="<%= camelCase(name) %>.helloWorldText"
|
|
defaultMessage="{name}"
|
|
values={{ name: PLUGIN_NAME }}
|
|
/>
|
|
</h1>
|
|
</EuiTitle>
|
|
</EuiPageTemplate.Header>
|
|
<EuiPageTemplate.Section>
|
|
<EuiTitle>
|
|
<h2>
|
|
<FormattedMessage
|
|
id="<%= camelCase(name) %>.congratulationsTitle"
|
|
defaultMessage="Congratulations, you have successfully created a new Kibana Plugin!"
|
|
/>
|
|
</h2>
|
|
</EuiTitle>
|
|
<EuiText>
|
|
<p>
|
|
<FormattedMessage
|
|
id="<%= camelCase(name) %>.content"
|
|
defaultMessage="Look through the generated code and check out the plugin development documentation."
|
|
/>
|
|
</p>
|
|
<EuiHorizontalRule/>
|
|
<p>
|
|
<FormattedMessage
|
|
id="<%= camelCase(name) %>.timestampText"
|
|
defaultMessage="Last timestamp: {time}"
|
|
values={{ time: timestamp ? timestamp : 'Unknown' }}
|
|
/>
|
|
</p>
|
|
<EuiButton type="primary" size="s" onClick={onClickHandler}>
|
|
<FormattedMessage
|
|
id="<%= camelCase(name) %>.buttonText"
|
|
defaultMessage="<%= hasServer ? 'Get data' : 'Click me' %>"
|
|
/>
|
|
</EuiButton>
|
|
</EuiText>
|
|
</EuiPageTemplate.Section>
|
|
</EuiPageTemplate>
|
|
</>
|
|
</I18nProvider>
|
|
</Router>
|
|
);
|
|
};
|