mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
* Field Formats namespace * Export IFieldFormatsRegistry and FieldFormatsRegistry separately. * remove field_formats export from data plugin and adjust lens test * Updated doc return types * Cleanup fieldFormat namespace and define it index.ts Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
5b55ee90b9
commit
7a9c5aa114
32 changed files with 267 additions and 182 deletions
|
@ -35,7 +35,7 @@ import { Schema } from './schemas';
|
|||
import {
|
||||
ISearchSource,
|
||||
FetchOptions,
|
||||
fieldFormats,
|
||||
FieldFormatsContentType,
|
||||
KBN_FIELD_TYPES,
|
||||
} from '../../../../../../plugins/data/public';
|
||||
|
||||
|
@ -383,7 +383,7 @@ export class AggConfig {
|
|||
return this.aggConfigs.timeRange;
|
||||
}
|
||||
|
||||
fieldFormatter(contentType?: fieldFormats.ContentType, defaultFormat?: any) {
|
||||
fieldFormatter(contentType?: FieldFormatsContentType, defaultFormat?: any) {
|
||||
const format = this.type && this.type.getFormat(this);
|
||||
|
||||
if (format) {
|
||||
|
@ -393,7 +393,7 @@ export class AggConfig {
|
|||
return this.fieldOwnFormatter(contentType, defaultFormat);
|
||||
}
|
||||
|
||||
fieldOwnFormatter(contentType?: fieldFormats.ContentType, defaultFormat?: any) {
|
||||
fieldOwnFormatter(contentType?: FieldFormatsContentType, defaultFormat?: any) {
|
||||
const fieldFormatsService = npStart.plugins.data.fieldFormats;
|
||||
const field = this.getField();
|
||||
let format = field && field.format;
|
||||
|
|
|
@ -29,7 +29,7 @@ import { BaseParamType } from './param_types/base';
|
|||
import { AggParamType } from './param_types/agg';
|
||||
import {
|
||||
KBN_FIELD_TYPES,
|
||||
fieldFormats,
|
||||
IFieldFormat,
|
||||
ISearchSource,
|
||||
} from '../../../../../../plugins/data/public';
|
||||
|
||||
|
@ -58,7 +58,7 @@ export interface AggTypeConfig<
|
|||
inspectorAdapters: Adapters,
|
||||
abortSignal?: AbortSignal
|
||||
) => Promise<any>;
|
||||
getFormat?: (agg: TAggConfig) => fieldFormats.FieldFormat;
|
||||
getFormat?: (agg: TAggConfig) => IFieldFormat;
|
||||
getValue?: (agg: TAggConfig, bucket: any) => any;
|
||||
getKey?: (bucket: any, key: any, agg: TAggConfig) => any;
|
||||
}
|
||||
|
@ -199,7 +199,7 @@ export class AggType<
|
|||
* @param {agg} agg - the agg to pick a format for
|
||||
* @return {FieldFormat}
|
||||
*/
|
||||
getFormat: (agg: TAggConfig) => fieldFormats.FieldFormat;
|
||||
getFormat: (agg: TAggConfig) => IFieldFormat;
|
||||
|
||||
getValue: (agg: TAggConfig, bucket: any) => any;
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
import moment from 'moment';
|
||||
import { createFilterDateRange } from './date_range';
|
||||
import { fieldFormats } from '../../../../../../../../plugins/data/public';
|
||||
import { fieldFormats, FieldFormatsGetConfigFn } from '../../../../../../../../plugins/data/public';
|
||||
import { AggConfigs } from '../../agg_configs';
|
||||
import { BUCKET_TYPES } from '../bucket_agg_types';
|
||||
import { IBucketAggConfig } from '../_bucket_agg_type';
|
||||
|
@ -28,7 +28,7 @@ jest.mock('ui/new_platform');
|
|||
|
||||
describe('AggConfig Filters', () => {
|
||||
describe('Date range', () => {
|
||||
const getConfig = (() => {}) as fieldFormats.GetConfigFn;
|
||||
const getConfig = (() => {}) as FieldFormatsGetConfigFn;
|
||||
const getAggConfigs = () => {
|
||||
const field = {
|
||||
name: '@timestamp',
|
||||
|
|
|
@ -20,13 +20,13 @@ import { createFilterHistogram } from './histogram';
|
|||
import { AggConfigs } from '../../agg_configs';
|
||||
import { BUCKET_TYPES } from '../bucket_agg_types';
|
||||
import { IBucketAggConfig } from '../_bucket_agg_type';
|
||||
import { fieldFormats } from '../../../../../../../../plugins/data/public';
|
||||
import { fieldFormats, FieldFormatsGetConfigFn } from '../../../../../../../../plugins/data/public';
|
||||
|
||||
jest.mock('ui/new_platform');
|
||||
|
||||
describe('AggConfig Filters', () => {
|
||||
describe('histogram', () => {
|
||||
const getConfig = (() => {}) as fieldFormats.GetConfigFn;
|
||||
const getConfig = (() => {}) as FieldFormatsGetConfigFn;
|
||||
const getAggConfigs = () => {
|
||||
const field = {
|
||||
name: 'bytes',
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
|
||||
import { createFilterRange } from './range';
|
||||
import { fieldFormats } from '../../../../../../../../plugins/data/public';
|
||||
import { fieldFormats, FieldFormatsGetConfigFn } from '../../../../../../../../plugins/data/public';
|
||||
import { AggConfigs } from '../../agg_configs';
|
||||
import { BUCKET_TYPES } from '../bucket_agg_types';
|
||||
import { IBucketAggConfig } from '../_bucket_agg_type';
|
||||
|
@ -27,7 +27,7 @@ jest.mock('ui/new_platform');
|
|||
|
||||
describe('AggConfig Filters', () => {
|
||||
describe('range', () => {
|
||||
const getConfig = (() => {}) as fieldFormats.GetConfigFn;
|
||||
const getConfig = (() => {}) as FieldFormatsGetConfigFn;
|
||||
const getAggConfigs = () => {
|
||||
const field = {
|
||||
name: 'bytes',
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
import { AggConfigs } from '../agg_configs';
|
||||
import { BUCKET_TYPES } from './bucket_agg_types';
|
||||
import { fieldFormats } from '../../../../../../../plugins/data/public';
|
||||
import { FieldFormatsGetConfigFn, fieldFormats } from '../../../../../../../plugins/data/public';
|
||||
|
||||
jest.mock('ui/new_platform');
|
||||
|
||||
|
@ -44,7 +44,7 @@ const buckets = [
|
|||
];
|
||||
|
||||
describe('Range Agg', () => {
|
||||
const getConfig = (() => {}) as fieldFormats.GetConfigFn;
|
||||
const getConfig = (() => {}) as FieldFormatsGetConfigFn;
|
||||
const getAggConfigs = () => {
|
||||
const field = {
|
||||
name: 'bytes',
|
||||
|
|
|
@ -30,7 +30,8 @@ import { IAggConfigs } from '../agg_configs';
|
|||
import { Adapters } from '../../../../../../../plugins/inspector/public';
|
||||
import {
|
||||
ISearchSource,
|
||||
fieldFormats,
|
||||
IFieldFormat,
|
||||
FieldFormatsContentType,
|
||||
KBN_FIELD_TYPES,
|
||||
} from '../../../../../../../plugins/data/public';
|
||||
|
||||
|
@ -80,9 +81,9 @@ export const termsBucketAgg = new BucketAggType({
|
|||
const params = agg.params;
|
||||
return agg.getFieldDisplayName() + ': ' + params.order.text;
|
||||
},
|
||||
getFormat(bucket): fieldFormats.FieldFormat {
|
||||
getFormat(bucket): IFieldFormat {
|
||||
return {
|
||||
getConverterFor: (type: fieldFormats.ContentType) => {
|
||||
getConverterFor: (type: FieldFormatsContentType) => {
|
||||
return (val: any) => {
|
||||
if (val === '__other__') {
|
||||
return bucket.params.otherBucketLabel;
|
||||
|
@ -94,7 +95,7 @@ export const termsBucketAgg = new BucketAggType({
|
|||
return bucket.params.field.format.convert(val, type);
|
||||
};
|
||||
},
|
||||
} as fieldFormats.FieldFormat;
|
||||
} as IFieldFormat;
|
||||
},
|
||||
createFilter: createFilterTerms,
|
||||
postFlightRequest: async (
|
||||
|
|
|
@ -24,7 +24,7 @@ import { isColorDark } from '@elastic/eui';
|
|||
|
||||
import { getFormat } from '../legacy_imports';
|
||||
import { MetricVisValue } from './metric_vis_value';
|
||||
import { fieldFormats } from '../../../../../plugins/data/public';
|
||||
import { FieldFormatsContentType, IFieldFormat } from '../../../../../plugins/data/public';
|
||||
import { Context } from '../metric_vis_fn';
|
||||
import { KibanaDatatable } from '../../../../../plugins/expressions/public';
|
||||
import { getHeatmapColors } from '../../../../../plugins/charts/public';
|
||||
|
@ -100,9 +100,9 @@ export class MetricVisComponent extends Component<MetricVisComponentProps> {
|
|||
}
|
||||
|
||||
private getFormattedValue = (
|
||||
fieldFormatter: fieldFormats.FieldFormat,
|
||||
fieldFormatter: IFieldFormat,
|
||||
value: any,
|
||||
format: fieldFormats.ContentType = 'text'
|
||||
format: FieldFormatsContentType = 'text'
|
||||
) => {
|
||||
if (isNaN(value)) return '-';
|
||||
return fieldFormatter.convert(value, format);
|
||||
|
@ -119,7 +119,7 @@ export class MetricVisComponent extends Component<MetricVisComponentProps> {
|
|||
const metrics: MetricVisMetric[] = [];
|
||||
|
||||
let bucketColumnId: string;
|
||||
let bucketFormatter: fieldFormats.FieldFormat;
|
||||
let bucketFormatter: IFieldFormat;
|
||||
|
||||
if (dimensions.bucket) {
|
||||
bucketColumnId = table.columns[dimensions.bucket.accessor].id;
|
||||
|
|
|
@ -22,7 +22,12 @@ import { identity } from 'lodash';
|
|||
import { IAggConfig } from 'ui/agg_types';
|
||||
import { npStart } from 'ui/new_platform';
|
||||
import { SerializedFieldFormat } from 'src/plugins/expressions/public';
|
||||
import { fieldFormats } from '../../../../../../plugins/data/public';
|
||||
import {
|
||||
fieldFormats,
|
||||
IFieldFormat,
|
||||
FieldFormatId,
|
||||
FieldFormatsContentType,
|
||||
} from '../../../../../../plugins/data/public';
|
||||
import { Vis } from '../../../../../core_plugins/visualizations/public';
|
||||
|
||||
import { tabifyGetColumns } from '../../../agg_response/tabify/_get_columns';
|
||||
|
@ -45,10 +50,7 @@ const getConfig = (key: string, defaultOverride?: any): any =>
|
|||
npStart.core.uiSettings.get(key, defaultOverride);
|
||||
const DefaultFieldFormat = fieldFormats.FieldFormat.from(identity);
|
||||
|
||||
const getFieldFormat = (
|
||||
id?: fieldFormats.IFieldFormatId,
|
||||
params: object = {}
|
||||
): fieldFormats.FieldFormat => {
|
||||
const getFieldFormat = (id?: FieldFormatId, params: object = {}): IFieldFormat => {
|
||||
const fieldFormatsService = npStart.plugins.data.fieldFormats;
|
||||
|
||||
if (id) {
|
||||
|
@ -94,7 +96,7 @@ export const createFormat = (agg: IAggConfig): SerializedFieldFormat => {
|
|||
return formats[agg.type.name] ? formats[agg.type.name]() : format;
|
||||
};
|
||||
|
||||
export type FormatFactory = (mapping?: SerializedFieldFormat) => fieldFormats.FieldFormat;
|
||||
export type FormatFactory = (mapping?: SerializedFieldFormat) => IFieldFormat;
|
||||
|
||||
export const getFormat: FormatFactory = mapping => {
|
||||
if (!mapping) {
|
||||
|
@ -133,7 +135,7 @@ export const getFormat: FormatFactory = mapping => {
|
|||
return new IpRangeFormat();
|
||||
} else if (isTermsFieldFormat(mapping) && mapping.params) {
|
||||
const { params } = mapping;
|
||||
const convert = (val: string, type: fieldFormats.ContentType) => {
|
||||
const convert = (val: string, type: FieldFormatsContentType) => {
|
||||
const format = getFieldFormat(params.id, mapping.params);
|
||||
|
||||
if (val === '__other__') {
|
||||
|
@ -148,8 +150,8 @@ export const getFormat: FormatFactory = mapping => {
|
|||
|
||||
return {
|
||||
convert,
|
||||
getConverterFor: (type: fieldFormats.ContentType) => (val: string) => convert(val, type),
|
||||
} as fieldFormats.FieldFormat;
|
||||
getConverterFor: (type: FieldFormatsContentType) => (val: string) => convert(val, type),
|
||||
} as IFieldFormat;
|
||||
} else {
|
||||
return getFieldFormat(id, mapping.params);
|
||||
}
|
||||
|
|
|
@ -17,10 +17,10 @@
|
|||
* under the License.
|
||||
*/
|
||||
import { escape, isFunction } from 'lodash';
|
||||
import { IFieldFormat, HtmlContextTypeConvert } from '../types';
|
||||
import { IFieldFormat, HtmlContextTypeConvert, FieldFormatsContentType } from '../types';
|
||||
import { asPrettyString, getHighlightHtml } from '../utils';
|
||||
|
||||
export const HTML_CONTEXT_TYPE = 'html';
|
||||
export const HTML_CONTEXT_TYPE: FieldFormatsContentType = 'html';
|
||||
|
||||
const getConvertFn = (
|
||||
format: IFieldFormat,
|
||||
|
|
|
@ -18,10 +18,10 @@
|
|||
*/
|
||||
|
||||
import { isFunction } from 'lodash';
|
||||
import { IFieldFormat, TextContextTypeConvert } from '../types';
|
||||
import { IFieldFormat, TextContextTypeConvert, FieldFormatsContentType } from '../types';
|
||||
import { asPrettyString } from '../utils';
|
||||
|
||||
export const TEXT_CONTEXT_TYPE = 'text';
|
||||
export const TEXT_CONTEXT_TYPE: FieldFormatsContentType = 'text';
|
||||
|
||||
export const setup = (
|
||||
format: IFieldFormat,
|
||||
|
|
|
@ -25,7 +25,7 @@ import { FieldFormat } from '../field_format';
|
|||
import {
|
||||
TextContextTypeConvert,
|
||||
FIELD_FORMAT_IDS,
|
||||
GetConfigFn,
|
||||
FieldFormatsGetConfigFn,
|
||||
IFieldFormatMetaParams,
|
||||
} from '../types';
|
||||
|
||||
|
@ -40,7 +40,7 @@ export class DateFormat extends FieldFormat {
|
|||
private memoizedPattern: string = '';
|
||||
private timeZone: string = '';
|
||||
|
||||
constructor(params: IFieldFormatMetaParams, getConfig?: GetConfigFn) {
|
||||
constructor(params: IFieldFormatMetaParams, getConfig?: FieldFormatsGetConfigFn) {
|
||||
super(params, getConfig);
|
||||
|
||||
this.memoizedConverter = memoize((val: any) => {
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
import { transform, size, cloneDeep, get, defaults } from 'lodash';
|
||||
import { createCustomFieldFormat } from './converters/custom';
|
||||
import {
|
||||
GetConfigFn,
|
||||
ContentType,
|
||||
FieldFormatsGetConfigFn,
|
||||
FieldFormatsContentType,
|
||||
IFieldFormatType,
|
||||
FieldFormatConvert,
|
||||
FieldFormatConvertFunction,
|
||||
|
@ -29,12 +29,7 @@ import {
|
|||
TextContextTypeOptions,
|
||||
IFieldFormatMetaParams,
|
||||
} from './types';
|
||||
import {
|
||||
htmlContentTypeSetup,
|
||||
textContentTypeSetup,
|
||||
TEXT_CONTEXT_TYPE,
|
||||
HTML_CONTEXT_TYPE,
|
||||
} from './content_types';
|
||||
import { htmlContentTypeSetup, textContentTypeSetup, TEXT_CONTEXT_TYPE } from './content_types';
|
||||
import { HtmlContextTypeConvert, TextContextTypeConvert } from './types';
|
||||
|
||||
const DEFAULT_CONTEXT_TYPE = TEXT_CONTEXT_TYPE;
|
||||
|
@ -90,9 +85,9 @@ export abstract class FieldFormat {
|
|||
public type: any = this.constructor;
|
||||
|
||||
protected readonly _params: any;
|
||||
protected getConfig: GetConfigFn | undefined;
|
||||
protected getConfig: FieldFormatsGetConfigFn | undefined;
|
||||
|
||||
constructor(_params: IFieldFormatMetaParams = {}, getConfig?: GetConfigFn) {
|
||||
constructor(_params: IFieldFormatMetaParams = {}, getConfig?: FieldFormatsGetConfigFn) {
|
||||
this._params = _params;
|
||||
|
||||
if (getConfig) {
|
||||
|
@ -112,7 +107,7 @@ export abstract class FieldFormat {
|
|||
*/
|
||||
convert(
|
||||
value: any,
|
||||
contentType: ContentType = DEFAULT_CONTEXT_TYPE,
|
||||
contentType: FieldFormatsContentType = DEFAULT_CONTEXT_TYPE,
|
||||
options?: HtmlContextTypeOptions | TextContextTypeOptions
|
||||
): string {
|
||||
const converter = this.getConverterFor(contentType);
|
||||
|
@ -131,7 +126,7 @@ export abstract class FieldFormat {
|
|||
* @public
|
||||
*/
|
||||
getConverterFor(
|
||||
contentType: ContentType = DEFAULT_CONTEXT_TYPE
|
||||
contentType: FieldFormatsContentType = DEFAULT_CONTEXT_TYPE
|
||||
): FieldFormatConvertFunction | null {
|
||||
if (!this.convertObject) {
|
||||
this.convertObject = this.setupContentType();
|
||||
|
@ -210,8 +205,8 @@ export abstract class FieldFormat {
|
|||
|
||||
setupContentType(): FieldFormatConvert {
|
||||
return {
|
||||
[TEXT_CONTEXT_TYPE]: textContentTypeSetup(this, this.textConvert),
|
||||
[HTML_CONTEXT_TYPE]: htmlContentTypeSetup(this, this.htmlConvert),
|
||||
text: textContentTypeSetup(this, this.textConvert),
|
||||
html: htmlContentTypeSetup(this, this.htmlConvert),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
import { FieldFormatsRegistry } from './field_formats_registry';
|
||||
import { BoolFormat, PercentFormat, StringFormat } from './converters';
|
||||
import { GetConfigFn, IFieldFormatType } from './types';
|
||||
import { FieldFormatsGetConfigFn, IFieldFormatType } from './types';
|
||||
import { KBN_FIELD_TYPES } from '../../common';
|
||||
|
||||
const getValueOfPrivateField = (instance: any, field: string) => instance[field];
|
||||
|
@ -26,7 +26,7 @@ const getValueOfPrivateField = (instance: any, field: string) => instance[field]
|
|||
describe('FieldFormatsRegistry', () => {
|
||||
let fieldFormatsRegistry: FieldFormatsRegistry;
|
||||
let defaultMap = {};
|
||||
const getConfig = (() => defaultMap) as GetConfigFn;
|
||||
const getConfig = (() => defaultMap) as FieldFormatsGetConfigFn;
|
||||
|
||||
beforeEach(() => {
|
||||
fieldFormatsRegistry = new FieldFormatsRegistry();
|
||||
|
|
|
@ -23,24 +23,24 @@ import { forOwn, isFunction, memoize } from 'lodash';
|
|||
import { ES_FIELD_TYPES, KBN_FIELD_TYPES } from '../../common';
|
||||
|
||||
import {
|
||||
GetConfigFn,
|
||||
IFieldFormatConfig,
|
||||
FieldFormatsGetConfigFn,
|
||||
FieldFormatConfig,
|
||||
FIELD_FORMAT_IDS,
|
||||
IFieldFormatType,
|
||||
IFieldFormatId,
|
||||
FieldFormatId,
|
||||
IFieldFormatMetaParams,
|
||||
} from './types';
|
||||
import { baseFormatters } from './constants/base_formatters';
|
||||
import { FieldFormat } from './field_format';
|
||||
|
||||
export class FieldFormatsRegistry {
|
||||
protected fieldFormats: Map<IFieldFormatId, IFieldFormatType> = new Map();
|
||||
protected defaultMap: Record<string, IFieldFormatConfig> = {};
|
||||
protected fieldFormats: Map<FieldFormatId, IFieldFormatType> = new Map();
|
||||
protected defaultMap: Record<string, FieldFormatConfig> = {};
|
||||
protected metaParamsOptions: Record<string, any> = {};
|
||||
protected getConfig?: GetConfigFn;
|
||||
protected getConfig?: FieldFormatsGetConfigFn;
|
||||
|
||||
init(
|
||||
getConfig: GetConfigFn,
|
||||
getConfig: FieldFormatsGetConfigFn,
|
||||
metaParamsOptions: Record<string, any> = {},
|
||||
defaultFieldConverters: IFieldFormatType[] = baseFormatters
|
||||
) {
|
||||
|
@ -62,7 +62,7 @@ export class FieldFormatsRegistry {
|
|||
getDefaultConfig = (
|
||||
fieldType: KBN_FIELD_TYPES,
|
||||
esTypes?: ES_FIELD_TYPES[]
|
||||
): IFieldFormatConfig => {
|
||||
): FieldFormatConfig => {
|
||||
const type = this.getDefaultTypeName(fieldType, esTypes);
|
||||
|
||||
return (
|
||||
|
@ -73,10 +73,10 @@ export class FieldFormatsRegistry {
|
|||
/**
|
||||
* Get a derived FieldFormat class by its id.
|
||||
*
|
||||
* @param {IFieldFormatId} formatId - the format id
|
||||
* @return {FieldFormat | undefined}
|
||||
* @param {FieldFormatId} formatId - the format id
|
||||
* @return {IFieldFormatType | undefined}
|
||||
*/
|
||||
getType = (formatId: IFieldFormatId): IFieldFormatType | undefined => {
|
||||
getType = (formatId: FieldFormatId): IFieldFormatType | undefined => {
|
||||
const fieldFormat = this.fieldFormats.get(formatId);
|
||||
|
||||
if (fieldFormat) {
|
||||
|
@ -97,7 +97,7 @@ export class FieldFormatsRegistry {
|
|||
*
|
||||
* @param {KBN_FIELD_TYPES} fieldType
|
||||
* @param {ES_FIELD_TYPES[]} esTypes - Array of ES data types
|
||||
* @return {FieldFormat | undefined}
|
||||
* @return {IFieldFormatType | undefined}
|
||||
*/
|
||||
getDefaultType = (
|
||||
fieldType: KBN_FIELD_TYPES,
|
||||
|
@ -129,7 +129,7 @@ export class FieldFormatsRegistry {
|
|||
*
|
||||
* @param {KBN_FIELD_TYPES} fieldType
|
||||
* @param {ES_FIELD_TYPES[]} esTypes
|
||||
* @return {ES_FIELD_TYPES | String}
|
||||
* @return {ES_FIELD_TYPES | KBN_FIELD_TYPES}
|
||||
*/
|
||||
getDefaultTypeName = (
|
||||
fieldType: KBN_FIELD_TYPES,
|
||||
|
@ -143,11 +143,11 @@ export class FieldFormatsRegistry {
|
|||
/**
|
||||
* Get the singleton instance of the FieldFormat type by its id.
|
||||
*
|
||||
* @param {IFieldFormatId} formatId
|
||||
* @return {FIELD_FORMATS_INSTANCES[number]}
|
||||
* @param {FieldFormatId} formatId
|
||||
* @return {FieldFormat}
|
||||
*/
|
||||
getInstance = memoize(
|
||||
(formatId: IFieldFormatId, params: Record<string, any> = {}): FieldFormat => {
|
||||
(formatId: FieldFormatId, params: Record<string, any> = {}): FieldFormat => {
|
||||
const ConcreteFieldFormat = this.getType(formatId);
|
||||
|
||||
if (!ConcreteFieldFormat) {
|
||||
|
@ -156,7 +156,7 @@ export class FieldFormatsRegistry {
|
|||
|
||||
return new ConcreteFieldFormat(params, this.getConfig);
|
||||
},
|
||||
(formatId: IFieldFormatId, params: Record<string, any>) =>
|
||||
(formatId: FieldFormatId, params: Record<string, any>) =>
|
||||
JSON.stringify({
|
||||
formatId,
|
||||
...params,
|
||||
|
@ -197,7 +197,7 @@ export class FieldFormatsRegistry {
|
|||
* Get filtered list of field formats by format type
|
||||
*
|
||||
* @param {KBN_FIELD_TYPES} fieldType
|
||||
* @return {FieldFormat[]}
|
||||
* @return {IFieldFormatType[]}
|
||||
*/
|
||||
getByFieldType(fieldType: KBN_FIELD_TYPES): IFieldFormatType[] {
|
||||
return [...this.fieldFormats.values()]
|
||||
|
@ -238,7 +238,7 @@ export class FieldFormatsRegistry {
|
|||
*
|
||||
* @private
|
||||
* @param {IFieldFormatType} fieldFormat - field format type
|
||||
* @return {FieldFormat | undefined}
|
||||
* @return {IFieldFormatType | undefined}
|
||||
*/
|
||||
private fieldFormatMetaParamsDecorator = (
|
||||
fieldFormat: IFieldFormatType
|
||||
|
@ -250,7 +250,7 @@ export class FieldFormatsRegistry {
|
|||
static id = fieldFormat.id;
|
||||
static fieldType = fieldFormat.fieldType;
|
||||
|
||||
constructor(params: Record<string, any> = {}, getConfig?: GetConfigFn) {
|
||||
constructor(params: Record<string, any> = {}, getConfig?: FieldFormatsGetConfigFn) {
|
||||
super(getMetaParams(params), getConfig);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -17,6 +17,42 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import * as fieldFormats from './static';
|
||||
import { FieldFormatsRegistry } from './field_formats_registry';
|
||||
type IFieldFormatsRegistry = PublicMethodsOf<FieldFormatsRegistry>;
|
||||
|
||||
export { fieldFormats };
|
||||
export { FieldFormatsRegistry, IFieldFormatsRegistry };
|
||||
export { FieldFormat } from './field_format';
|
||||
export { baseFormatters } from './constants/base_formatters';
|
||||
export {
|
||||
BoolFormat,
|
||||
BytesFormat,
|
||||
ColorFormat,
|
||||
DateFormat,
|
||||
DateNanosFormat,
|
||||
DurationFormat,
|
||||
IpFormat,
|
||||
NumberFormat,
|
||||
PercentFormat,
|
||||
RelativeDateFormat,
|
||||
SourceFormat,
|
||||
StaticLookupFormat,
|
||||
UrlFormat,
|
||||
StringFormat,
|
||||
TruncateFormat,
|
||||
} from './converters';
|
||||
|
||||
export { getHighlightRequest } from './utils';
|
||||
|
||||
export { DEFAULT_CONVERTER_COLOR } from './constants/color_default';
|
||||
export { FIELD_FORMAT_IDS } from './types';
|
||||
export { HTML_CONTEXT_TYPE, TEXT_CONTEXT_TYPE } from './content_types';
|
||||
|
||||
export {
|
||||
FieldFormatsGetConfigFn,
|
||||
FieldFormatsContentType,
|
||||
FieldFormatConfig,
|
||||
FieldFormatId,
|
||||
// Used in data plugin only
|
||||
IFieldFormatType,
|
||||
IFieldFormat,
|
||||
} from './types';
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Everything the file exports is public
|
||||
*/
|
||||
|
||||
export { HTML_CONTEXT_TYPE, TEXT_CONTEXT_TYPE } from './content_types';
|
||||
export { FieldFormat } from './field_format';
|
||||
export { FieldFormatsRegistry } from './field_formats_registry';
|
||||
export { getHighlightRequest, asPrettyString, getHighlightHtml } from './utils';
|
||||
|
||||
export { baseFormatters } from './constants/base_formatters';
|
||||
export { DEFAULT_CONVERTER_COLOR } from './constants/color_default';
|
||||
|
||||
export {
|
||||
BoolFormat,
|
||||
BytesFormat,
|
||||
ColorFormat,
|
||||
DateFormat,
|
||||
DateNanosFormat,
|
||||
DurationFormat,
|
||||
IpFormat,
|
||||
NumberFormat,
|
||||
PercentFormat,
|
||||
RelativeDateFormat,
|
||||
SourceFormat,
|
||||
StaticLookupFormat,
|
||||
UrlFormat,
|
||||
StringFormat,
|
||||
TruncateFormat,
|
||||
} from './converters';
|
||||
|
||||
export {
|
||||
GetConfigFn,
|
||||
FIELD_FORMAT_IDS,
|
||||
ContentType,
|
||||
IFieldFormatConfig,
|
||||
IFieldFormatType,
|
||||
IFieldFormat,
|
||||
IFieldFormatId,
|
||||
} from './types';
|
|
@ -20,7 +20,7 @@
|
|||
import { FieldFormat } from './field_format';
|
||||
|
||||
/** @public **/
|
||||
export type ContentType = 'html' | 'text';
|
||||
export type FieldFormatsContentType = 'html' | 'text';
|
||||
|
||||
/** @internal **/
|
||||
export interface HtmlContextTypeOptions {
|
||||
|
@ -66,23 +66,26 @@ export enum FIELD_FORMAT_IDS {
|
|||
URL = 'url',
|
||||
}
|
||||
|
||||
export interface IFieldFormatConfig {
|
||||
id: IFieldFormatId;
|
||||
export interface FieldFormatConfig {
|
||||
id: FieldFormatId;
|
||||
params: Record<string, any>;
|
||||
es?: boolean;
|
||||
}
|
||||
|
||||
export type GetConfigFn = <T = any>(key: string, defaultOverride?: T) => T;
|
||||
export type FieldFormatsGetConfigFn = <T = any>(key: string, defaultOverride?: T) => T;
|
||||
|
||||
export type IFieldFormat = PublicMethodsOf<FieldFormat>;
|
||||
|
||||
/**
|
||||
* @string id type is needed for creating custom converters.
|
||||
*/
|
||||
export type IFieldFormatId = FIELD_FORMAT_IDS | string;
|
||||
export type FieldFormatId = FIELD_FORMAT_IDS | string;
|
||||
|
||||
export type IFieldFormatType = (new (params?: any, getConfig?: GetConfigFn) => FieldFormat) & {
|
||||
id: IFieldFormatId;
|
||||
export type IFieldFormatType = (new (
|
||||
params?: any,
|
||||
getConfig?: FieldFormatsGetConfigFn
|
||||
) => FieldFormat) & {
|
||||
id: FieldFormatId;
|
||||
fieldType: string | string[];
|
||||
};
|
||||
|
||||
|
|
|
@ -18,10 +18,10 @@
|
|||
*/
|
||||
|
||||
import { CoreSetup } from 'src/core/public';
|
||||
import { fieldFormats } from '../../common/field_formats';
|
||||
import { FieldFormatsRegistry } from '../../common/field_formats';
|
||||
|
||||
export class FieldFormatsService {
|
||||
private readonly fieldFormatsRegistry: fieldFormats.FieldFormatsRegistry = new fieldFormats.FieldFormatsRegistry();
|
||||
private readonly fieldFormatsRegistry: FieldFormatsRegistry = new FieldFormatsRegistry();
|
||||
|
||||
public setup(core: CoreSetup) {
|
||||
core.uiSettings.getUpdate$().subscribe(({ key, newValue }) => {
|
||||
|
@ -49,7 +49,7 @@ export class FieldFormatsService {
|
|||
}
|
||||
|
||||
/** @public */
|
||||
export type FieldFormatsSetup = Pick<fieldFormats.FieldFormatsRegistry, 'register'>;
|
||||
export type FieldFormatsSetup = Pick<FieldFormatsRegistry, 'register'>;
|
||||
|
||||
/** @public */
|
||||
export type FieldFormatsStart = Omit<fieldFormats.FieldFormatsRegistry, 'init' & 'register'>;
|
||||
export type FieldFormatsStart = Omit<FieldFormatsRegistry, 'init' & 'register'>;
|
||||
|
|
|
@ -19,6 +19,60 @@
|
|||
|
||||
import { PluginInitializerContext } from '../../../core/public';
|
||||
|
||||
/*
|
||||
* Field Formatters helper namespace:
|
||||
*/
|
||||
|
||||
import {
|
||||
FieldFormat,
|
||||
FieldFormatsRegistry, // exported only for tests. Consider mock.
|
||||
DEFAULT_CONVERTER_COLOR,
|
||||
HTML_CONTEXT_TYPE,
|
||||
TEXT_CONTEXT_TYPE,
|
||||
FIELD_FORMAT_IDS,
|
||||
BoolFormat,
|
||||
BytesFormat,
|
||||
ColorFormat,
|
||||
DateFormat,
|
||||
DateNanosFormat,
|
||||
DurationFormat,
|
||||
IpFormat,
|
||||
NumberFormat,
|
||||
PercentFormat,
|
||||
RelativeDateFormat,
|
||||
SourceFormat,
|
||||
StaticLookupFormat,
|
||||
UrlFormat,
|
||||
StringFormat,
|
||||
TruncateFormat,
|
||||
} from '../common/field_formats';
|
||||
|
||||
export const fieldFormats = {
|
||||
FieldFormat,
|
||||
FieldFormatsRegistry, // exported only for tests. Consider mock.
|
||||
|
||||
DEFAULT_CONVERTER_COLOR,
|
||||
HTML_CONTEXT_TYPE,
|
||||
TEXT_CONTEXT_TYPE,
|
||||
FIELD_FORMAT_IDS,
|
||||
|
||||
BoolFormat,
|
||||
BytesFormat,
|
||||
ColorFormat,
|
||||
DateFormat,
|
||||
DateNanosFormat,
|
||||
DurationFormat,
|
||||
IpFormat,
|
||||
NumberFormat,
|
||||
PercentFormat,
|
||||
RelativeDateFormat,
|
||||
SourceFormat,
|
||||
StaticLookupFormat,
|
||||
UrlFormat,
|
||||
StringFormat,
|
||||
TruncateFormat,
|
||||
};
|
||||
|
||||
export function plugin(initializerContext: PluginInitializerContext) {
|
||||
return new DataPublicPlugin(initializerContext);
|
||||
}
|
||||
|
@ -42,9 +96,15 @@ export {
|
|||
// timefilter
|
||||
RefreshInterval,
|
||||
TimeRange,
|
||||
// Field Formats
|
||||
IFieldFormat,
|
||||
IFieldFormatsRegistry,
|
||||
FieldFormatsContentType,
|
||||
FieldFormatsGetConfigFn,
|
||||
FieldFormatConfig,
|
||||
FieldFormatId,
|
||||
} from '../common';
|
||||
export { autocomplete } from './autocomplete';
|
||||
export * from './field_formats';
|
||||
export * from './index_patterns';
|
||||
export * from './search';
|
||||
export * from './query';
|
||||
|
@ -54,7 +114,6 @@ export {
|
|||
esFilters,
|
||||
esKuery,
|
||||
esQuery,
|
||||
fieldFormats,
|
||||
// index patterns
|
||||
isFilterable,
|
||||
// kbn field types
|
||||
|
|
|
@ -26,8 +26,8 @@ import {
|
|||
IFieldType,
|
||||
getKbnFieldType,
|
||||
IFieldSubType,
|
||||
fieldFormats,
|
||||
shortenDottedString,
|
||||
FieldFormat,
|
||||
} from '../../../common';
|
||||
|
||||
export type FieldSpec = Record<string, any>;
|
||||
|
@ -95,7 +95,7 @@ export class Field implements IFieldType {
|
|||
|
||||
let format = spec.format;
|
||||
|
||||
if (!fieldFormats.FieldFormat.isInstanceOfFieldFormat(format)) {
|
||||
if (!FieldFormat.isInstanceOfFieldFormat(format)) {
|
||||
const fieldFormatsService = getFieldFormats();
|
||||
|
||||
format =
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
import _ from 'lodash';
|
||||
import { IndexPattern } from './index_pattern';
|
||||
import { fieldFormats } from '../../../common';
|
||||
import { FieldFormatsContentType } from '../../../common';
|
||||
|
||||
const formattedCache = new WeakMap();
|
||||
const partialFormattedCache = new WeakMap();
|
||||
|
@ -31,7 +31,7 @@ export function formatHitProvider(indexPattern: IndexPattern, defaultFormat: any
|
|||
hit: Record<string, any>,
|
||||
val: any,
|
||||
fieldName: string,
|
||||
type: fieldFormats.ContentType = 'html'
|
||||
type: FieldFormatsContentType = 'html'
|
||||
) {
|
||||
const field = indexPattern.fields.getByName(fieldName);
|
||||
const format = field ? field.format : defaultFormat;
|
||||
|
|
|
@ -31,7 +31,7 @@ import { setNotifications, setFieldFormats } from '../../services';
|
|||
// Temporary disable eslint, will be removed after moving to new platform folder
|
||||
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
|
||||
import { notificationServiceMock } from '../../../../../core/public/notifications/notifications_service.mock';
|
||||
import { fieldFormats } from '../../../common/field_formats';
|
||||
import { FieldFormatsRegistry } from '../../../common/field_formats';
|
||||
|
||||
jest.mock('../../../../kibana_utils/public', () => {
|
||||
const originalModule = jest.requireActual('../../../../kibana_utils/public');
|
||||
|
@ -125,7 +125,7 @@ describe('IndexPattern', () => {
|
|||
setNotifications(notifications);
|
||||
setFieldFormats(({
|
||||
getDefaultInstance: jest.fn(),
|
||||
} as unknown) as fieldFormats.FieldFormatsRegistry);
|
||||
} as unknown) as FieldFormatsRegistry);
|
||||
|
||||
return create(indexPatternId).then((pattern: IndexPattern) => {
|
||||
indexPattern = pattern;
|
||||
|
|
|
@ -18,10 +18,10 @@
|
|||
*/
|
||||
import {
|
||||
Plugin,
|
||||
FieldFormatsStart,
|
||||
FieldFormatsSetup,
|
||||
DataPublicPluginSetup,
|
||||
DataPublicPluginStart,
|
||||
IndexPatternsContract,
|
||||
fieldFormats,
|
||||
IFieldFormatsRegistry,
|
||||
} from '.';
|
||||
import { searchSetupMock } from './search/mocks';
|
||||
import { queryServiceMock } from './query/mocks';
|
||||
|
@ -35,7 +35,7 @@ const autocompleteMock: any = {
|
|||
hasQuerySuggestions: jest.fn(),
|
||||
};
|
||||
|
||||
const fieldFormatsMock: PublicMethodsOf<fieldFormats.FieldFormatsRegistry> = {
|
||||
const fieldFormatsMock: IFieldFormatsRegistry = {
|
||||
getByFieldType: jest.fn(),
|
||||
getDefaultConfig: jest.fn(),
|
||||
getDefaultInstance: jest.fn() as any,
|
||||
|
@ -56,7 +56,7 @@ const createSetupContract = (): Setup => {
|
|||
const setupContract = {
|
||||
autocomplete: autocompleteMock,
|
||||
search: searchSetupMock,
|
||||
fieldFormats: fieldFormatsMock as FieldFormatsSetup,
|
||||
fieldFormats: fieldFormatsMock as DataPublicPluginSetup['fieldFormats'],
|
||||
query: querySetupMock,
|
||||
__LEGACY: {
|
||||
esClient: {
|
||||
|
@ -84,7 +84,7 @@ const createStartContract = (): Start => {
|
|||
},
|
||||
},
|
||||
},
|
||||
fieldFormats: fieldFormatsMock as FieldFormatsStart,
|
||||
fieldFormats: fieldFormatsMock as DataPublicPluginStart['fieldFormats'],
|
||||
query: queryStartMock,
|
||||
ui: {
|
||||
IndexPatternSelect: jest.fn(),
|
||||
|
|
|
@ -73,11 +73,12 @@ import _ from 'lodash';
|
|||
import { normalizeSortRequest } from './normalize_sort_request';
|
||||
import { filterDocvalueFields } from './filter_docvalue_fields';
|
||||
import { fieldWildcardFilter } from '../../../../kibana_utils/public';
|
||||
import { fieldFormats, esFilters, esQuery, SearchRequest } from '../..';
|
||||
import { esFilters, esQuery, SearchRequest } from '../..';
|
||||
import { SearchSourceOptions, SearchSourceFields } from './types';
|
||||
import { fetchSoon, FetchOptions, RequestFailure } from '../fetch';
|
||||
|
||||
import { getSearchService, getUiSettings, getInjectedMetadata } from '../../services';
|
||||
import { getHighlightRequest } from '../../../common';
|
||||
|
||||
export type ISearchSource = Pick<SearchSource, keyof SearchSource>;
|
||||
|
||||
|
@ -382,10 +383,7 @@ export class SearchSource {
|
|||
body.query = esQuery.buildEsQuery(index, query, filters, esQueryConfigs);
|
||||
|
||||
if (highlightAll && body.query) {
|
||||
body.highlight = fieldFormats.getHighlightRequest(
|
||||
body.query,
|
||||
getUiSettings().get('doc_table:highlight')
|
||||
);
|
||||
body.highlight = getHighlightRequest(body.query, getUiSettings().get('doc_table:highlight'));
|
||||
delete searchRequest.highlightAll;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
import { NotificationsStart } from 'src/core/public';
|
||||
import { CoreSetup, CoreStart } from 'kibana/public';
|
||||
import { FieldFormatsStart } from '.';
|
||||
import { FieldFormatsStart } from './field_formats';
|
||||
import { createGetterSetter } from '../../kibana_utils/public';
|
||||
import { IndexPatternsContract } from './index_patterns';
|
||||
import { DataPublicPluginStart } from './types';
|
||||
|
|
|
@ -17,16 +17,15 @@
|
|||
* under the License.
|
||||
*/
|
||||
import { has } from 'lodash';
|
||||
import { fieldFormats } from '../../common/field_formats';
|
||||
import { FieldFormatsRegistry, IFieldFormatType, baseFormatters } from '../../common/field_formats';
|
||||
import { IUiSettingsClient } from '../../../../core/server';
|
||||
|
||||
export class FieldFormatsService {
|
||||
private readonly fieldFormatClasses: fieldFormats.IFieldFormatType[] =
|
||||
fieldFormats.baseFormatters;
|
||||
private readonly fieldFormatClasses: IFieldFormatType[] = baseFormatters;
|
||||
|
||||
public setup() {
|
||||
return {
|
||||
register: (customFieldFormat: fieldFormats.IFieldFormatType) =>
|
||||
register: (customFieldFormat: IFieldFormatType) =>
|
||||
this.fieldFormatClasses.push(customFieldFormat),
|
||||
};
|
||||
}
|
||||
|
@ -34,7 +33,7 @@ export class FieldFormatsService {
|
|||
public start() {
|
||||
return {
|
||||
fieldFormatServiceFactory: async (uiSettings: IUiSettingsClient) => {
|
||||
const fieldFormatsRegistry = new fieldFormats.FieldFormatsRegistry();
|
||||
const fieldFormatsRegistry = new FieldFormatsRegistry();
|
||||
const uiConfigs = await uiSettings.getAll();
|
||||
const registeredUiSettings = uiSettings.getRegistered();
|
||||
|
||||
|
|
|
@ -20,6 +20,50 @@
|
|||
import { PluginInitializerContext } from '../../../core/server';
|
||||
import { DataServerPlugin, DataPluginSetup, DataPluginStart } from './plugin';
|
||||
|
||||
/*
|
||||
* Field Formatters helper namespace:
|
||||
*/
|
||||
|
||||
import {
|
||||
FieldFormat,
|
||||
FieldFormatsRegistry, // exported only for tests. Consider mock.
|
||||
BoolFormat,
|
||||
BytesFormat,
|
||||
ColorFormat,
|
||||
DateFormat,
|
||||
DateNanosFormat,
|
||||
DurationFormat,
|
||||
IpFormat,
|
||||
NumberFormat,
|
||||
PercentFormat,
|
||||
RelativeDateFormat,
|
||||
SourceFormat,
|
||||
StaticLookupFormat,
|
||||
UrlFormat,
|
||||
StringFormat,
|
||||
TruncateFormat,
|
||||
} from '../common/field_formats';
|
||||
|
||||
export const fieldFormats = {
|
||||
FieldFormat,
|
||||
FieldFormatsRegistry, // exported only for tests. Consider mock.
|
||||
|
||||
BoolFormat,
|
||||
BytesFormat,
|
||||
ColorFormat,
|
||||
DateFormat,
|
||||
DateNanosFormat,
|
||||
DurationFormat,
|
||||
IpFormat,
|
||||
NumberFormat,
|
||||
PercentFormat,
|
||||
RelativeDateFormat,
|
||||
SourceFormat,
|
||||
StaticLookupFormat,
|
||||
UrlFormat,
|
||||
StringFormat,
|
||||
TruncateFormat,
|
||||
};
|
||||
export function plugin(initializerContext: PluginInitializerContext) {
|
||||
return new DataServerPlugin(initializerContext);
|
||||
}
|
||||
|
@ -35,7 +79,6 @@ export {
|
|||
esFilters,
|
||||
esKuery,
|
||||
esQuery,
|
||||
fieldFormats,
|
||||
// kbn field types
|
||||
castEsToKbnFieldTypeName,
|
||||
getKbnFieldType,
|
||||
|
@ -56,6 +99,9 @@ export {
|
|||
// utils
|
||||
parseInterval,
|
||||
isNestedField,
|
||||
IFieldFormatsRegistry,
|
||||
FieldFormatsGetConfigFn,
|
||||
FieldFormatConfig,
|
||||
} from '../common';
|
||||
|
||||
/**
|
||||
|
|
|
@ -11,7 +11,7 @@ import { FieldItem, FieldItemProps } from './field_item';
|
|||
import { coreMock } from 'src/core/public/mocks';
|
||||
import { mountWithIntl } from 'test_utils/enzyme_helpers';
|
||||
import { npStart } from 'ui/new_platform';
|
||||
import { FieldFormatsStart } from '../../../../../../src/plugins/data/public';
|
||||
import { DataPublicPluginStart } from '../../../../../../src/plugins/data/public';
|
||||
import { IndexPattern } from './types';
|
||||
|
||||
jest.mock('ui/new_platform');
|
||||
|
@ -87,7 +87,7 @@ describe('IndexPattern Field Item', () => {
|
|||
getDefaultInstance: jest.fn(() => ({
|
||||
convert: jest.fn((s: unknown) => JSON.stringify(s)),
|
||||
})),
|
||||
} as unknown) as FieldFormatsStart;
|
||||
} as unknown) as DataPublicPluginStart['fieldFormats'];
|
||||
});
|
||||
|
||||
it('should request field stats without a time field, if the index pattern has none', async () => {
|
||||
|
|
|
@ -9,7 +9,7 @@ import { LensMultiTable } from '../types';
|
|||
import React from 'react';
|
||||
import { shallow } from 'enzyme';
|
||||
import { MetricConfig } from './types';
|
||||
import { fieldFormats } from '../../../../../../src/plugins/data/public';
|
||||
import { IFieldFormat } from '../../../../../../src/plugins/data/public';
|
||||
|
||||
function sampleArgs() {
|
||||
const data: LensMultiTable = {
|
||||
|
@ -55,9 +55,7 @@ describe('metric_expression', () => {
|
|||
const { data, args } = sampleArgs();
|
||||
|
||||
expect(
|
||||
shallow(
|
||||
<MetricChart data={data} args={args} formatFactory={x => x as fieldFormats.FieldFormat} />
|
||||
)
|
||||
shallow(<MetricChart data={data} args={args} formatFactory={x => x as IFieldFormat} />)
|
||||
).toMatchInlineSnapshot(`
|
||||
<VisualizationContainer
|
||||
className="lnsMetricExpression__container"
|
||||
|
@ -98,7 +96,7 @@ describe('metric_expression', () => {
|
|||
<MetricChart
|
||||
data={data}
|
||||
args={{ ...args, mode: 'reduced' }}
|
||||
formatFactory={x => x as fieldFormats.FieldFormat}
|
||||
formatFactory={x => x as IFieldFormat}
|
||||
/>
|
||||
)
|
||||
).toMatchInlineSnapshot(`
|
||||
|
|
|
@ -6,7 +6,10 @@
|
|||
|
||||
import expect from '@kbn/expect';
|
||||
|
||||
import { fieldFormats } from '../../../../../../../../src/plugins/data/server';
|
||||
import {
|
||||
fieldFormats,
|
||||
FieldFormatsGetConfigFn,
|
||||
} from '../../../../../../../../src/plugins/data/server';
|
||||
import { fieldFormatMapFactory } from './field_format_map';
|
||||
|
||||
type ConfigValue = { number: { id: string; params: {} } } | string;
|
||||
|
@ -29,7 +32,7 @@ describe('field format map', function() {
|
|||
number: { id: 'number', params: {} },
|
||||
};
|
||||
configMock['format:number:defaultPattern'] = '0,0.[000]';
|
||||
const getConfig = ((key: string) => configMock[key]) as fieldFormats.GetConfigFn;
|
||||
const getConfig = ((key: string) => configMock[key]) as FieldFormatsGetConfigFn;
|
||||
const testValue = '4000';
|
||||
|
||||
const fieldFormatsRegistry = new fieldFormats.FieldFormatsRegistry();
|
||||
|
|
|
@ -5,7 +5,10 @@
|
|||
*/
|
||||
|
||||
import _ from 'lodash';
|
||||
import { fieldFormats } from '../../../../../../../../src/plugins/data/server';
|
||||
import {
|
||||
FieldFormatConfig,
|
||||
IFieldFormatsRegistry,
|
||||
} from '../../../../../../../../src/plugins/data/server';
|
||||
|
||||
interface IndexPatternSavedObject {
|
||||
attributes: {
|
||||
|
@ -25,7 +28,7 @@ interface IndexPatternSavedObject {
|
|||
*/
|
||||
export function fieldFormatMapFactory(
|
||||
indexPatternSavedObject: IndexPatternSavedObject,
|
||||
fieldFormatsRegistry: fieldFormats.FieldFormatsRegistry
|
||||
fieldFormatsRegistry: IFieldFormatsRegistry
|
||||
) {
|
||||
const formatsMap = new Map();
|
||||
|
||||
|
@ -33,7 +36,7 @@ export function fieldFormatMapFactory(
|
|||
if (_.has(indexPatternSavedObject, 'attributes.fieldFormatMap')) {
|
||||
const fieldFormatMap = JSON.parse(indexPatternSavedObject.attributes.fieldFormatMap);
|
||||
Object.keys(fieldFormatMap).forEach(fieldName => {
|
||||
const formatConfig: fieldFormats.IFieldFormatConfig = fieldFormatMap[fieldName];
|
||||
const formatConfig: FieldFormatConfig = fieldFormatMap[fieldName];
|
||||
|
||||
if (!_.isEmpty(formatConfig)) {
|
||||
formatsMap.set(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue