mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
Remove bfetch explorer example plugin (#204284)
## Summary Part of https://github.com/elastic/kibana/issues/186139. First step of breaking up https://github.com/elastic/kibana/pull/199066 into smaller pieces. Removes the bfetch explorer example plugin.
This commit is contained in:
parent
edc79773f5
commit
8ad0eb4122
24 changed files with 0 additions and 777 deletions
2
.github/CODEOWNERS
vendored
2
.github/CODEOWNERS
vendored
|
@ -5,7 +5,6 @@
|
|||
## `node scripts/generate codeowners`.
|
||||
####
|
||||
|
||||
examples/bfetch_explorer @elastic/appex-sharedux
|
||||
examples/content_management_examples @elastic/appex-sharedux
|
||||
examples/controls_example @elastic/kibana-presentation
|
||||
examples/data_view_field_editor_example @elastic/kibana-data-discovery
|
||||
|
@ -2617,7 +2616,6 @@ x-pack/plugins/observability_solution/observability_shared/public/components/pro
|
|||
/test/examples/state_sync/*.ts @elastic/appex-sharedux
|
||||
/test/examples/error_boundary/index.ts @elastic/appex-sharedux
|
||||
/test/examples/content_management/*.ts @elastic/appex-sharedux
|
||||
/test/examples/bfetch_explorer/*.ts @elastic/appex-sharedux
|
||||
/test/api_integration/apis/guided_onboarding @elastic/appex-sharedux
|
||||
/x-pack/test/banners_functional @elastic/appex-sharedux
|
||||
/x-pack/test/custom_branding @elastic/appex-sharedux
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
## bfetch explorer
|
||||
|
||||
bfetch is a service that allows you to batch HTTP requests and stream responses
|
||||
back.
|
||||
|
||||
This example app demonstrates:
|
||||
- How you can create a streaming response route and consume it from the
|
||||
client
|
||||
- How you can create a batch processing route and consume it from the client
|
||||
|
||||
To run this example, use the command `yarn start --run-examples`.
|
|
@ -1,17 +0,0 @@
|
|||
{
|
||||
"type": "plugin",
|
||||
"id": "@kbn/bfetch-explorer-plugin",
|
||||
"owner": "@elastic/appex-sharedux",
|
||||
"plugin": {
|
||||
"id": "bfetchExplorer",
|
||||
"server": true,
|
||||
"browser": true,
|
||||
"requiredPlugins": [
|
||||
"bfetch",
|
||||
"developerExamples"
|
||||
],
|
||||
"requiredBundles": [
|
||||
"kibanaReact"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -1,83 +0,0 @@
|
|||
/*
|
||||
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
|
||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import React, { useState } from 'react';
|
||||
import useMountedState from 'react-use/lib/useMountedState';
|
||||
import useList from 'react-use/lib/useList';
|
||||
import { EuiForm, EuiSpacer, EuiFieldNumber, EuiFormRow, EuiButton } from '@elastic/eui';
|
||||
import { BfetchPublicSetup } from '@kbn/bfetch-plugin/public';
|
||||
|
||||
export interface Props {
|
||||
fetchStreaming: BfetchPublicSetup['fetchStreaming'];
|
||||
}
|
||||
|
||||
export const CountUntil: React.FC<Props> = ({ fetchStreaming }) => {
|
||||
const isMounted = useMountedState();
|
||||
const [data, setData] = useState(5);
|
||||
const [showingResults, setShowingResults] = useState(false);
|
||||
const [results, { push: pushResult, clear: clearList }] = useList<string>([]);
|
||||
const [completed, setCompleted] = useState(false);
|
||||
const [error, setError] = useState<any>(null);
|
||||
|
||||
const handleSubmit = () => {
|
||||
setShowingResults(true);
|
||||
const { stream } = fetchStreaming({
|
||||
url: '/bfetch_explorer/count',
|
||||
body: JSON.stringify({ data }),
|
||||
});
|
||||
stream.subscribe({
|
||||
next: (next: string) => {
|
||||
if (!isMounted()) return;
|
||||
pushResult(next);
|
||||
},
|
||||
error: (nextError: any) => {
|
||||
if (!isMounted()) return;
|
||||
setError(nextError);
|
||||
},
|
||||
complete: () => {
|
||||
if (!isMounted()) return;
|
||||
setCompleted(true);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const handleReset = () => {
|
||||
setShowingResults(false);
|
||||
clearList();
|
||||
setError(null);
|
||||
setCompleted(false);
|
||||
};
|
||||
|
||||
if (showingResults) {
|
||||
return (
|
||||
<EuiForm data-test-subj="CountUntil">
|
||||
<pre>{JSON.stringify(error || results, null, 4)}</pre>
|
||||
<EuiSpacer size="l" />
|
||||
<EuiButton disabled={!completed} onClick={handleReset}>
|
||||
Reset
|
||||
</EuiButton>
|
||||
</EuiForm>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<EuiForm data-test-subj="CountUntil">
|
||||
<EuiFormRow label="Some integer" fullWidth>
|
||||
<EuiFieldNumber
|
||||
placeholder="Some integer"
|
||||
value={data}
|
||||
onChange={(e) => setData(Number(e.target.value))}
|
||||
/>
|
||||
</EuiFormRow>
|
||||
<EuiButton type="submit" fill onClick={handleSubmit}>
|
||||
Start
|
||||
</EuiButton>
|
||||
</EuiForm>
|
||||
);
|
||||
};
|
|
@ -1,95 +0,0 @@
|
|||
/*
|
||||
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
|
||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import React, { useState } from 'react';
|
||||
import useMountedState from 'react-use/lib/useMountedState';
|
||||
import useList from 'react-use/lib/useList';
|
||||
import useCounter from 'react-use/lib/useCounter';
|
||||
import { EuiForm, EuiSpacer, EuiTextArea, EuiFormRow, EuiButton } from '@elastic/eui';
|
||||
import { ExplorerService } from '../../plugin';
|
||||
|
||||
interface ResultItem {
|
||||
num: number;
|
||||
result?: {
|
||||
num: number;
|
||||
};
|
||||
error?: any;
|
||||
}
|
||||
|
||||
const defaultNumbers = [2000, 300, -1, 1000].join('\n');
|
||||
|
||||
export interface Props {
|
||||
double: ExplorerService['double'];
|
||||
}
|
||||
|
||||
export const DoubleIntegers: React.FC<Props> = ({ double }) => {
|
||||
const isMounted = useMountedState();
|
||||
const [numbers, setNumbers] = useState(defaultNumbers);
|
||||
const [showingResults, setShowingResults] = useState(false);
|
||||
const [numberOfResultsAwaiting, counter] = useCounter(0);
|
||||
const [results, { push: pushResult, clear: clearList }] = useList<ResultItem>([]);
|
||||
|
||||
const handleSubmit = () => {
|
||||
setShowingResults(true);
|
||||
const nums = numbers
|
||||
.split('\n')
|
||||
.map((num) => num.trim())
|
||||
.filter(Boolean)
|
||||
.map(Number);
|
||||
counter.set(nums.length);
|
||||
nums.forEach((num) => {
|
||||
double({ num }).then(
|
||||
(result) => {
|
||||
if (!isMounted()) return;
|
||||
counter.dec();
|
||||
pushResult({ num, result });
|
||||
},
|
||||
(error) => {
|
||||
if (!isMounted()) return;
|
||||
counter.dec();
|
||||
pushResult({ num, error });
|
||||
}
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
const handleReset = () => {
|
||||
setShowingResults(false);
|
||||
counter.reset();
|
||||
clearList();
|
||||
};
|
||||
|
||||
if (showingResults) {
|
||||
return (
|
||||
<EuiForm data-test-subj="DoubleIntegers">
|
||||
<pre>{JSON.stringify(results, null, 4)}</pre>
|
||||
<EuiSpacer size="l" />
|
||||
<EuiButton disabled={!!numberOfResultsAwaiting} onClick={handleReset}>
|
||||
Reset
|
||||
</EuiButton>
|
||||
</EuiForm>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<EuiForm data-test-subj="DoubleIntegers">
|
||||
<EuiFormRow label="Numbers in ms separated by new line" fullWidth>
|
||||
<EuiTextArea
|
||||
fullWidth
|
||||
placeholder="Enter numbers in milliseconds separated by new line"
|
||||
value={numbers}
|
||||
onChange={(e) => setNumbers(e.target.value)}
|
||||
/>
|
||||
</EuiFormRow>
|
||||
<EuiButton type="submit" fill onClick={handleSubmit}>
|
||||
Send
|
||||
</EuiButton>
|
||||
</EuiForm>
|
||||
);
|
||||
};
|
|
@ -1,34 +0,0 @@
|
|||
/*
|
||||
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
|
||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import React, { FC, PropsWithChildren } from 'react';
|
||||
import { EuiPageTemplate, EuiPageSection, EuiPageHeader } from '@elastic/eui';
|
||||
|
||||
export interface PageProps {
|
||||
title?: React.ReactNode;
|
||||
sidebar?: React.ReactNode;
|
||||
}
|
||||
|
||||
export const Page: FC<PropsWithChildren<PageProps>> = ({
|
||||
title = 'Untitled',
|
||||
sidebar,
|
||||
children,
|
||||
}) => {
|
||||
return (
|
||||
<EuiPageTemplate offset={0} grow={true}>
|
||||
<EuiPageTemplate.Sidebar>{sidebar}</EuiPageTemplate.Sidebar>
|
||||
<EuiPageTemplate.Header>
|
||||
<EuiPageHeader pageTitle={title} />
|
||||
</EuiPageTemplate.Header>
|
||||
<EuiPageTemplate.Section>
|
||||
<EuiPageSection style={{ maxWidth: 800, margin: '0 auto' }}>{children}</EuiPageSection>
|
||||
</EuiPageTemplate.Section>
|
||||
</EuiPageTemplate>
|
||||
);
|
||||
};
|
|
@ -1,37 +0,0 @@
|
|||
/*
|
||||
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
|
||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { Redirect } from 'react-router-dom';
|
||||
import { BrowserRouter as Router, Route, Routes } from '@kbn/shared-ux-router';
|
||||
import { EuiPage } from '@elastic/eui';
|
||||
import { useDeps } from '../../hooks/use_deps';
|
||||
import { routes } from '../../routes';
|
||||
|
||||
export const App: React.FC = () => {
|
||||
const { appBasePath } = useDeps();
|
||||
|
||||
const routeElements: React.ReactElement[] = [];
|
||||
for (const { items } of routes) {
|
||||
for (const { id, component } of items) {
|
||||
routeElements.push(<Route key={id} path={`/${id}`} render={(props) => component} />);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Router basename={appBasePath}>
|
||||
<EuiPage>
|
||||
<Routes>
|
||||
{routeElements}
|
||||
<Redirect to="/count-until" />
|
||||
</Routes>
|
||||
</EuiPage>
|
||||
</Router>
|
||||
);
|
||||
};
|
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
|
||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import * as React from 'react';
|
||||
import { EuiPanel, EuiText } from '@elastic/eui';
|
||||
import { CountUntil } from '../../../../components/count_until';
|
||||
import { Page } from '../../../../components/page';
|
||||
import { useDeps } from '../../../../hooks/use_deps';
|
||||
import { Sidebar } from '../../sidebar';
|
||||
|
||||
export const PageCountUntil = () => {
|
||||
const { plugins } = useDeps();
|
||||
|
||||
return (
|
||||
<Page title={'Count Until'} sidebar={<Sidebar />}>
|
||||
<EuiText>
|
||||
This demo sends a single number N using <code>fetchStreaming</code> to the server. The
|
||||
server will stream back N number of messages with 1 second delay each containing a number
|
||||
from 1 to N, after which it will close the stream.
|
||||
</EuiText>
|
||||
<br />
|
||||
<EuiPanel paddingSize="l">
|
||||
<CountUntil fetchStreaming={plugins.bfetch.fetchStreaming} />
|
||||
</EuiPanel>
|
||||
</Page>
|
||||
);
|
||||
};
|
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
|
||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import * as React from 'react';
|
||||
import { EuiPanel, EuiText } from '@elastic/eui';
|
||||
import { DoubleIntegers } from '../../../../components/double_integers';
|
||||
import { Page } from '../../../../components/page';
|
||||
import { useDeps } from '../../../../hooks/use_deps';
|
||||
import { Sidebar } from '../../sidebar';
|
||||
|
||||
export const PageDoubleIntegers = () => {
|
||||
const { explorer } = useDeps();
|
||||
|
||||
return (
|
||||
<Page title={'Double Integers'} sidebar={<Sidebar />}>
|
||||
<EuiText>
|
||||
Below is a list of numbers in milliseconds. They are sent as a batch to the server. For each
|
||||
number server waits given number of milliseconds then doubles the number and streams it
|
||||
back.
|
||||
</EuiText>
|
||||
<br />
|
||||
<EuiPanel paddingSize="l">
|
||||
<DoubleIntegers double={explorer.double} />
|
||||
</EuiPanel>
|
||||
</Page>
|
||||
);
|
||||
};
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
|
||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { EuiSideNav } from '@elastic/eui';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { routes } from '../../../routes';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||
interface SidebarProps {}
|
||||
|
||||
export const Sidebar: React.FC<SidebarProps> = () => {
|
||||
const history = useHistory();
|
||||
|
||||
return (
|
||||
<EuiSideNav
|
||||
items={[
|
||||
{
|
||||
name: 'bfetch explorer',
|
||||
id: 'home',
|
||||
items: routes.map(({ id, title, items }) => ({
|
||||
id,
|
||||
name: title,
|
||||
isSelected: true,
|
||||
items: items.map((route) => ({
|
||||
id: route.id,
|
||||
name: route.title,
|
||||
onClick: () => history.push(`/${route.id}`),
|
||||
'data-test-subj': route.id,
|
||||
})),
|
||||
})),
|
||||
},
|
||||
]}
|
||||
/>
|
||||
);
|
||||
};
|
|
@ -1,13 +0,0 @@
|
|||
/*
|
||||
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
|
||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import { useKibana } from '@kbn/kibana-react-plugin/public';
|
||||
import { BfetchDeps } from '../mount';
|
||||
|
||||
export const useDeps = () => useKibana().services as unknown as BfetchDeps;
|
|
@ -1,12 +0,0 @@
|
|||
/*
|
||||
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
|
||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import { BfetchExplorerPlugin } from './plugin';
|
||||
|
||||
export const plugin = () => new BfetchExplorerPlugin();
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
|
||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import * as React from 'react';
|
||||
import { render, unmountComponentAtNode } from 'react-dom';
|
||||
import { CoreSetup, CoreStart, AppMountParameters } from '@kbn/core/public';
|
||||
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
|
||||
import { KibanaRenderContextProvider } from '@kbn/react-kibana-context-render';
|
||||
import { BfetchExplorerStartPlugins, ExplorerService } from './plugin';
|
||||
import { App } from './containers/app';
|
||||
|
||||
export interface BfetchDeps {
|
||||
appBasePath: string;
|
||||
core: CoreStart;
|
||||
plugins: BfetchExplorerStartPlugins;
|
||||
explorer: ExplorerService;
|
||||
}
|
||||
|
||||
export const mount =
|
||||
(coreSetup: CoreSetup<BfetchExplorerStartPlugins>, explorer: ExplorerService) =>
|
||||
async ({ appBasePath, element }: AppMountParameters) => {
|
||||
const [core, plugins] = await coreSetup.getStartServices();
|
||||
const deps: BfetchDeps = { appBasePath, core, plugins, explorer };
|
||||
const reactElement = (
|
||||
<KibanaRenderContextProvider {...core}>
|
||||
<KibanaContextProvider services={deps}>
|
||||
<App />
|
||||
</KibanaContextProvider>
|
||||
</KibanaRenderContextProvider>
|
||||
);
|
||||
render(reactElement, element);
|
||||
return () => unmountComponentAtNode(element);
|
||||
};
|
|
@ -1,67 +0,0 @@
|
|||
/*
|
||||
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
|
||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import { Plugin, CoreSetup } from '@kbn/core/public';
|
||||
import { BfetchPublicSetup, BfetchPublicStart } from '@kbn/bfetch-plugin/public';
|
||||
import { DeveloperExamplesSetup } from '@kbn/developer-examples-plugin/public';
|
||||
import { mount } from './mount';
|
||||
|
||||
export interface ExplorerService {
|
||||
double: (number: { num: number }) => Promise<{ num: number }>;
|
||||
}
|
||||
|
||||
export interface BfetchExplorerSetupPlugins {
|
||||
bfetch: BfetchPublicSetup;
|
||||
developerExamples: DeveloperExamplesSetup;
|
||||
}
|
||||
|
||||
export interface BfetchExplorerStartPlugins {
|
||||
bfetch: BfetchPublicStart;
|
||||
}
|
||||
|
||||
export class BfetchExplorerPlugin implements Plugin {
|
||||
public setup(
|
||||
core: CoreSetup<BfetchExplorerStartPlugins, void>,
|
||||
{ bfetch, developerExamples }: BfetchExplorerSetupPlugins
|
||||
) {
|
||||
const double = bfetch.batchedFunction<{ num: number }, { num: number }>({
|
||||
url: '/bfetch_explorer/double',
|
||||
});
|
||||
|
||||
const explorer: ExplorerService = {
|
||||
double,
|
||||
};
|
||||
|
||||
core.application.register({
|
||||
id: 'bfetch-explorer',
|
||||
title: 'bfetch explorer',
|
||||
visibleIn: [],
|
||||
mount: mount(core, explorer),
|
||||
});
|
||||
|
||||
developerExamples.register({
|
||||
appId: 'bfetch-explorer',
|
||||
title: 'bfetch',
|
||||
description:
|
||||
'bfetch is a service that allows to batch HTTP requests and streams responses back.',
|
||||
links: [
|
||||
{
|
||||
label: 'README',
|
||||
href: 'https://github.com/elastic/kibana/blob/main/src/plugins/bfetch/README.md',
|
||||
iconType: 'logoGithub',
|
||||
size: 's',
|
||||
target: '_blank',
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
public start() {}
|
||||
public stop() {}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
/*
|
||||
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
|
||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { PageDoubleIntegers } from './containers/app/pages/page_double_integers';
|
||||
import { PageCountUntil } from './containers/app/pages/page_count_until';
|
||||
|
||||
interface RouteSectionDef {
|
||||
title: string;
|
||||
id: string;
|
||||
items: RouteDef[];
|
||||
}
|
||||
|
||||
interface RouteDef {
|
||||
title: string;
|
||||
id: string;
|
||||
component: React.ReactNode;
|
||||
}
|
||||
|
||||
export const routes: RouteSectionDef[] = [
|
||||
{
|
||||
title: 'fetchStreaming',
|
||||
id: 'fetchStreaming',
|
||||
items: [
|
||||
{
|
||||
title: 'Count until',
|
||||
id: 'count-until',
|
||||
component: <PageCountUntil />,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: 'batchedFunction',
|
||||
id: 'batchedFunction',
|
||||
items: [
|
||||
{
|
||||
title: 'Double integers',
|
||||
id: 'double-integers',
|
||||
component: <PageDoubleIntegers />,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
|
@ -1,13 +0,0 @@
|
|||
/*
|
||||
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
|
||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
export const plugin = async () => {
|
||||
const { BfetchExplorerPlugin } = await import('./plugin');
|
||||
return new BfetchExplorerPlugin();
|
||||
};
|
|
@ -1,58 +0,0 @@
|
|||
/*
|
||||
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
|
||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import { Subject } from 'rxjs';
|
||||
import { Plugin, CoreSetup, CoreStart } from '@kbn/core/server';
|
||||
import { BfetchServerSetup, BfetchServerStart } from '@kbn/bfetch-plugin/server';
|
||||
|
||||
export interface BfetchExplorerSetupPlugins {
|
||||
bfetch: BfetchServerSetup;
|
||||
}
|
||||
|
||||
export interface BfetchExplorerStartPlugins {
|
||||
bfetch: BfetchServerStart;
|
||||
}
|
||||
|
||||
export class BfetchExplorerPlugin implements Plugin {
|
||||
public setup(core: CoreSetup, plugins: BfetchExplorerSetupPlugins) {
|
||||
plugins.bfetch.addStreamingResponseRoute<string, string>('/bfetch_explorer/count', () => ({
|
||||
getResponseStream: ({ data }: any) => {
|
||||
const subject = new Subject<string>();
|
||||
const countTo = Number(data);
|
||||
for (let cnt = 1; cnt <= countTo; cnt++) {
|
||||
setTimeout(() => {
|
||||
subject.next(String(cnt));
|
||||
}, cnt * 1000);
|
||||
}
|
||||
setTimeout(() => {
|
||||
subject.complete();
|
||||
}, countTo * 1000);
|
||||
return subject;
|
||||
},
|
||||
}));
|
||||
|
||||
plugins.bfetch.addBatchProcessingRoute<{ num: number }, { num: number }>(
|
||||
'/bfetch_explorer/double',
|
||||
() => ({
|
||||
onBatchItem: async ({ num }) => {
|
||||
// Validate inputs.
|
||||
if (num < 0) throw new Error('Invalid number');
|
||||
// Wait number of specified milliseconds.
|
||||
await new Promise((r) => setTimeout(r, num));
|
||||
// Double the number and send it back.
|
||||
return { num: 2 * num };
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
public start(core: CoreStart, plugins: BfetchExplorerStartPlugins) {}
|
||||
|
||||
public stop() {}
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"outDir": "target/types",
|
||||
},
|
||||
"include": [
|
||||
"index.ts",
|
||||
"public/**/*.ts",
|
||||
"public/**/*.tsx",
|
||||
"server/**/*.ts",
|
||||
"../../typings/**/*",
|
||||
],
|
||||
"exclude": [
|
||||
"target/**/*",
|
||||
],
|
||||
"kbn_references": [
|
||||
"@kbn/core",
|
||||
"@kbn/developer-examples-plugin",
|
||||
"@kbn/bfetch-plugin",
|
||||
"@kbn/kibana-react-plugin",
|
||||
"@kbn/shared-ux-router",
|
||||
"@kbn/react-kibana-context-render",
|
||||
]
|
||||
}
|
|
@ -197,7 +197,6 @@
|
|||
"@kbn/avc-banner": "link:src/platform/packages/shared/kbn-avc-banner",
|
||||
"@kbn/banners-plugin": "link:x-pack/plugins/banners",
|
||||
"@kbn/bfetch-error": "link:packages/kbn-bfetch-error",
|
||||
"@kbn/bfetch-explorer-plugin": "link:examples/bfetch_explorer",
|
||||
"@kbn/bfetch-plugin": "link:src/plugins/bfetch",
|
||||
"@kbn/calculate-auto": "link:packages/kbn-calculate-auto",
|
||||
"@kbn/calculate-width-from-char-count": "link:packages/kbn-calculate-width-from-char-count",
|
||||
|
|
|
@ -1,82 +0,0 @@
|
|||
/*
|
||||
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
|
||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import expect from '@kbn/expect';
|
||||
import { FtrProviderContext } from '../../functional/ftr_provider_context';
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default function ({ getService }: FtrProviderContext) {
|
||||
const testSubjects = getService('testSubjects');
|
||||
|
||||
describe('batchedFunction', () => {
|
||||
beforeEach(async () => {
|
||||
await testSubjects.click('count-until');
|
||||
await testSubjects.click('double-integers');
|
||||
});
|
||||
|
||||
it('executes all requests in a batch', async () => {
|
||||
const form = await testSubjects.find('DoubleIntegers');
|
||||
const btn = await form.findByCssSelector('button');
|
||||
await btn.click();
|
||||
await new Promise((r) => setTimeout(r, 4000));
|
||||
const pre = await form.findByCssSelector('pre');
|
||||
const text = await pre.getVisibleText();
|
||||
const json = JSON.parse(text);
|
||||
|
||||
expect(json).to.eql([
|
||||
{
|
||||
num: -1,
|
||||
error: {
|
||||
message: 'Invalid number',
|
||||
},
|
||||
},
|
||||
{
|
||||
num: 300,
|
||||
result: {
|
||||
num: 600,
|
||||
},
|
||||
},
|
||||
{
|
||||
num: 1000,
|
||||
result: {
|
||||
num: 2000,
|
||||
},
|
||||
},
|
||||
{
|
||||
num: 2000,
|
||||
result: {
|
||||
num: 4000,
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('streams results back', async () => {
|
||||
const form = await testSubjects.find('DoubleIntegers');
|
||||
const btn = await form.findByCssSelector('button');
|
||||
await btn.click();
|
||||
|
||||
await new Promise((r) => setTimeout(r, 500));
|
||||
const pre = await form.findByCssSelector('pre');
|
||||
|
||||
const text1 = await pre.getVisibleText();
|
||||
const json1 = JSON.parse(text1);
|
||||
|
||||
expect(json1.length > 0).to.be(true);
|
||||
expect(json1.length < 4).to.be(true);
|
||||
|
||||
await new Promise((r) => setTimeout(r, 3500));
|
||||
|
||||
const text2 = await pre.getVisibleText();
|
||||
const json2 = JSON.parse(text2);
|
||||
|
||||
expect(json2.length).to.be(4);
|
||||
});
|
||||
});
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
/*
|
||||
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
|
||||
* License v3.0 only", or the "Server Side Public License, v 1".
|
||||
*/
|
||||
|
||||
import { FtrProviderContext } from '../../functional/ftr_provider_context';
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default function ({ getService, getPageObjects, loadTestFile }: FtrProviderContext) {
|
||||
const browser = getService('browser');
|
||||
const PageObjects = getPageObjects(['common', 'header']);
|
||||
|
||||
describe('bfetch explorer', function () {
|
||||
before(async () => {
|
||||
await browser.setWindowSize(1300, 900);
|
||||
await PageObjects.common.navigateToApp('bfetch-explorer', { insertTimestamp: false });
|
||||
});
|
||||
|
||||
loadTestFile(require.resolve('./batched_function'));
|
||||
});
|
||||
}
|
|
@ -19,7 +19,6 @@ export default async function ({ readConfigFile }) {
|
|||
rootTags: ['runOutsideOfCiGroups'],
|
||||
testFiles: [
|
||||
require.resolve('./hello_world'),
|
||||
require.resolve('./bfetch_explorer'),
|
||||
require.resolve('./ui_actions'),
|
||||
require.resolve('./state_sync'),
|
||||
require.resolve('./routing'),
|
||||
|
|
|
@ -118,8 +118,6 @@
|
|||
"@kbn/bazel-runner/*": ["packages/kbn-bazel-runner/*"],
|
||||
"@kbn/bfetch-error": ["packages/kbn-bfetch-error"],
|
||||
"@kbn/bfetch-error/*": ["packages/kbn-bfetch-error/*"],
|
||||
"@kbn/bfetch-explorer-plugin": ["examples/bfetch_explorer"],
|
||||
"@kbn/bfetch-explorer-plugin/*": ["examples/bfetch_explorer/*"],
|
||||
"@kbn/bfetch-plugin": ["src/plugins/bfetch"],
|
||||
"@kbn/bfetch-plugin/*": ["src/plugins/bfetch/*"],
|
||||
"@kbn/calculate-auto": ["packages/kbn-calculate-auto"],
|
||||
|
|
|
@ -4053,10 +4053,6 @@
|
|||
version "0.0.0"
|
||||
uid ""
|
||||
|
||||
"@kbn/bfetch-explorer-plugin@link:examples/bfetch_explorer":
|
||||
version "0.0.0"
|
||||
uid ""
|
||||
|
||||
"@kbn/bfetch-plugin@link:src/plugins/bfetch":
|
||||
version "0.0.0"
|
||||
uid ""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue