Skip to content

Commit

Permalink
Merge branch 'master' into alerting/rename-reload-alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine committed Feb 22, 2021
2 parents 5525915 + 678f848 commit a61dd80
Show file tree
Hide file tree
Showing 84 changed files with 2,729 additions and 2,059 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ x-pack/plugins/telemetry_collection_xpack/schema/ @elastic/kibana-core @elastic/
/x-pack/test/security_api_integration/ @elastic/kibana-security
/x-pack/test/security_functional/ @elastic/kibana-security
/x-pack/test/spaces_api_integration/ @elastic/kibana-security
/x-pack/test/saved_object_api_integration/ @elastic/kibana-security
#CC# /x-pack/plugins/security/ @elastic/kibana-security

# Kibana Alerting Services
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

## AppLeaveHandler type

> Warning: This API is now obsolete.
>
> [AppMountParameters.onAppLeave](./kibana-plugin-core-public.appmountparameters.onappleave.md) has been deprecated in favor of [ScopedHistory.block](./kibana-plugin-core-public.scopedhistory.block.md)
>
A handler that will be executed before leaving the application, either when going to another application or when closing the browser tab or manually changing the url. Should return `confirm` to to prompt a message to the user before leaving the page, or `default` to keep the default behavior (doing nothing).

See [AppMountParameters](./kibana-plugin-core-public.appmountparameters.md) for detailed usage examples.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

## AppMountParameters.onAppLeave property

> Warning: This API is now obsolete.
>
> [ScopedHistory.block](./kibana-plugin-core-public.scopedhistory.block.md) should be used instead.
>
A function that can be used to register a handler that will be called when the user is leaving the current application, allowing to prompt a confirmation message before actually changing the page.

This will be called either when the user goes to another application, or when trying to close the tab or manually changing the url.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@

## ScopedHistory.block property

Not supported. Use [AppMountParameters.onAppLeave](./kibana-plugin-core-public.appmountparameters.onappleave.md)<!-- -->.
Add a block prompt requesting user confirmation when navigating away from the current page.

<b>Signature:</b>

```typescript
block: (prompt?: string | boolean | History.TransitionPromptHook<HistoryLocationState> | undefined) => UnregisterCallback;
```

## Remarks

We prefer that applications use the `onAppLeave` API because it supports a more graceful experience that prefers a modal when possible, falling back to a confirm dialog box in the beforeunload case.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export declare class ScopedHistory<HistoryLocationState = unknown> implements Hi
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [action](./kibana-plugin-core-public.scopedhistory.action.md) | | <code>Action</code> | The last action dispatched on the history stack. |
| [block](./kibana-plugin-core-public.scopedhistory.block.md) | | <code>(prompt?: string &#124; boolean &#124; History.TransitionPromptHook&lt;HistoryLocationState&gt; &#124; undefined) =&gt; UnregisterCallback</code> | Not supported. Use [AppMountParameters.onAppLeave](./kibana-plugin-core-public.appmountparameters.onappleave.md)<!-- -->. |
| [block](./kibana-plugin-core-public.scopedhistory.block.md) | | <code>(prompt?: string &#124; boolean &#124; History.TransitionPromptHook&lt;HistoryLocationState&gt; &#124; undefined) =&gt; UnregisterCallback</code> | Add a block prompt requesting user confirmation when navigating away from the current page. |
| [createHref](./kibana-plugin-core-public.scopedhistory.createhref.md) | | <code>(location: LocationDescriptorObject&lt;HistoryLocationState&gt;, { prependBasePath }?: {</code><br/><code> prependBasePath?: boolean &#124; undefined;</code><br/><code> }) =&gt; Href</code> | Creates an href (string) to the location. If <code>prependBasePath</code> is true (default), it will prepend the location's path with the scoped history basePath. |
| [createSubHistory](./kibana-plugin-core-public.scopedhistory.createsubhistory.md) | | <code>&lt;SubHistoryLocationState = unknown&gt;(basePath: string) =&gt; ScopedHistory&lt;SubHistoryLocationState&gt;</code> | Creates a <code>ScopedHistory</code> for a subpath of this <code>ScopedHistory</code>. Useful for applications that may have sub-apps that do not need access to the containing application's history. |
| [go](./kibana-plugin-core-public.scopedhistory.go.md) | | <code>(n: number) =&gt; void</code> | Send the user forward or backwards in the history stack. |
Expand Down
4 changes: 2 additions & 2 deletions examples/search_examples/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"kibanaVersion": "kibana",
"server": true,
"ui": true,
"requiredPlugins": ["navigation", "data", "developerExamples", "kibanaUtils"],
"requiredPlugins": ["navigation", "data", "developerExamples", "kibanaUtils", "share"],
"optionalPlugins": [],
"requiredBundles": []
"requiredBundles": ["kibanaReact"]
}
67 changes: 54 additions & 13 deletions examples/search_examples/public/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,67 @@

import React from 'react';
import ReactDOM from 'react-dom';
import { Router, Route, Redirect } from 'react-router-dom';
import { I18nProvider } from '@kbn/i18n/react';
import { AppMountParameters, CoreStart } from '../../../src/core/public';
import { AppPluginStartDependencies } from './types';
import { SearchExamplesApp } from './components/app';
import { SearchExamplePage, ExampleLink } from './common/example_page';
import { SearchExamplesApp } from './search/app';
import { SearchSessionsExampleApp } from './search_sessions/app';
import { RedirectAppLinks } from '../../../src/plugins/kibana_react/public';

const LINKS: ExampleLink[] = [
{
path: '/search',
title: 'Search',
},
{
path: '/search-sessions',
title: 'Search Sessions',
},
{
path: 'https://github.com/elastic/kibana/blob/master/src/plugins/data/README.mdx',
title: 'README (GitHub)',
},
];

export const renderApp = (
{ notifications, savedObjects, http }: CoreStart,
{ navigation, data }: AppPluginStartDependencies,
{ appBasePath, element }: AppMountParameters
{ notifications, savedObjects, http, application }: CoreStart,
{ data, navigation }: AppPluginStartDependencies,
{ element, history }: AppMountParameters
) => {
ReactDOM.render(
<SearchExamplesApp
basename={appBasePath}
notifications={notifications}
savedObjectsClient={savedObjects.client}
navigation={navigation}
data={data}
http={http}
/>,
<I18nProvider>
<RedirectAppLinks application={application}>
<SearchExamplePage exampleLinks={LINKS} basePath={http.basePath}>
<Router history={history}>
<Route path={LINKS[0].path}>
<SearchExamplesApp
notifications={notifications}
navigation={navigation}
data={data}
http={http}
/>
</Route>
<Route path={LINKS[1].path}>
<SearchSessionsExampleApp
navigation={navigation}
notifications={notifications}
data={data}
/>
</Route>
<Route path="/" exact={true}>
<Redirect to={LINKS[0].path} />
</Route>
</Router>
</SearchExamplePage>
</RedirectAppLinks>
</I18nProvider>,
element
);

return () => ReactDOM.unmountComponentAtNode(element);
return () => {
data.search.session.clear();
ReactDOM.unmountComponentAtNode(element);
};
};
65 changes: 65 additions & 0 deletions examples/search_examples/public/common/example_page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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.
*/

import React, { PropsWithChildren } from 'react';
import { EuiPage, EuiPageSideBar, EuiSideNav } from '@elastic/eui';
import { IBasePath } from 'kibana/public';
import { PLUGIN_ID } from '../../common';

export interface ExampleLink {
title: string;
path: string;
}

interface NavProps {
exampleLinks: ExampleLink[];
basePath: IBasePath;
}

const SideNav: React.FC<NavProps> = ({ exampleLinks, basePath }: NavProps) => {
const navItems = exampleLinks.map((example) => ({
id: example.path,
name: example.title,
'data-test-subj': example.path,
href: example.path.startsWith('http')
? example.path
: basePath.prepend(`/app/${PLUGIN_ID}${example.path}`),
}));

return (
<EuiSideNav
items={[
{
name: 'Search Examples',
id: 'home',
items: [...navItems],
},
]}
/>
);
};

interface Props {
exampleLinks: ExampleLink[];
basePath: IBasePath;
}

export const SearchExamplePage: React.FC<Props> = ({
children,
exampleLinks,
basePath,
}: PropsWithChildren<Props>) => {
return (
<EuiPage>
<EuiPageSideBar>
<SideNav exampleLinks={exampleLinks} basePath={basePath} />
</EuiPageSideBar>
{children}
</EuiPage>
);
};

0 comments on commit a61dd80

Please sign in to comment.