Skip to content

Commit

Permalink
Merge branch 'master' of github.com:elastic/kibana into telemetry/aut…
Browse files Browse the repository at this point in the history
…omate_mapping
  • Loading branch information
Bamieh committed Jun 24, 2020
2 parents bf590ee + b614dbc commit 32664b9
Show file tree
Hide file tree
Showing 91 changed files with 4,131 additions and 1,053 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
fieldFormats: {
FieldFormat: typeof FieldFormat;
FieldFormatsRegistry: typeof FieldFormatsRegistry;
serialize: (agg: import("./search").AggConfig) => import("../../expressions").SerializedFieldFormat<object>;
DEFAULT_CONVERTER_COLOR: {
range: string;
regex: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
fieldFormats: {
FieldFormatsRegistry: typeof FieldFormatsRegistry;
FieldFormat: typeof FieldFormat;
serializeFieldFormat: (agg: import("../public/search").AggConfig) => import("../../expressions").SerializedFieldFormat<object>;
BoolFormat: typeof BoolFormat;
BytesFormat: typeof BytesFormat;
ColorFormat: typeof ColorFormat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
setup(core: CoreSetup<object, DataPluginStart>, { usageCollection }: DataPluginSetupDependencies): {
search: ISearchSetup;
fieldFormats: {
register: (customFieldFormat: import("../public").FieldFormatInstanceType) => number;
register: (customFieldFormat: import("../common").FieldFormatInstanceType) => number;
};
};
```
Expand All @@ -27,7 +27,7 @@ setup(core: CoreSetup<object, DataPluginStart>, { usageCollection }: DataPluginS
`{
search: ISearchSetup;
fieldFormats: {
register: (customFieldFormat: import("../public").FieldFormatInstanceType) => number;
register: (customFieldFormat: import("../common").FieldFormatInstanceType) => number;
};
}`

21 changes: 0 additions & 21 deletions src/legacy/ui/public/visualize/loader/pipeline_helpers/index.ts

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion src/plugins/data/common/field_formats/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export {
TruncateFormat,
} from './converters';

export { getHighlightRequest, serializeFieldFormat } from './utils';
export { getHighlightRequest } from './utils';

export { DEFAULT_CONVERTER_COLOR } from './constants/color_default';
export { FIELD_FORMAT_IDS } from './types';
Expand Down
1 change: 0 additions & 1 deletion src/plugins/data/common/field_formats/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@ import { IFieldFormat } from '../index';

export { asPrettyString } from './as_pretty_string';
export { getHighlightHtml, getHighlightRequest } from './highlight';
export { serializeFieldFormat } from './serialize';

export type FormatFactory = (mapping?: SerializedFieldFormat) => IFieldFormat;
53 changes: 0 additions & 53 deletions src/plugins/data/common/field_formats/utils/serialize.ts

This file was deleted.

107 changes: 21 additions & 86 deletions src/plugins/data/public/field_formats/utils/deserialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,107 +18,42 @@
*/

import { identity } from 'lodash';
import { i18n } from '@kbn/i18n';
import { convertDateRangeToString, DateRangeKey } from '../../search/aggs/buckets/lib/date_range';
import { convertIPRangeToString, IpRangeKey } from '../../search/aggs/buckets/lib/ip_range';

import { SerializedFieldFormat } from '../../../../expressions/common/types';
import { FieldFormatId, FieldFormatsContentType, IFieldFormat } from '../..';

import { FieldFormat } from '../../../common';
import { DataPublicPluginStart } from '../../../public';
import { getUiSettings } from '../../../public/services';
import { FormatFactory } from '../../../common/field_formats/utils';

interface TermsFieldFormatParams {
otherBucketLabel: string;
missingBucketLabel: string;
id: string;
}

function isTermsFieldFormat(
serializedFieldFormat: SerializedFieldFormat
): serializedFieldFormat is SerializedFieldFormat<TermsFieldFormatParams> {
return serializedFieldFormat.id === 'terms';
}
import { DataPublicPluginStart, IFieldFormat } from '../../../public';
import { getUiSettings } from '../../../public/services';
import { getFormatWithAggs } from '../../search/aggs/utils';

const getConfig = (key: string, defaultOverride?: any): any =>
getUiSettings().get(key, defaultOverride);
const DefaultFieldFormat = FieldFormat.from(identity);

const getFieldFormat = (
fieldFormatsService: DataPublicPluginStart['fieldFormats'],
id?: FieldFormatId,
params: object = {}
): IFieldFormat => {
if (id) {
const Format = fieldFormatsService.getType(id);

if (Format) {
return new Format(params, getConfig);
}
}

return new DefaultFieldFormat();
};

export const deserializeFieldFormat: FormatFactory = function (
this: DataPublicPluginStart['fieldFormats'],
mapping?: SerializedFieldFormat
serializedFieldFormat?: SerializedFieldFormat
) {
if (!mapping) {
if (!serializedFieldFormat) {
return new DefaultFieldFormat();
}
const { id } = mapping;
if (id === 'range') {
const RangeFormat = FieldFormat.from((range: any) => {
const nestedFormatter = mapping.params as SerializedFieldFormat;
const format = getFieldFormat(this, nestedFormatter.id, nestedFormatter.params);
const gte = '\u2265';
const lt = '\u003c';
return i18n.translate('data.aggTypes.buckets.ranges.rangesFormatMessage', {
defaultMessage: '{gte} {from} and {lt} {to}',
values: {
gte,
from: format.convert(range.gte),
lt,
to: format.convert(range.lt),
},
});
});
return new RangeFormat();
} else if (id === 'date_range') {
const nestedFormatter = mapping.params as SerializedFieldFormat;
const DateRangeFormat = FieldFormat.from((range: DateRangeKey) => {
const format = getFieldFormat(this, nestedFormatter.id, nestedFormatter.params);
return convertDateRangeToString(range, format.convert.bind(format));
});
return new DateRangeFormat();
} else if (id === 'ip_range') {
const nestedFormatter = mapping.params as SerializedFieldFormat;
const IpRangeFormat = FieldFormat.from((range: IpRangeKey) => {
const format = getFieldFormat(this, nestedFormatter.id, nestedFormatter.params);
return convertIPRangeToString(range, format.convert.bind(format));
});
return new IpRangeFormat();
} else if (isTermsFieldFormat(mapping) && mapping.params) {
const { params } = mapping;
const convert = (val: string, type: FieldFormatsContentType) => {
const format = getFieldFormat(this, params.id, mapping.params);

if (val === '__other__') {
return params.otherBucketLabel;
}
if (val === '__missing__') {
return params.missingBucketLabel;
const getFormat = (mapping: SerializedFieldFormat): IFieldFormat => {
const { id, params = {} } = mapping;
if (id) {
const Format = this.getType(id);

if (Format) {
return new Format(params, getConfig);
}
}

return new DefaultFieldFormat();
};

return format.convert(val, type);
};
// decorate getFormat to handle custom types created by aggs
const getFieldFormat = getFormatWithAggs(getFormat);

return {
convert,
getConverterFor: (type: FieldFormatsContentType) => (val: string) => convert(val, type),
} as IFieldFormat;
} else {
return getFieldFormat(this, id, mapping.params);
}
return getFieldFormat(serializedFieldFormat);
};
3 changes: 0 additions & 3 deletions src/plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ import {
UrlFormat,
StringFormat,
TruncateFormat,
serializeFieldFormat,
} from '../common/field_formats';

import { DateFormat } from './field_formats';
Expand All @@ -179,8 +178,6 @@ export const fieldFormats = {
FieldFormat,
FieldFormatsRegistry, // exported only for tests. Consider mock.

serialize: serializeFieldFormat,

DEFAULT_CONVERTER_COLOR,
HTML_CONTEXT_TYPE,
TEXT_CONTEXT_TYPE,
Expand Down
Loading

0 comments on commit 32664b9

Please sign in to comment.