Skip to content

Commit

Permalink
Merge branch 'master' into capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Apr 24, 2020
2 parents 4a06642 + 6bb7515 commit af4271e
Show file tree
Hide file tree
Showing 93 changed files with 168 additions and 236 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
/src/plugins/vis_type_timelion/ @elastic/kibana-app
/src/plugins/dashboard/ @elastic/kibana-app
/src/plugins/discover/ @elastic/kibana-app
/src/plugins/input_control_vis/ @elastic/kibana-app
/src/plugins/visualize/ @elastic/kibana-app
/src/plugins/vis_type_timeseries/ @elastic/kibana-app
/src/plugins/vis_type_metric/ @elastic/kibana-app
Expand Down
2 changes: 1 addition & 1 deletion .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"esUi": "src/plugins/es_ui_shared",
"devTools": "src/plugins/dev_tools",
"expressions": "src/plugins/expressions",
"inputControl": "src/legacy/core_plugins/input_control_vis",
"inputControl": "src/plugins/input_control_vis",
"inspector": "src/plugins/inspector",
"inspectorViews": "src/legacy/core_plugins/inspector_views",
"interpreter": "src/legacy/core_plugins/interpreter",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<b>Signature:</b>

```typescript
baseFormattersPublic: (import("../../common").IFieldFormatType | typeof DateFormat)[]
baseFormattersPublic: (import("../../common").FieldFormatInstanceType | typeof DateFormat)[]
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
```typescript
setup(core: CoreSetup, { usageCollection }: DataPluginSetupDependencies): {
fieldFormats: {
register: (customFieldFormat: import("../common").IFieldFormatType) => number;
register: (customFieldFormat: import("../common").FieldFormatInstanceType) => number;
};
search: ISearchSetup;
};
Expand All @@ -26,7 +26,7 @@ setup(core: CoreSetup, { usageCollection }: DataPluginSetupDependencies): {

`{
fieldFormats: {
register: (customFieldFormat: import("../common").IFieldFormatType) => number;
register: (customFieldFormat: import("../common").FieldFormatInstanceType) => number;
};
search: ISearchSetup;
}`
Expand Down
44 changes: 0 additions & 44 deletions src/legacy/core_plugins/input_control_vis/index.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/legacy/core_plugins/input_control_vis/package.json

This file was deleted.

45 changes: 0 additions & 45 deletions src/legacy/core_plugins/input_control_vis/public/legacy.ts

This file was deleted.

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

27 changes: 27 additions & 0 deletions src/plugins/data/common/es_query/kuery/ast/ast.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,33 @@ describe('kuery AST API', () => {
expect(fromLiteralExpression('true')).toEqual(booleanTrueLiteral);
expect(fromLiteralExpression('false')).toEqual(booleanFalseLiteral);
expect(fromLiteralExpression('42')).toEqual(numberLiteral);

expect(fromLiteralExpression('.3').value).toEqual(0.3);
expect(fromLiteralExpression('.36').value).toEqual(0.36);
expect(fromLiteralExpression('.00001').value).toEqual(0.00001);
expect(fromLiteralExpression('3').value).toEqual(3);
expect(fromLiteralExpression('-4').value).toEqual(-4);
expect(fromLiteralExpression('0').value).toEqual(0);
expect(fromLiteralExpression('0.0').value).toEqual(0);
expect(fromLiteralExpression('2.0').value).toEqual(2.0);
expect(fromLiteralExpression('0.8').value).toEqual(0.8);
expect(fromLiteralExpression('790.9').value).toEqual(790.9);
expect(fromLiteralExpression('0.0001').value).toEqual(0.0001);
expect(fromLiteralExpression('96565646732345').value).toEqual(96565646732345);

expect(fromLiteralExpression('..4').value).toEqual('..4');
expect(fromLiteralExpression('.3text').value).toEqual('.3text');
expect(fromLiteralExpression('text').value).toEqual('text');
expect(fromLiteralExpression('.').value).toEqual('.');
expect(fromLiteralExpression('-').value).toEqual('-');
expect(fromLiteralExpression('001').value).toEqual('001');
expect(fromLiteralExpression('00.2').value).toEqual('00.2');
expect(fromLiteralExpression('0.0.1').value).toEqual('0.0.1');
expect(fromLiteralExpression('3.').value).toEqual('3.');
expect(fromLiteralExpression('--4').value).toEqual('--4');
expect(fromLiteralExpression('-.4').value).toEqual('-.4');
expect(fromLiteralExpression('-0').value).toEqual('-0');
expect(fromLiteralExpression('00949').value).toEqual('00949');
});

test('should allow escaping of special characters with a backslash', () => {
Expand Down
5 changes: 2 additions & 3 deletions src/plugins/data/common/es_query/kuery/ast/kuery.peg
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,8 @@ UnquotedLiteral
if (sequence === 'true') return buildLiteralNode(true);
if (sequence === 'false') return buildLiteralNode(false);
if (chars.includes(wildcardSymbol)) return buildWildcardNode(sequence);
const number = Number(sequence);
const value = isNaN(number) ? sequence : number;
return buildLiteralNode(value);
const isNumberPattern = /^(-?[1-9]+\d*([.]\d+)?)$|^(-?0[.]\d*[1-9]+)$|^0$|^0.0$|^[.]\d{1,}$/
return buildLiteralNode(isNumberPattern.test(sequence) ? Number(sequence) : sequence);
}

UnquotedCharacter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { IFieldFormatType } from '../types';
import { FieldFormatInstanceType } from '../types';

import {
BoolFormat,
Expand All @@ -36,7 +36,7 @@ import {
UrlFormat,
} from '../converters';

export const baseFormatters: IFieldFormatType[] = [
export const baseFormatters: FieldFormatInstanceType[] = [
BoolFormat,
BytesFormat,
ColorFormat,
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/data/common/field_formats/converters/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/

import { FieldFormat } from '../field_format';
import { TextContextTypeConvert, FIELD_FORMAT_IDS, IFieldFormatType } from '../types';
import { TextContextTypeConvert, FIELD_FORMAT_IDS, FieldFormatInstanceType } from '../types';

export const createCustomFieldFormat = (convert: TextContextTypeConvert): IFieldFormatType =>
export const createCustomFieldFormat = (convert: TextContextTypeConvert): FieldFormatInstanceType =>
class CustomFieldFormat extends FieldFormat {
static id = FIELD_FORMAT_IDS.CUSTOM;

Expand Down
4 changes: 2 additions & 2 deletions src/plugins/data/common/field_formats/field_format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { createCustomFieldFormat } from './converters/custom';
import {
FieldFormatsGetConfigFn,
FieldFormatsContentType,
IFieldFormatType,
FieldFormatInstanceType,
FieldFormatConvert,
FieldFormatConvertFunction,
HtmlContextTypeOptions,
Expand Down Expand Up @@ -199,7 +199,7 @@ export abstract class FieldFormat {
};
}

static from(convertFn: FieldFormatConvertFunction): IFieldFormatType {
static from(convertFn: FieldFormatConvertFunction): FieldFormatInstanceType {
return createCustomFieldFormat(convertFn);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
import { FieldFormatsRegistry } from './field_formats_registry';
import { BoolFormat, PercentFormat, StringFormat } from './converters';
import { FieldFormatsGetConfigFn, IFieldFormatType } from './types';
import { FieldFormatsGetConfigFn, FieldFormatInstanceType } from './types';
import { KBN_FIELD_TYPES } from '../../common';

const getValueOfPrivateField = (instance: any, field: string) => instance[field];
Expand Down Expand Up @@ -75,10 +75,10 @@ describe('FieldFormatsRegistry', () => {
test('should register field formats', () => {
fieldFormatsRegistry.register([StringFormat, BoolFormat]);

const registeredFieldFormatters: Map<string, IFieldFormatType> = getValueOfPrivateField(
fieldFormatsRegistry,
'fieldFormats'
);
const registeredFieldFormatters: Map<
string,
FieldFormatInstanceType
> = getValueOfPrivateField(fieldFormatsRegistry, 'fieldFormats');

expect(registeredFieldFormatters.size).toBe(2);

Expand Down
40 changes: 21 additions & 19 deletions src/plugins/data/common/field_formats/field_formats_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
FieldFormatsGetConfigFn,
FieldFormatConfig,
FIELD_FORMAT_IDS,
IFieldFormatType,
FieldFormatInstanceType,
FieldFormatId,
IFieldFormatMetaParams,
IFieldFormat,
Expand All @@ -35,7 +35,7 @@ import { SerializedFieldFormat } from '../../../expressions/common/types';
import { ES_FIELD_TYPES, KBN_FIELD_TYPES } from '../types';

export class FieldFormatsRegistry {
protected fieldFormats: Map<FieldFormatId, IFieldFormatType> = new Map();
protected fieldFormats: Map<FieldFormatId, FieldFormatInstanceType> = new Map();
protected defaultMap: Record<string, FieldFormatConfig> = {};
protected metaParamsOptions: Record<string, any> = {};
protected getConfig?: FieldFormatsGetConfigFn;
Expand All @@ -47,7 +47,7 @@ export class FieldFormatsRegistry {
init(
getConfig: FieldFormatsGetConfigFn,
metaParamsOptions: Record<string, any> = {},
defaultFieldConverters: IFieldFormatType[] = baseFormatters
defaultFieldConverters: FieldFormatInstanceType[] = baseFormatters
) {
const defaultTypeMap = getConfig('format:defaultTypeMap');
this.register(defaultFieldConverters);
Expand Down Expand Up @@ -79,23 +79,23 @@ export class FieldFormatsRegistry {
* Get a derived FieldFormat class by its id.
*
* @param {FieldFormatId} formatId - the format id
* @return {IFieldFormatType | undefined}
* @return {FieldFormatInstanceType | undefined}
*/
getType = (formatId: FieldFormatId): IFieldFormatType | undefined => {
getType = (formatId: FieldFormatId): FieldFormatInstanceType | undefined => {
const fieldFormat = this.fieldFormats.get(formatId);

if (fieldFormat) {
const decoratedFieldFormat: any = this.fieldFormatMetaParamsDecorator(fieldFormat);

if (decoratedFieldFormat) {
return decoratedFieldFormat as IFieldFormatType;
return decoratedFieldFormat as FieldFormatInstanceType;
}
}

return undefined;
};

getTypeWithoutMetaParams = (formatId: FieldFormatId): IFieldFormatType | undefined => {
getTypeWithoutMetaParams = (formatId: FieldFormatId): FieldFormatInstanceType | undefined => {
return this.fieldFormats.get(formatId);
};

Expand All @@ -106,12 +106,12 @@ export class FieldFormatsRegistry {
*
* @param {KBN_FIELD_TYPES} fieldType
* @param {ES_FIELD_TYPES[]} esTypes - Array of ES data types
* @return {IFieldFormatType | undefined}
* @return {FieldFormatInstanceType | undefined}
*/
getDefaultType = (
fieldType: KBN_FIELD_TYPES,
esTypes: ES_FIELD_TYPES[]
): IFieldFormatType | undefined => {
): FieldFormatInstanceType | undefined => {
const config = this.getDefaultConfig(fieldType, esTypes);

return this.getType(config.id);
Expand Down Expand Up @@ -206,14 +206,16 @@ export class FieldFormatsRegistry {
* Get filtered list of field formats by format type
*
* @param {KBN_FIELD_TYPES} fieldType
* @return {IFieldFormatType[]}
* @return {FieldFormatInstanceType[]}
*/
getByFieldType(fieldType: KBN_FIELD_TYPES): IFieldFormatType[] {
getByFieldType(fieldType: KBN_FIELD_TYPES): FieldFormatInstanceType[] {
return [...this.fieldFormats.values()]
.filter((format: IFieldFormatType) => format && format.fieldType.indexOf(fieldType) !== -1)
.filter(
(format: FieldFormatInstanceType) => format && format.fieldType.indexOf(fieldType) !== -1
)
.map(
(format: IFieldFormatType) =>
this.fieldFormatMetaParamsDecorator(format) as IFieldFormatType
(format: FieldFormatInstanceType) =>
this.fieldFormatMetaParamsDecorator(format) as FieldFormatInstanceType
);
}

Expand All @@ -238,20 +240,20 @@ export class FieldFormatsRegistry {
});
}

register(fieldFormats: IFieldFormatType[]) {
register(fieldFormats: FieldFormatInstanceType[]) {
fieldFormats.forEach(fieldFormat => this.fieldFormats.set(fieldFormat.id, fieldFormat));
}

/**
* FieldFormat decorator - provide a one way to add meta-params for all field formatters
*
* @private
* @param {IFieldFormatType} fieldFormat - field format type
* @return {IFieldFormatType | undefined}
* @param {FieldFormatInstanceType} fieldFormat - field format type
* @return {FieldFormatInstanceType | undefined}
*/
private fieldFormatMetaParamsDecorator = (
fieldFormat: IFieldFormatType
): IFieldFormatType | undefined => {
fieldFormat: FieldFormatInstanceType
): FieldFormatInstanceType | undefined => {
const getMetaParams = (customParams: Record<string, any>) => this.buildMetaParams(customParams);

if (fieldFormat) {
Expand Down
Loading

0 comments on commit af4271e

Please sign in to comment.