Skip to content

Commit

Permalink
Merge branch 'master' into lens/97421/focus-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Jul 26, 2021
2 parents f04db4c + 6a50aff commit 68d3e6a
Show file tree
Hide file tree
Showing 192 changed files with 7,297 additions and 453 deletions.
1 change: 1 addition & 0 deletions .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"devTools": "src/plugins/dev_tools",
"expressions": "src/plugins/expressions",
"expressionError": "src/plugins/expression_error",
"expressionRepeatImage": "src/plugins/expression_repeat_image",
"expressionRevealImage": "src/plugins/expression_reveal_image",
"expressionShape": "src/plugins/expression_shape",
"inputControl": "src/plugins/input_control_vis",
Expand Down
2 changes: 1 addition & 1 deletion docs/developer/advanced/running-elasticsearch.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ See all available options, like how to specify a specific license, with the `--h
yarn es snapshot --help
----

`trial` will give you access to all capabilities.
`--license trial` will give you access to all capabilities.

**Keeping data between snapshots**

Expand Down
4 changes: 4 additions & 0 deletions docs/developer/plugin-list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ This API doesn't support angular, for registering angular dev tools, bootstrap a
|Expression Error plugin adds an error renderer to the expression plugin. The renderer will display the error image.
|{kib-repo}blob/{branch}/src/plugins/expression_repeat_image/README.md[expressionRepeatImage]
|Expression Repeat Image plugin adds a repeatImage function to the expression plugin and an associated renderer. The renderer will display the given image in mutliple instances.
|{kib-repo}blob/{branch}/src/plugins/expression_reveal_image/README.md[expressionRevealImage]
|Expression Reveal Image plugin adds a revealImage function to the expression plugin and an associated renderer. The renderer will display the given percentage of a given image.
Expand Down
3 changes: 2 additions & 1 deletion packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,6 @@ pageLoadAssetSize:
expressionRevealImage: 25675
cases: 144442
expressionError: 22127
userSetup: 18532
expressionRepeatImage: 22341
expressionShape: 30033
userSetup: 18532
1 change: 1 addition & 0 deletions src/dev/storybook/aliases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const storybookAliases = {
data_enhanced: 'x-pack/plugins/data_enhanced/.storybook',
embeddable: 'src/plugins/embeddable/.storybook',
expression_error: 'src/plugins/expression_error/.storybook',
expression_repeat_image: 'src/plugins/expression_repeat_image/.storybook',
expression_reveal_image: 'src/plugins/expression_reveal_image/.storybook',
expression_shape: 'src/plugins/expression_shape/.storybook',
infra: 'x-pack/plugins/infra/.storybook',
Expand Down
264 changes: 264 additions & 0 deletions src/plugins/data/common/search/expressions/kibana_context.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
/*
* 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 { FilterStateStore, buildFilter, FILTERS } from '@kbn/es-query';
import type { DeeplyMockedKeys } from '@kbn/utility-types/jest';
import type { ExecutionContext } from 'src/plugins/expressions/common';
import { KibanaContext } from './kibana_context_type';

import {
getKibanaContextFn,
ExpressionFunctionKibanaContext,
KibanaContextStartDependencies,
} from './kibana_context';

type StartServicesMock = DeeplyMockedKeys<KibanaContextStartDependencies>;

const createExecutionContextMock = (): DeeplyMockedKeys<ExecutionContext> => ({
abortSignal: {} as any,
getExecutionContext: jest.fn(),
getSearchContext: jest.fn(),
getSearchSessionId: jest.fn(),
inspectorAdapters: jest.fn(),
types: {},
variables: {},
getKibanaRequest: jest.fn(),
});

const emptyArgs = { q: null, timeRange: null, savedSearchId: null };

describe('kibanaContextFn', () => {
let kibanaContextFn: ExpressionFunctionKibanaContext;
let startServicesMock: StartServicesMock;

const getStartServicesMock = (): Promise<StartServicesMock> => Promise.resolve(startServicesMock);

beforeEach(async () => {
kibanaContextFn = getKibanaContextFn(getStartServicesMock);
startServicesMock = {
savedObjectsClient: {
create: jest.fn(),
delete: jest.fn(),
find: jest.fn(),
get: jest.fn(),
update: jest.fn(),
},
};
});

it('merges and deduplicates queries from different sources', async () => {
const { fn } = kibanaContextFn;
startServicesMock.savedObjectsClient.get.mockResolvedValue({
attributes: {
kibanaSavedObjectMeta: {
searchSourceJSON: JSON.stringify({
query: [
{
language: 'kuery',
query: {
match_phrase: {
DUPLICATE: 'DUPLICATE',
},
},
},
{
language: 'kuery',
query: {
match_phrase: {
DUPLICATE: 'DUPLICATE',
},
},
},
{
language: 'kuery',
query: {
match_phrase: {
test: 'something1',
},
},
},
],
}),
},
},
} as any);
const args = {
...emptyArgs,
q: {
type: 'kibana_query' as 'kibana_query',
language: 'test',
query: {
type: 'test',
match_phrase: {
test: 'something2',
},
},
},
savedSearchId: 'test',
};
const input: KibanaContext = {
type: 'kibana_context',
query: [
{
language: 'kuery',
query: [
// TODO: Is it expected that if we pass in an array that the values in the array are not deduplicated?
{
language: 'kuery',
query: {
match_phrase: {
DUPLICATE: 'DUPLICATE',
},
},
},
{
language: 'kuery',
query: {
match_phrase: {
DUPLICATE: 'DUPLICATE',
},
},
},
{
language: 'kuery',
query: {
match_phrase: {
test: 'something3',
},
},
},
],
},
],
timeRange: {
from: 'now-24h',
to: 'now',
},
};

const { query } = await fn(input, args, createExecutionContextMock());

expect(query).toEqual([
{
language: 'kuery',
query: [
{
language: 'kuery',
query: {
match_phrase: {
DUPLICATE: 'DUPLICATE',
},
},
},
{
language: 'kuery',
query: {
match_phrase: {
DUPLICATE: 'DUPLICATE',
},
},
},
{
language: 'kuery',
query: {
match_phrase: {
test: 'something3',
},
},
},
],
},
{
type: 'kibana_query',
language: 'test',
query: {
type: 'test',
match_phrase: {
test: 'something2',
},
},
},
{
language: 'kuery',
query: {
match_phrase: {
DUPLICATE: 'DUPLICATE',
},
},
},
{
language: 'kuery',
query: {
match_phrase: {
test: 'something1',
},
},
},
]);
});

it('deduplicates duplicated filters and keeps the first enabled filter', async () => {
const { fn } = kibanaContextFn;
const filter1 = buildFilter(
{ fields: [] },
{ name: 'test', type: 'test' },
FILTERS.PHRASE,
false,
true,
{
query: 'JetBeats',
},
null,
FilterStateStore.APP_STATE
);
const filter2 = buildFilter(
{ fields: [] },
{ name: 'test', type: 'test' },
FILTERS.PHRASE,
false,
false,
{
query: 'JetBeats',
},
null,
FilterStateStore.APP_STATE
);

const filter3 = buildFilter(
{ fields: [] },
{ name: 'test', type: 'test' },
FILTERS.PHRASE,
false,
false,
{
query: 'JetBeats',
},
null,
FilterStateStore.APP_STATE
);

const input: KibanaContext = {
type: 'kibana_context',
query: [
{
language: 'kuery',
query: '',
},
],
filters: [filter1, filter2, filter3],
timeRange: {
from: 'now-24h',
to: 'now',
},
};

const { filters } = await fn(input, emptyArgs, createExecutionContextMock());
expect(filters!.length).toBe(1);
expect(filters![0]).toBe(filter2);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export const getKibanaContextFn = (
return {
type: 'kibana_context',
query: queries,
filters: uniqFilters(filters).filter((f: any) => !f.meta?.disabled),
filters: uniqFilters(filters.filter((f: any) => !f.meta?.disabled)),
timeRange,
};
},
Expand Down
12 changes: 6 additions & 6 deletions src/plugins/expression_error/public/components/error/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import { i18n } from '@kbn/i18n';
import { get } from 'lodash';
import { ShowDebugging } from './show_debugging';

export interface Props {
payload: {
error: Error;
};
}

const strings = {
getDescription: () =>
i18n.translate('expressionError.errorComponent.description', {
Expand All @@ -23,12 +29,6 @@ const strings = {
}),
};

export interface Props {
payload: {
error: Error;
};
}

export const Error: FC<Props> = ({ payload }) => {
const message = get(payload, 'error.message');

Expand Down
10 changes: 10 additions & 0 deletions src/plugins/expression_repeat_image/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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.
*/

// eslint-disable-next-line import/no-commonjs
module.exports = require('@kbn/storybook').defaultConfig;
9 changes: 9 additions & 0 deletions src/plugins/expression_repeat_image/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# expressionRepeatImage

Expression Repeat Image plugin adds a `repeatImage` function to the expression plugin and an associated renderer. The renderer will display the given image in mutliple instances.

---

## Development

See the [kibana contributing guide](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md) for instructions setting up your development environment.
14 changes: 14 additions & 0 deletions src/plugins/expression_repeat_image/common/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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.
*/

export const PLUGIN_ID = 'expressionRepeatImage';
export const PLUGIN_NAME = 'expressionRepeatImage';

export const CONTEXT = '_context_';
export const BASE64 = '`base64`';
export const URL = 'URL';
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* 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 { repeatImageFunction } from './repeat_image_function';

export const functions = [repeatImageFunction];

export { repeatImageFunction };
Loading

0 comments on commit 68d3e6a

Please sign in to comment.