Skip to content

Commit d30dd2a

Browse files
committed
Merge remote-tracking branch 'upstream/master' into docs/testing
2 parents e444eee + 2ddaddc commit d30dd2a

File tree

16 files changed

+1350
-185
lines changed

16 files changed

+1350
-185
lines changed

STYLEGUIDE.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ remove it, don't simply comment it out.
3535

3636
We are gradually moving the Kibana code base over to Prettier. All TypeScript code
3737
and some JavaScript code (check `.eslintrc.js`) is using Prettier to format code. You
38-
can run `node script/eslint --fix` to fix linting issues and apply Prettier formatting.
38+
can run `node scripts/eslint --fix` to fix linting issues and apply Prettier formatting.
3939
We recommend you to enable running ESLint via your IDE.
4040

4141
Whenever possible we are trying to use Prettier and linting over written style guide rules.

dev_docs/best_practices.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ Kibana is translated into other languages. Use our i18n utilities to ensure your
171171

172172
## Styleguide
173173

174-
We use es-lint rules when possible, but please review our [styleguide](https://github.com/elastic/kibana/blob/master/STYLEGUIDE.md), which includes recommendations that can't be linted on.
174+
We use es-lint rules when possible, but please review our [styleguide](https://github.com/elastic/kibana/blob/master/STYLEGUIDE.mdx), which includes recommendations that can't be linted on.
175175

176176
Es-lint overrides on a per-plugin level are discouraged.
177177

docs/developer/best-practices/index.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ guidelines]
4545
=== Conventions
4646

4747
* Become familiar with our
48-
{kib-repo}blob/{branch}/STYLEGUIDE.md[styleguide]
48+
{kib-repo}blob/{branch}/STYLEGUIDE.mdx[styleguide]
4949
(use Typescript!)
5050
* Write all new code on
5151
{kib-repo}blob/{branch}/src/core/README.md[the

docs/developer/contributing/linting.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
== Linting
33

44
A note about linting: We use http://eslint.org[eslint] to check that the
5-
link:STYLEGUIDE.md[styleguide] is being followed. It runs in a
5+
link:STYLEGUIDE.mdx[styleguide] is being followed. It runs in a
66
pre-commit hook and as a part of the tests, but most contributors
77
integrate it with their code editors for real-time feedback.
88

docs/developer/contributing/pr-review.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Reviewers are not simply evaluating the code itself, they are also evaluating th
7575

7676
Having a relatively consistent codebase is an important part of us building a sustainable project. With dozens of active contributors at any given time, we rely on automation to help ensure consistency - we enforce a comprehensive set of linting rules through CI. We're also rolling out prettier to make this even more automatic.
7777

78-
For things that can't be easily automated, we maintain a link:{kib-repo}tree/{branch}/STYLEGUIDE.md[style guide] that authors should adhere to and reviewers should keep in mind when they review a pull request.
78+
For things that can't be easily automated, we maintain a link:{kib-repo}tree/{branch}/STYLEGUIDE.mdx[style guide] that authors should adhere to and reviewers should keep in mind when they review a pull request.
7979

8080
Beyond that, we're into subjective territory. Statements like "this isn't very readable" are hardly helpful since they can't be qualified, but that doesn't mean a reviewer should outright ignore code that is hard to understand due to how it is written. There isn't one definitively "best" way to write any particular code, so pursuing such shouldn't be our goal. Instead, reviewers and authors alike must accept that there are likely many different appropriate ways to accomplish the same thing with code, and so long as the contribution is utilizing one of those ways, then we're in good shape.
8181

examples/routing_example/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ Read more:
66

77
- [IRouter API Docs](../../docs/development/core/server/kibana-plugin-core-server.irouter.md)
88
- [HttpHandler (core.http.fetch) API Docs](../../docs/development/core/public/kibana-plugin-core-public.httphandler.md)
9-
- [Routing Conventions](../../STYLEGUIDE.md#api-endpoints)
9+
- [Routing Conventions](../../STYLEGUIDE.mdx#api-endpoints)

examples/routing_example/public/app.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ function RoutingExplorer({
6363
},
6464
{
6565
label: 'Conventions',
66-
href: 'https://github.com/elastic/kibana/tree/master/STYLEGUIDE.md#api-endpoints',
66+
href:
67+
'https://github.com/elastic/kibana/tree/master/STYLEGUIDE.mdx#api-endpoints',
6768
iconType: 'logoGithub',
6869
target: '_blank',
6970
size: 's',

src/plugins/home/server/services/sample_data/data_sets/ecommerce/saved_objects.ts

Lines changed: 1226 additions & 143 deletions
Large diffs are not rendered by default.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
import { extendSearchParamsWithRuntimeFields } from './search_api';
10+
import { dataPluginMock } from '../../../data/public/mocks';
11+
12+
import { getSearchParamsFromRequest, DataPublicPluginStart } from '../../../data/public';
13+
14+
const mockComputedFields = (
15+
dataStart: DataPublicPluginStart,
16+
index: string,
17+
runtimeFields: Record<string, unknown>
18+
) => {
19+
dataStart.indexPatterns.find = jest.fn().mockReturnValue([
20+
{
21+
title: index,
22+
getComputedFields: () => ({
23+
runtimeFields,
24+
}),
25+
},
26+
]);
27+
};
28+
29+
describe('extendSearchParamsWithRuntimeFields', () => {
30+
let dataStart: DataPublicPluginStart;
31+
32+
beforeEach(() => {
33+
dataStart = dataPluginMock.createStartContract();
34+
});
35+
36+
test('should inject default runtime_mappings for known indexes', async () => {
37+
const requestParams = {};
38+
const runtimeFields = { foo: {} };
39+
40+
mockComputedFields(dataStart, 'index', runtimeFields);
41+
42+
expect(
43+
await extendSearchParamsWithRuntimeFields(dataStart.indexPatterns, requestParams, 'index')
44+
).toMatchInlineSnapshot(`
45+
Object {
46+
"body": Object {
47+
"runtime_mappings": Object {
48+
"foo": Object {},
49+
},
50+
},
51+
}
52+
`);
53+
});
54+
55+
test('should use runtime mappings from spec if it is specified', async () => {
56+
const requestParams = ({
57+
body: {
58+
runtime_mappings: {
59+
test: {},
60+
},
61+
},
62+
} as unknown) as ReturnType<typeof getSearchParamsFromRequest>;
63+
const runtimeFields = { foo: {} };
64+
65+
mockComputedFields(dataStart, 'index', runtimeFields);
66+
67+
expect(
68+
await extendSearchParamsWithRuntimeFields(dataStart.indexPatterns, requestParams, 'index')
69+
).toMatchInlineSnapshot(`
70+
Object {
71+
"body": Object {
72+
"runtime_mappings": Object {
73+
"test": Object {},
74+
},
75+
},
76+
}
77+
`);
78+
});
79+
});

src/plugins/vis_type_vega/public/data_model/search_api.ts

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,36 @@
88

99
import { combineLatest, from } from 'rxjs';
1010
import { map, tap, switchMap } from 'rxjs/operators';
11-
import { CoreStart, IUiSettingsClient } from 'kibana/public';
12-
import { getData } from '../services';
11+
import type { CoreStart, IUiSettingsClient } from 'kibana/public';
1312
import {
1413
getSearchParamsFromRequest,
1514
SearchRequest,
1615
DataPublicPluginStart,
1716
IEsSearchResponse,
1817
} from '../../../data/public';
1918
import { search as dataPluginSearch } from '../../../data/public';
20-
import { VegaInspectorAdapters } from '../vega_inspector';
21-
import { RequestResponder } from '../../../inspector/public';
19+
import type { VegaInspectorAdapters } from '../vega_inspector';
20+
import type { RequestResponder } from '../../../inspector/public';
2221

23-
const extendSearchParamsWithRuntimeFields = async (
22+
/** @internal **/
23+
export const extendSearchParamsWithRuntimeFields = async (
24+
indexPatterns: SearchAPIDependencies['indexPatterns'],
2425
requestParams: ReturnType<typeof getSearchParamsFromRequest>,
2526
indexPatternString?: string
2627
) => {
2728
if (indexPatternString) {
28-
const indexPattern = (await getData().indexPatterns.find(indexPatternString)).find(
29-
(index) => index.title === indexPatternString
30-
);
31-
const runtimeFields = indexPattern?.getComputedFields().runtimeFields;
29+
let runtimeMappings = requestParams.body?.runtime_mappings;
30+
31+
if (!runtimeMappings) {
32+
const indexPattern = (await indexPatterns.find(indexPatternString)).find(
33+
(index) => index.title === indexPatternString
34+
);
35+
runtimeMappings = indexPattern?.getComputedFields().runtimeFields;
36+
}
3237

3338
return {
3439
...requestParams,
35-
body: { ...requestParams.body, runtime_mappings: runtimeFields },
40+
body: { ...requestParams.body, runtime_mappings: runtimeMappings },
3641
};
3742
}
3843

@@ -43,6 +48,7 @@ export interface SearchAPIDependencies {
4348
uiSettings: IUiSettingsClient;
4449
injectedMetadata: CoreStart['injectedMetadata'];
4550
search: DataPublicPluginStart['search'];
51+
indexPatterns: DataPublicPluginStart['indexPatterns'];
4652
}
4753

4854
export class SearchAPI {
@@ -54,7 +60,7 @@ export class SearchAPI {
5460
) {}
5561

5662
search(searchRequests: SearchRequest[]) {
57-
const { search } = this.dependencies;
63+
const { search, indexPatterns } = this.dependencies;
5864
const requestResponders: any = {};
5965

6066
return combineLatest(
@@ -64,15 +70,19 @@ export class SearchAPI {
6470
getConfig: this.dependencies.uiSettings.get.bind(this.dependencies.uiSettings),
6571
});
6672

67-
if (this.inspectorAdapters) {
68-
requestResponders[requestId] = this.inspectorAdapters.requests.start(requestId, {
69-
...request,
70-
searchSessionId: this.searchSessionId,
71-
});
72-
requestResponders[requestId].json(requestParams.body);
73-
}
74-
75-
return from(extendSearchParamsWithRuntimeFields(requestParams, request.index)).pipe(
73+
return from(
74+
extendSearchParamsWithRuntimeFields(indexPatterns, requestParams, request.index)
75+
).pipe(
76+
tap((params) => {
77+
/** inspect request data **/
78+
if (this.inspectorAdapters) {
79+
requestResponders[requestId] = this.inspectorAdapters.requests.start(requestId, {
80+
...request,
81+
searchSessionId: this.searchSessionId,
82+
});
83+
requestResponders[requestId].json(params.body);
84+
}
85+
}),
7686
switchMap((params) =>
7787
search
7888
.search(

0 commit comments

Comments
 (0)