Skip to content

Commit

Permalink
Migrate field format to new instance
Browse files Browse the repository at this point in the history
  • Loading branch information
Avinar-24 committed Oct 24, 2019
1 parent 66c66ef commit ccd5570
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { i18n } from '@kbn/i18n';
// @ts-ignore
import { ObjDefine } from './obj_define';
import { FieldFormat } from '../../../../../../plugins/data/common/field_formats';
import { FieldFormat } from '../../../../../../plugins/data/public';
// @ts-ignore
import { shortenDottedString } from '../../../../../core_plugins/kibana/common/utils/shorten_dotted_string';
import { IndexPattern } from '../index_patterns';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@
import { buildHierarchicalData } from './build_hierarchical_data';
import { legacyResponseHandlerProvider } from '../../vis/response_handlers/legacy';

jest.mock('../../registry/field_formats', () => {
return { fieldFormats: {
jest.mock('../../../../../plugins/data/public', () =>({
...jest.requireActual('../../../../../plugins/data/public'),
getFieldFormats: jest.fn(() => ({
getType: id => {
if(id === '1') { return jest.fn(); }
if(id === 'agg_1') { return jest.fn(); }
}
}
};
}
);
}))
}));

jest.mock('../../chrome', () => ({
getUiSettingsClient: jest.fn()
Expand Down
6 changes: 3 additions & 3 deletions src/legacy/ui/public/agg_types/buckets/date_range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ import { BUCKET_TYPES } from './bucket_agg_types';
import { BucketAggType } from './_bucket_agg_type';
import { createFilterDateRange } from './create_filter/date_range';
import { AggConfig } from '../agg_config';
import { FieldFormat } from '../../../../../plugins/data/common/';
import { FieldFormat, getFieldFormats } from '../../../../../plugins/data/public';
import { DateRangesParamEditor } from '../../vis/editors/default/controls/date_ranges';

// @ts-ignore
import { fieldFormats } from '../../registry/field_formats';
// @ts-ignore
import { dateRange } from '../../utils/date_range';
import { KBN_FIELD_TYPES } from '../../../../../plugins/data/common';
Expand All @@ -37,6 +35,8 @@ const dateRangeTitle = i18n.translate('common.ui.aggTypes.buckets.dateRangeTitle
defaultMessage: 'Date Range',
});

const fieldFormats = getFieldFormats();

export interface DateRangeKey {
from: number;
to: number;
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/ui/public/agg_types/buckets/range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { i18n } from '@kbn/i18n';
import { IBucketAggConfig } from './_bucket_agg_type';
import { BucketAggType } from './_bucket_agg_type';
import { FieldFormat } from '../../../../../plugins/data/common/field_formats';
import { FieldFormat } from '../../../../../plugins/data/public';
import { RangeKey } from './range_key';
import { RangesEditor } from './range_editor';

Expand Down
4 changes: 2 additions & 2 deletions src/legacy/ui/public/agg_types/metrics/count.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import { i18n } from '@kbn/i18n';
import { MetricAggType } from './metric_agg_type';
import { METRIC_TYPES } from './metric_agg_types';
import { getFieldFormats } from '../../../../../plugins/data/public';

// @ts-ignore
import { fieldFormats } from '../../registry/field_formats';
const fieldFormats = getFieldFormats();

export const countMetricAgg = new MetricAggType({
name: METRIC_TYPES.COUNT,
Expand Down
5 changes: 2 additions & 3 deletions src/legacy/ui/public/agg_types/metrics/metric_agg_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ import { AggType, AggTypeConfig } from '../agg_type';
import { AggParamType } from '../param_types/agg';
import { AggConfig } from '../agg_config';
import { METRIC_TYPES } from './metric_agg_types';
import { KBN_FIELD_TYPES, getFieldFormats } from '../../../../../plugins/data/public';

// @ts-ignore
import { fieldFormats } from '../../registry/field_formats';
import { KBN_FIELD_TYPES } from '../../../../../plugins/data/common';
const fieldFormats = getFieldFormats();

export type IMetricAggConfig = AggConfig;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ import { normalizeSortRequest } from './_normalize_sort_request';

import { fetchSoon } from '../fetch';
import { fieldWildcardFilter } from '../../field_wildcard';
import { getHighlightRequest } from '../../../../../plugins/data/common/field_formats';
import { getHighlightRequest } from '../../../../../plugins/data/common';
import { npSetup } from 'ui/new_platform';
import chrome from '../../chrome';
import { RequestFailure } from '../fetch/errors';
Expand Down
5 changes: 4 additions & 1 deletion src/legacy/ui/public/vis/__tests__/_agg_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@
import sinon from 'sinon';
import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import { npSetup } from 'ui/new_platform';
import { VisProvider } from '..';
import { AggType } from '../../agg_types/agg_type';
import { AggConfig } from '../../agg_types/agg_config';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
import { fieldFormats } from '../../registry/field_formats';
import { FieldFormatRegisty } from '../../../../../plugins/data/public';

const fieldFormats = new FieldFormatRegisty(npSetup.core.uiSettings);

describe('AggConfig', function () {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ import { identity } from 'lodash';
import { AggConfig, Vis } from 'ui/vis';
import { SerializedFieldFormat } from 'src/plugins/expressions/common/expressions/types/common';

import { FieldFormat } from '../../../../../../plugins/data/common/field_formats';
import { FieldFormat, getFieldFormats } from '../../../../../../plugins/data/public';

import { tabifyGetColumns } from '../../../agg_response/tabify/_get_columns';
import chrome from '../../../chrome';
// @ts-ignore
import { fieldFormats } from '../../../registry/field_formats';
import { dateRange } from '../../../utils/date_range';
import { ipRange } from '../../../utils/ip_range';
import { DateRangeKey } from '../../../agg_types/buckets/date_range';
Expand All @@ -46,6 +44,7 @@ function isTermsFieldFormat(
}

const config = chrome.getUiSettingsClient();
const fieldFormats = getFieldFormats();

const getConfig = (...args: any[]): any => config.get(...args);
const getDefaultFieldFormat = () => ({ convert: identity });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@

import { forOwn, isFunction, memoize } from 'lodash';
import { UiSettingsClientContract } from 'kibana/public';
import { FieldFormat } from '../../common/field_formats';
import { FIELD_FORMATS_IDS } from './types';
import { ES_FIELD_TYPES, KBN_FIELD_TYPES } from '../../common';
import { ES_FIELD_TYPES, KBN_FIELD_TYPES, FieldFormat } from '../../common';

interface FieldType {
id: FIELD_FORMATS_IDS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ import { mountWithIntl, shallowWithIntl } from 'test_utils/enzyme_helpers';
import { ChangeIndexPattern } from './change_indexpattern';
import { EuiProgress } from '@elastic/eui';

jest.mock('ui/new_platform');
jest.mock('../../../../../../src/legacy/ui/public/registry/field_formats');

const initialState: IndexPatternPrivateState = {
indexPatternRefs: [],
existingFields: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import { mountWithIntl } from 'test_utils/enzyme_helpers';
jest.mock('ui/new_platform');

// Formatter must be mocked to return a string, or the rendering will fail
jest.mock('../../../../../../src/legacy/ui/public/registry/field_formats', () => ({
fieldFormats: {
jest.mock('../../../../../../src/plugins/data/public', () => ({
...jest.requireActual('../../../../../../plugins/data/public/'),
getFieldFormats: jest.fn(() => ({
getDefaultInstance: jest.fn().mockReturnValue({
convert: jest.fn().mockReturnValue((s: unknown) => JSON.stringify(s)),
}),
},
})),
}));

const waitForPromises = () => new Promise(resolve => setTimeout(resolve));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ import {
import { i18n } from '@kbn/i18n';
import { Filter, buildEsQuery, getEsQueryConfig } from '@kbn/es-query';
import { Query } from 'src/plugins/data/common';
// @ts-ignore
import { fieldFormats } from '../../../../../../src/legacy/ui/public/registry/field_formats';
import { getFieldFormats } from '../../../../../../src/plugins/data/public';
import { DraggedField } from './indexpattern';
import { DragDrop } from '../drag_drop';
import { DatasourceDataPanelProps, DataType } from '../types';
Expand Down Expand Up @@ -74,6 +73,8 @@ function wrapOnDot(str?: string) {
return str ? str.replace(/\./g, '.\u200B') : '';
}

const fieldFormats = getFieldFormats();

export function FieldItem(props: FieldItemProps) {
const { core, field, indexPattern, highlight, exists, query, dateRange, filters } = props;

Expand Down

0 comments on commit ccd5570

Please sign in to comment.