Skip to content

Commit

Permalink
Merge branch 'master' into fix-es-lint-exhaustive-deps-rule
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Sep 2, 2020
2 parents 6d152dd + 0300245 commit c09a5be
Show file tree
Hide file tree
Showing 239 changed files with 7,989 additions and 1,954 deletions.
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE/APM.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: APM Issue
about: Issues related to the APM solution in Kibana
labels: Team:apm
title: [APM]
---

**Versions**
Kibana: (if relevant)
APM Server: (if relevant)
Elasticsearch: (if relevant)
31 changes: 0 additions & 31 deletions docs/canvas/canvas-tinymath-functions.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -492,37 +492,6 @@ find the mean by index.
|one or more numbers or arrays of numbers
|===

*Returns*: `number` | `Array.<number>`. The maximum value of all numbers if
`args` contains only numbers. Returns an array with the the maximum values at each
index, including all scalar numbers in `args` in the calculation at each index if
`args` contains at least one array.

*Throws*: `'Array length mismatch'` if `args` contains arrays of different lengths

*Example*
[source, js]
------------
max(1, 2, 3) // returns 3
max([10, 20, 30, 40], 15) // returns [15, 20, 30, 40]
max([1, 9], 4, [3, 5]) // returns [max([1, 4, 3]), max([9, 4, 5])] = [4, 9]
------------

[float]
=== mean( ...args )

Finds the mean value of one of more numbers/arrays of numbers passed into the function.
If at least one array of numbers is passed into the function, the function will
find the mean by index.

[cols="3*^<"]
|===
|Param |Type |Description

|...args
|number \| Array.<number>
|one or more numbers or arrays of numbers
|===

*Returns*: `number` | `Array.<number>`. The mean value of all numbers if `args`
contains only numbers. Returns an array with the the mean values of each index,
including all scalar numbers in `args` in the calculation at each index if `args`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ export interface AppMountParameters<HistoryLocationState = unknown>
| [element](./kibana-plugin-core-public.appmountparameters.element.md) | <code>HTMLElement</code> | The container element to render the application into. |
| [history](./kibana-plugin-core-public.appmountparameters.history.md) | <code>ScopedHistory&lt;HistoryLocationState&gt;</code> | A scoped history instance for your application. Should be used to wire up your applications Router. |
| [onAppLeave](./kibana-plugin-core-public.appmountparameters.onappleave.md) | <code>(handler: AppLeaveHandler) =&gt; void</code> | 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. |
| [setHeaderActionMenu](./kibana-plugin-core-public.appmountparameters.setheaderactionmenu.md) | <code>(menuMount: MountPoint &#124; undefined) =&gt; void</code> | A function that can be used to set the mount point used to populate the application action container in the chrome header.<!-- -->Calling the handler multiple time will erase the current content of the action menu with the mount from the latest call. Calling the handler with <code>undefined</code> will unmount the current mount point. Calling the handler after the application has been unmounted will have no effect. |

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-core-public](./kibana-plugin-core-public.md) &gt; [AppMountParameters](./kibana-plugin-core-public.appmountparameters.md) &gt; [setHeaderActionMenu](./kibana-plugin-core-public.appmountparameters.setheaderactionmenu.md)

## AppMountParameters.setHeaderActionMenu property

A function that can be used to set the mount point used to populate the application action container in the chrome header.

Calling the handler multiple time will erase the current content of the action menu with the mount from the latest call. Calling the handler with `undefined` will unmount the current mount point. Calling the handler after the application has been unmounted will have no effect.

<b>Signature:</b>

```typescript
setHeaderActionMenu: (menuMount: MountPoint | undefined) => void;
```

## Example


```ts
// application.tsx
import React from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter, Route } from 'react-router-dom';

import { CoreStart, AppMountParameters } from 'src/core/public';
import { MyPluginDepsStart } from './plugin';

export renderApp = ({ element, history, setHeaderActionMenu }: AppMountParameters) => {
const { renderApp } = await import('./application');
const { renderActionMenu } = await import('./action_menu');
setHeaderActionMenu((element) => {
return renderActionMenu(element);
})
return renderApp({ element, history });
}

```

Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<b>Signature:</b>

```typescript
filter?: string;
filter?: string | KueryNode;
```
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface SavedObjectsFindOptions
| --- | --- | --- |
| [defaultSearchOperator](./kibana-plugin-core-public.savedobjectsfindoptions.defaultsearchoperator.md) | <code>'AND' &#124; 'OR'</code> | |
| [fields](./kibana-plugin-core-public.savedobjectsfindoptions.fields.md) | <code>string[]</code> | An array of fields to include in the results |
| [filter](./kibana-plugin-core-public.savedobjectsfindoptions.filter.md) | <code>string</code> | |
| [filter](./kibana-plugin-core-public.savedobjectsfindoptions.filter.md) | <code>string &#124; KueryNode</code> | |
| [hasReference](./kibana-plugin-core-public.savedobjectsfindoptions.hasreference.md) | <code>{</code><br/><code> type: string;</code><br/><code> id: string;</code><br/><code> }</code> | |
| [namespaces](./kibana-plugin-core-public.savedobjectsfindoptions.namespaces.md) | <code>string[]</code> | |
| [page](./kibana-plugin-core-public.savedobjectsfindoptions.page.md) | <code>number</code> | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<b>Signature:</b>

```typescript
filter?: string;
filter?: string | KueryNode;
```
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface SavedObjectsFindOptions
| --- | --- | --- |
| [defaultSearchOperator](./kibana-plugin-core-server.savedobjectsfindoptions.defaultsearchoperator.md) | <code>'AND' &#124; 'OR'</code> | |
| [fields](./kibana-plugin-core-server.savedobjectsfindoptions.fields.md) | <code>string[]</code> | An array of fields to include in the results |
| [filter](./kibana-plugin-core-server.savedobjectsfindoptions.filter.md) | <code>string</code> | |
| [filter](./kibana-plugin-core-server.savedobjectsfindoptions.filter.md) | <code>string &#124; KueryNode</code> | |
| [hasReference](./kibana-plugin-core-server.savedobjectsfindoptions.hasreference.md) | <code>{</code><br/><code> type: string;</code><br/><code> id: string;</code><br/><code> }</code> | |
| [namespaces](./kibana-plugin-core-server.savedobjectsfindoptions.namespaces.md) | <code>string[]</code> | |
| [page](./kibana-plugin-core-server.savedobjectsfindoptions.page.md) | <code>number</code> | |
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
"test:ftr:server": "node scripts/functional_tests_server",
"test:ftr:runner": "node scripts/functional_test_runner",
"test:coverage": "grunt test:coverage",
"typespec": "typings-tester --config x-pack/plugins/canvas/public/lib/aeroelastic/tsconfig.json x-pack/plugins/canvas/public/lib/aeroelastic/__fixtures__/typescript/typespec_tests.ts",
"checkLicenses": "node scripts/check_licenses --dev",
"build": "node scripts/build --all-platforms",
"start": "node scripts/kibana --dev",
Expand Down Expand Up @@ -145,6 +144,7 @@
"@kbn/test-subj-selector": "0.2.1",
"@kbn/ui-framework": "1.0.0",
"@kbn/ui-shared-deps": "1.0.0",
"@types/yauzl": "^2.9.1",
"JSONStream": "1.3.5",
"abortcontroller-polyfill": "^1.4.0",
"accept": "3.0.2",
Expand Down Expand Up @@ -473,7 +473,6 @@
"topojson-client": "3.0.0",
"tree-kill": "^1.2.2",
"typescript": "4.0.2",
"typings-tester": "^0.3.2",
"ui-select": "0.19.8",
"vega": "^5.13.0",
"vega-lite": "^4.13.1",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/core/public/application/application_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import { History } from 'history';
import { BehaviorSubject, Subject } from 'rxjs';

import type { MountPoint } from '../types';
import { capabilitiesServiceMock } from './capabilities/capabilities_service.mock';
import {
ApplicationSetup,
Expand Down Expand Up @@ -87,6 +88,7 @@ const createInternalStartContractMock = (): jest.Mocked<InternalApplicationStart
applications$: new BehaviorSubject<Map<string, PublicAppInfo | PublicLegacyAppInfo>>(new Map()),
capabilities: capabilitiesServiceMock.createStartContract().capabilities,
currentAppId$: currentAppId$.asObservable(),
currentActionMenu$: new BehaviorSubject<MountPoint | undefined>(undefined),
getComponent: jest.fn(),
getUrlForApp: jest.fn(),
navigateToApp: jest.fn().mockImplementation((appId) => currentAppId$.next(appId)),
Expand Down
42 changes: 37 additions & 5 deletions src/core/public/application/application_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { BehaviorSubject, Observable, Subject, Subscription } from 'rxjs';
import { map, shareReplay, takeUntil, distinctUntilChanged, filter } from 'rxjs/operators';
import { createBrowserHistory, History } from 'history';

import { MountPoint } from '../types';
import { InjectedMetadataSetup } from '../injected_metadata';
import { HttpSetup, HttpStart } from '../http';
import { OverlayStart } from '../overlays';
Expand Down Expand Up @@ -90,6 +91,11 @@ interface AppUpdaterWrapper {
updater: AppUpdater;
}

interface AppInternalState {
leaveHandler?: AppLeaveHandler;
actionMenu?: MountPoint;
}

/**
* Service that is responsible for registering new applications.
* @internal
Expand All @@ -98,8 +104,9 @@ export class ApplicationService {
private readonly apps = new Map<string, App<any> | LegacyApp>();
private readonly mounters = new Map<string, Mounter>();
private readonly capabilities = new CapabilitiesService();
private readonly appLeaveHandlers = new Map<string, AppLeaveHandler>();
private readonly appInternalStates = new Map<string, AppInternalState>();
private currentAppId$ = new BehaviorSubject<string | undefined>(undefined);
private currentActionMenu$ = new BehaviorSubject<MountPoint | undefined>(undefined);
private readonly statusUpdaters$ = new BehaviorSubject<Map<symbol, AppUpdaterWrapper>>(new Map());
private readonly subscriptions: Subscription[] = [];
private stop$ = new Subject();
Expand Down Expand Up @@ -293,12 +300,14 @@ export class ApplicationService {
if (path === undefined) {
path = applications$.value.get(appId)?.defaultPath;
}
this.appLeaveHandlers.delete(this.currentAppId$.value!);
this.appInternalStates.delete(this.currentAppId$.value!);
this.navigate!(getAppUrl(availableMounters, appId, path), state, replace);
this.currentAppId$.next(appId);
}
};

this.currentAppId$.subscribe(() => this.refreshCurrentActionMenu());

return {
applications$: applications$.pipe(
map((apps) => new Map([...apps.entries()].map(([id, app]) => [id, getAppInfo(app)]))),
Expand All @@ -310,6 +319,10 @@ export class ApplicationService {
distinctUntilChanged(),
takeUntil(this.stop$)
),
currentActionMenu$: this.currentActionMenu$.pipe(
distinctUntilChanged(),
takeUntil(this.stop$)
),
history: this.history,
registerMountContext: this.mountContext.registerContext,
getUrlForApp: (
Expand Down Expand Up @@ -338,6 +351,7 @@ export class ApplicationService {
mounters={availableMounters}
appStatuses$={applicationStatuses$}
setAppLeaveHandler={this.setAppLeaveHandler}
setAppActionMenu={this.setAppActionMenu}
setIsMounting={(isMounting) => httpLoadingCount$.next(isMounting ? 1 : 0)}
/>
);
Expand All @@ -346,15 +360,32 @@ export class ApplicationService {
}

private setAppLeaveHandler = (appId: string, handler: AppLeaveHandler) => {
this.appLeaveHandlers.set(appId, handler);
this.appInternalStates.set(appId, {
...(this.appInternalStates.get(appId) ?? {}),
leaveHandler: handler,
});
};

private setAppActionMenu = (appId: string, mount: MountPoint | undefined) => {
this.appInternalStates.set(appId, {
...(this.appInternalStates.get(appId) ?? {}),
actionMenu: mount,
});
this.refreshCurrentActionMenu();
};

private refreshCurrentActionMenu = () => {
const appId = this.currentAppId$.getValue();
const currentActionMenu = appId ? this.appInternalStates.get(appId)?.actionMenu : undefined;
this.currentActionMenu$.next(currentActionMenu);
};

private async shouldNavigate(overlays: OverlayStart): Promise<boolean> {
const currentAppId = this.currentAppId$.value;
if (currentAppId === undefined) {
return true;
}
const action = getLeaveAction(this.appLeaveHandlers.get(currentAppId));
const action = getLeaveAction(this.appInternalStates.get(currentAppId)?.leaveHandler);
if (isConfirmAction(action)) {
const confirmed = await overlays.openConfirm(action.text, {
title: action.title,
Expand All @@ -372,7 +403,7 @@ export class ApplicationService {
if (currentAppId === undefined) {
return;
}
const action = getLeaveAction(this.appLeaveHandlers.get(currentAppId));
const action = getLeaveAction(this.appInternalStates.get(currentAppId)?.leaveHandler);
if (isConfirmAction(action)) {
event.preventDefault();
// some browsers accept a string return value being the message displayed
Expand All @@ -383,6 +414,7 @@ export class ApplicationService {
public stop() {
this.stop$.next();
this.currentAppId$.complete();
this.currentActionMenu$.complete();
this.statusUpdaters$.complete();
this.subscriptions.forEach((sub) => sub.unsubscribe());
window.removeEventListener('beforeunload', this.onBeforeUnload);
Expand Down
Loading

0 comments on commit c09a5be

Please sign in to comment.