mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 10:40:07 -04:00
[ML] Response Stream developer example: Migrate deprecated EUI components. (#162454)
Migrates deprecated EUI components for the response stream developer example plugin. Adds a breadcrumb to the example to be able to navigate back to the overview page.
This commit is contained in:
parent
f8a16009f9
commit
c2219ba189
7 changed files with 52 additions and 35 deletions
10
examples/response_stream/common/constants.ts
Normal file
10
examples/response_stream/common/constants.ts
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
/*
|
||||||
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||||
|
* or more contributor license agreements. Licensed under the Elastic License
|
||||||
|
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||||
|
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||||
|
* Side Public License, v 1.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export const PLUGIN_ID = 'response-stream';
|
||||||
|
export const PLUGIN_NAME = 'response stream';
|
|
@ -8,14 +8,7 @@
|
||||||
|
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
|
||||||
import {
|
import { EuiPageTemplate, EuiTitle } from '@elastic/eui';
|
||||||
EuiPageBody,
|
|
||||||
EuiPageContent_Deprecated as EuiPageContent,
|
|
||||||
EuiPageContentBody_Deprecated as EuiPageContentBody,
|
|
||||||
EuiPageHeader,
|
|
||||||
EuiPageHeaderSection,
|
|
||||||
EuiTitle,
|
|
||||||
} from '@elastic/eui';
|
|
||||||
|
|
||||||
export interface PageProps {
|
export interface PageProps {
|
||||||
title?: React.ReactNode;
|
title?: React.ReactNode;
|
||||||
|
@ -23,19 +16,13 @@ export interface PageProps {
|
||||||
|
|
||||||
export const Page: React.FC<PageProps> = ({ title = 'Untitled', children }) => {
|
export const Page: React.FC<PageProps> = ({ title = 'Untitled', children }) => {
|
||||||
return (
|
return (
|
||||||
<EuiPageBody>
|
<>
|
||||||
<EuiPageHeader>
|
<EuiPageTemplate.Header>
|
||||||
<EuiPageHeaderSection>
|
<EuiTitle size="l">
|
||||||
<EuiTitle size="l">
|
<h1>{title}</h1>
|
||||||
<h1>{title}</h1>
|
</EuiTitle>
|
||||||
</EuiTitle>
|
</EuiPageTemplate.Header>
|
||||||
</EuiPageHeaderSection>
|
<EuiPageTemplate.Section>{children}</EuiPageTemplate.Section>
|
||||||
</EuiPageHeader>
|
</>
|
||||||
<EuiPageContent>
|
|
||||||
<EuiPageContentBody style={{ maxWidth: 800, margin: '0 auto' }}>
|
|
||||||
{children}
|
|
||||||
</EuiPageContentBody>
|
|
||||||
</EuiPageContent>
|
|
||||||
</EuiPageBody>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Redirect } from 'react-router-dom';
|
import { Redirect } from 'react-router-dom';
|
||||||
import { BrowserRouter as Router, Routes, Route } from '@kbn/shared-ux-router';
|
import { BrowserRouter as Router, Routes, Route } from '@kbn/shared-ux-router';
|
||||||
import { EuiPage } from '@elastic/eui';
|
import { EuiPageTemplate } from '@elastic/eui';
|
||||||
import { useDeps } from '../../hooks/use_deps';
|
import { useDeps } from '../../hooks/use_deps';
|
||||||
import { Sidebar } from './sidebar';
|
import { Sidebar } from './sidebar';
|
||||||
import { routes } from '../../routes';
|
import { routes } from '../../routes';
|
||||||
|
@ -26,13 +26,15 @@ export const App: React.FC = () => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Router basename={appBasePath}>
|
<Router basename={appBasePath}>
|
||||||
<EuiPage>
|
<EuiPageTemplate restrictWidth={true} offset={0}>
|
||||||
<Sidebar />
|
<EuiPageTemplate.Sidebar sticky={true}>
|
||||||
|
<Sidebar />
|
||||||
|
</EuiPageTemplate.Sidebar>
|
||||||
<Routes>
|
<Routes>
|
||||||
{routeElements}
|
{routeElements}
|
||||||
<Redirect to="/simple-string-stream" />
|
<Redirect to="/simple-string-stream" />
|
||||||
</Routes>
|
</Routes>
|
||||||
</EuiPage>
|
</EuiPageTemplate>
|
||||||
</Router>
|
</Router>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { EuiPageSideBar_Deprecated as EuiPageSideBar, EuiSideNav } from '@elastic/eui';
|
import { EuiPageSidebar, EuiSideNav } from '@elastic/eui';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
import { routes } from '../../routes';
|
import { routes } from '../../routes';
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ export const Sidebar: React.FC = () => {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<EuiPageSideBar>
|
<EuiPageSidebar>
|
||||||
<EuiSideNav
|
<EuiSideNav
|
||||||
items={routes.map(({ id, title, items }) => ({
|
items={routes.map(({ id, title, items }) => ({
|
||||||
id,
|
id,
|
||||||
|
@ -29,6 +29,6 @@ export const Sidebar: React.FC = () => {
|
||||||
})),
|
})),
|
||||||
}))}
|
}))}
|
||||||
/>
|
/>
|
||||||
</EuiPageSideBar>
|
</EuiPageSidebar>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,6 +10,7 @@ import * as React from 'react';
|
||||||
import { render, unmountComponentAtNode } from 'react-dom';
|
import { render, unmountComponentAtNode } from 'react-dom';
|
||||||
import { CoreSetup, CoreStart, AppMountParameters } from '@kbn/core/public';
|
import { CoreSetup, CoreStart, AppMountParameters } from '@kbn/core/public';
|
||||||
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
|
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
|
||||||
|
import { PLUGIN_NAME } from '../common/constants';
|
||||||
import { ResponseStreamStartPlugins } from './plugin';
|
import { ResponseStreamStartPlugins } from './plugin';
|
||||||
import { App } from './containers/app';
|
import { App } from './containers/app';
|
||||||
|
|
||||||
|
@ -24,6 +25,21 @@ export const mount =
|
||||||
async ({ appBasePath, element }: AppMountParameters) => {
|
async ({ appBasePath, element }: AppMountParameters) => {
|
||||||
const [core, plugins] = await coreSetup.getStartServices();
|
const [core, plugins] = await coreSetup.getStartServices();
|
||||||
const deps: ResponseStreamDeps = { appBasePath, core, plugins };
|
const deps: ResponseStreamDeps = { appBasePath, core, plugins };
|
||||||
|
|
||||||
|
core.chrome.setBreadcrumbs([
|
||||||
|
{
|
||||||
|
text: 'Developer examples',
|
||||||
|
href: `/app/developerExamples`,
|
||||||
|
onClick: (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
core.application.navigateToApp('developerExamples');
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: PLUGIN_NAME,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
const reactElement = (
|
const reactElement = (
|
||||||
<KibanaContextProvider services={deps}>
|
<KibanaContextProvider services={deps}>
|
||||||
<App />
|
<App />
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
import { Plugin, CoreSetup, AppNavLinkStatus } from '@kbn/core/public';
|
import { Plugin, CoreSetup, AppNavLinkStatus } from '@kbn/core/public';
|
||||||
import { DeveloperExamplesSetup } from '@kbn/developer-examples-plugin/public';
|
import { DeveloperExamplesSetup } from '@kbn/developer-examples-plugin/public';
|
||||||
|
import { PLUGIN_ID, PLUGIN_NAME } from '../common/constants';
|
||||||
import { mount } from './mount';
|
import { mount } from './mount';
|
||||||
|
|
||||||
export interface ResponseStreamSetupPlugins {
|
export interface ResponseStreamSetupPlugins {
|
||||||
|
@ -23,15 +24,15 @@ export class ResponseStreamPlugin implements Plugin {
|
||||||
{ developerExamples }: ResponseStreamSetupPlugins
|
{ developerExamples }: ResponseStreamSetupPlugins
|
||||||
) {
|
) {
|
||||||
core.application.register({
|
core.application.register({
|
||||||
id: 'response-stream',
|
id: PLUGIN_ID,
|
||||||
title: 'response stream',
|
title: PLUGIN_NAME,
|
||||||
navLinkStatus: AppNavLinkStatus.hidden,
|
navLinkStatus: AppNavLinkStatus.hidden,
|
||||||
mount: mount(core),
|
mount: mount(core),
|
||||||
});
|
});
|
||||||
|
|
||||||
developerExamples.register({
|
developerExamples.register({
|
||||||
appId: 'response-stream',
|
appId: PLUGIN_ID,
|
||||||
title: 'response stream',
|
title: PLUGIN_NAME,
|
||||||
description:
|
description:
|
||||||
'This example demonstrates how to stream chunks of data to the client with just a single request.',
|
'This example demonstrates how to stream chunks of data to the client with just a single request.',
|
||||||
links: [
|
links: [
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { PLUGIN_ID, PLUGIN_NAME } from '../common/constants';
|
||||||
import { PageSimpleStringStream } from './containers/app/pages/page_simple_string_stream';
|
import { PageSimpleStringStream } from './containers/app/pages/page_simple_string_stream';
|
||||||
import { PageReducerStream } from './containers/app/pages/page_reducer_stream';
|
import { PageReducerStream } from './containers/app/pages/page_reducer_stream';
|
||||||
|
|
||||||
|
@ -24,8 +25,8 @@ interface RouteDef {
|
||||||
|
|
||||||
export const routes: RouteSectionDef[] = [
|
export const routes: RouteSectionDef[] = [
|
||||||
{
|
{
|
||||||
title: 'response stream',
|
title: PLUGIN_NAME,
|
||||||
id: 'responseStream',
|
id: PLUGIN_ID,
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
title: 'Simple string stream',
|
title: 'Simple string stream',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue