Skip to content

Commit

Permalink
Merge branch 'master' into chore/apollo-3
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Feb 26, 2020
2 parents 588feda + 08e27d0 commit 04f4975
Show file tree
Hide file tree
Showing 506 changed files with 6,077 additions and 3,270 deletions.
6 changes: 0 additions & 6 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,6 @@ module.exports = {
'react-hooks/exhaustive-deps': 'off',
},
},
{
files: ['src/legacy/core_plugins/vis_type_table/**/*.{js,ts,tsx}'],
rules: {
'react-hooks/exhaustive-deps': 'off',
},
},
{
files: [
'src/legacy/core_plugins/vis_default_editor/public/components/controls/**/*.{ts,tsx}',
Expand Down
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@
/x-pack/legacy/plugins/rollup/ @elastic/es-ui
/x-pack/plugins/searchprofiler/ @elastic/es-ui
/x-pack/legacy/plugins/snapshot_restore/ @elastic/es-ui
/x-pack/legacy/plugins/upgrade_assistant/ @elastic/es-ui
/x-pack/plugins/upgrade_assistant/ @elastic/es-ui
/x-pack/plugins/watcher/ @elastic/es-ui

# Endpoint
Expand Down
2 changes: 1 addition & 1 deletion docs/setup/settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ This setting does not impact <<tilemap, Coordinate map visualizations>> and <<re
use in <<regionmap, Region Map>> visualizations. Supported on {ece}. Each layer
object points to an external vector file that contains a geojson
FeatureCollection. The file must use the
https://en.wikipedia.org/wiki/World_Geodetic_System[WGS84 coordinate reference system]
https://en.wikipedia.org/wiki/World_Geodetic_System[WGS84 coordinate reference system (ESPG:4326)]
and only include polygons. If the file is hosted on a separate domain from
Kibana, the server needs to be CORS-enabled so Kibana can download the file.
The following example shows a valid regionmap configuration.
Expand Down
9 changes: 9 additions & 0 deletions examples/demo_search/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import { IKibanaSearchRequest, IKibanaSearchResponse } from '../../../src/plugins/data/public';

export const DEMO_SEARCH_STRATEGY = 'DEMO_SEARCH_STRATEGY';
export const ASYNC_DEMO_SEARCH_STRATEGY = 'ASYNC_DEMO_SEARCH_STRATEGY';

export interface IDemoRequest extends IKibanaSearchRequest {
mood: string | 'sad' | 'happy';
Expand All @@ -29,3 +30,11 @@ export interface IDemoRequest extends IKibanaSearchRequest {
export interface IDemoResponse extends IKibanaSearchResponse {
greeting: string;
}

export interface IAsyncDemoRequest extends IKibanaSearchRequest {
fibonacciNumbers: number;
}

export interface IAsyncDemoResponse extends IKibanaSearchResponse {
fibonacciSequence: number[];
}
2 changes: 1 addition & 1 deletion examples/demo_search/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "demoSearch",
"version": "0.0.1",
"kibanaVersion": "kibana",
"configPath": ["demo_search"],
"configPath": ["demoSearch"],
"server": true,
"ui": true,
"requiredPlugins": ["data"],
Expand Down
69 changes: 69 additions & 0 deletions examples/demo_search/public/async_demo_search_strategy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { Observable } from 'rxjs';
import {
ISearchContext,
TSearchStrategyProvider,
ISearchStrategy,
} from '../../../src/plugins/data/public';

import { ASYNC_DEMO_SEARCH_STRATEGY, IAsyncDemoResponse } from '../common';
import { ASYNC_SEARCH_STRATEGY } from '../../../x-pack/plugins/data_enhanced/public';

/**
* This demo search strategy provider simply provides a shortcut for calling the DEMO_ASYNC_SEARCH_STRATEGY
* on the server side, without users having to pass it in explicitly, and it takes advantage of the
* already registered ASYNC_SEARCH_STRATEGY that exists on the client.
*
* so instead of callers having to do:
*
* ```
* search(
* { ...request, serverStrategy: DEMO_ASYNC_SEARCH_STRATEGY },
* options,
* ASYNC_SEARCH_STRATEGY
* ) as Observable<IDemoResponse>,
*```
* They can instead just do
*
* ```
* search(request, options, DEMO_ASYNC_SEARCH_STRATEGY);
* ```
*
* and are ensured type safety in regard to the request and response objects.
*
* @param context - context supplied by other plugins.
* @param search - a search function to access other strategies that have already been registered.
*/
export const asyncDemoClientSearchStrategyProvider: TSearchStrategyProvider<typeof ASYNC_DEMO_SEARCH_STRATEGY> = (
context: ISearchContext
): ISearchStrategy<typeof ASYNC_DEMO_SEARCH_STRATEGY> => {
const asyncStrategyProvider = context.getSearchStrategy(ASYNC_SEARCH_STRATEGY);
const { search } = asyncStrategyProvider(context);
return {
search: (request, options) => {
return search(
{ ...request, serverStrategy: ASYNC_DEMO_SEARCH_STRATEGY },
options
) as Observable<IAsyncDemoResponse>;
},
};
};
2 changes: 1 addition & 1 deletion examples/demo_search/public/demo_search_strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { DEMO_SEARCH_STRATEGY, IDemoResponse } from '../common';
* ```
* context.search(request, options, DEMO_SEARCH_STRATEGY);
* ```
*
*
* and are ensured type safety in regard to the request and response objects.
*
* @param context - context supplied by other plugins.
Expand Down
17 changes: 15 additions & 2 deletions examples/demo_search/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@

import { DataPublicPluginSetup } from '../../../src/plugins/data/public';
import { Plugin, CoreSetup } from '../../../src/core/public';
import { DEMO_SEARCH_STRATEGY } from '../common';
import {
DEMO_SEARCH_STRATEGY,
IDemoRequest,
IDemoResponse,
ASYNC_DEMO_SEARCH_STRATEGY,
IAsyncDemoRequest,
IAsyncDemoResponse,
} from '../common';
import { demoClientSearchStrategyProvider } from './demo_search_strategy';
import { IDemoRequest, IDemoResponse } from '../common';
import { asyncDemoClientSearchStrategyProvider } from './async_demo_search_strategy';

interface DemoDataSearchSetupDependencies {
data: DataPublicPluginSetup;
Expand All @@ -39,10 +46,12 @@ interface DemoDataSearchSetupDependencies {
declare module '../../../src/plugins/data/public' {
export interface IRequestTypesMap {
[DEMO_SEARCH_STRATEGY]: IDemoRequest;
[ASYNC_DEMO_SEARCH_STRATEGY]: IAsyncDemoRequest;
}

export interface IResponseTypesMap {
[DEMO_SEARCH_STRATEGY]: IDemoResponse;
[ASYNC_DEMO_SEARCH_STRATEGY]: IAsyncDemoResponse;
}
}

Expand All @@ -52,6 +61,10 @@ export class DemoDataPlugin implements Plugin {
DEMO_SEARCH_STRATEGY,
demoClientSearchStrategyProvider
);
deps.data.search.registerSearchStrategyProvider(
ASYNC_DEMO_SEARCH_STRATEGY,
asyncDemoClientSearchStrategyProvider
);
}

public start() {}
Expand Down
60 changes: 60 additions & 0 deletions examples/demo_search/server/async_demo_search_strategy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { TSearchStrategyProvider } from '../../../src/plugins/data/server';
import { ASYNC_DEMO_SEARCH_STRATEGY } from '../common';

function getFibonacciSequence(n = 0) {
const beginning = [0, 1].slice(0, n);
return Array(Math.max(0, n))
.fill(null)
.reduce((sequence, value, i) => {
if (i < 2) return sequence;
return [...sequence, sequence[i - 1] + sequence[i - 2]];
}, beginning);
}

const generateId = (() => {
let id = 0;
return () => `${id++}`;
})();

const loadedMap = new Map<string, number>();
const totalMap = new Map<string, number>();

export const asyncDemoSearchStrategyProvider: TSearchStrategyProvider<typeof ASYNC_DEMO_SEARCH_STRATEGY> = () => {
return {
search: async request => {
const id = request.id ?? generateId();

const loaded = (loadedMap.get(id) ?? 0) + 1;
loadedMap.set(id, loaded);

const total = request.fibonacciNumbers ?? totalMap.get(id);
totalMap.set(id, total);

const fibonacciSequence = getFibonacciSequence(loaded);
return { id, total, loaded, fibonacciSequence };
},
cancel: async id => {
loadedMap.delete(id);
totalMap.delete(id);
},
};
};
17 changes: 16 additions & 1 deletion examples/demo_search/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@
import { Plugin, CoreSetup, PluginInitializerContext } from 'kibana/server';
import { PluginSetup as DataPluginSetup } from 'src/plugins/data/server';
import { demoSearchStrategyProvider } from './demo_search_strategy';
import { DEMO_SEARCH_STRATEGY, IDemoRequest, IDemoResponse } from '../common';
import {
DEMO_SEARCH_STRATEGY,
IDemoRequest,
IDemoResponse,
ASYNC_DEMO_SEARCH_STRATEGY,
IAsyncDemoRequest,
IAsyncDemoResponse,
} from '../common';
import { asyncDemoSearchStrategyProvider } from './async_demo_search_strategy';

interface IDemoSearchExplorerDeps {
data: DataPluginSetup;
Expand All @@ -38,10 +46,12 @@ interface IDemoSearchExplorerDeps {
declare module '../../../src/plugins/data/server' {
export interface IRequestTypesMap {
[DEMO_SEARCH_STRATEGY]: IDemoRequest;
[ASYNC_DEMO_SEARCH_STRATEGY]: IAsyncDemoRequest;
}

export interface IResponseTypesMap {
[DEMO_SEARCH_STRATEGY]: IDemoResponse;
[ASYNC_DEMO_SEARCH_STRATEGY]: IAsyncDemoResponse;
}
}

Expand All @@ -54,6 +64,11 @@ export class DemoDataPlugin implements Plugin<void, void, IDemoSearchExplorerDep
DEMO_SEARCH_STRATEGY,
demoSearchStrategyProvider
);
deps.data.search.registerSearchStrategyProvider(
this.initializerContext.opaqueId,
ASYNC_DEMO_SEARCH_STRATEGY,
asyncDemoSearchStrategyProvider
);
}

public start() {}
Expand Down
2 changes: 1 addition & 1 deletion examples/search_explorer/kibana.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id": "search_explorer",
"id": "searchExplorer",
"version": "0.0.1",
"kibanaVersion": "kibana",
"configPath": ["search_explorer"],
Expand Down
2 changes: 1 addition & 1 deletion examples/search_explorer/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "search_explorer",
"name": "searchExplorer",
"version": "1.0.0",
"main": "target/examples/search_explorer",
"kibana": {
Expand Down
6 changes: 6 additions & 0 deletions examples/search_explorer/public/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { AppMountParameters, CoreStart } from '../../../src/core/public';
import { EsSearchTest } from './es_strategy';
import { Page } from './page';
import { DemoStrategy } from './demo_strategy';
import { AsyncDemoStrategy } from './async_demo_strategy';
import { DocumentationPage } from './documentation';
import { SearchApiPage } from './search_api';
import { AppPluginStartDependencies, SearchBarComponentParams } from './types';
Expand Down Expand Up @@ -94,6 +95,11 @@ const SearchApp = ({ basename, data, application }: SearchBarComponentParams) =>
id: 'demoSearch',
component: <DemoStrategy search={data.search.search} />,
},
{
title: 'Async demo search strategy',
id: 'asyncDemoSearch',
component: <AsyncDemoStrategy search={data.search.search} />,
},
];

const routes = pages.map((page, i) => (
Expand Down
Loading

0 comments on commit 04f4975

Please sign in to comment.