Skip to content

Commit

Permalink
removes angular from fieldFormatts (#17581)
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar authored Apr 12, 2018
1 parent d6d4ce8 commit adabbf3
Show file tree
Hide file tree
Showing 30 changed files with 186 additions and 228 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import expect from 'expect.js';
import ngMock from 'ng_mock';
import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats';
import { fieldFormats } from 'ui/registry/field_formats';

describe('Boolean Format', function () {

let boolean;
beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
const fieldFormats = Private(RegistryFieldFormatsProvider);
boolean = fieldFormats.getInstance('boolean');
}));
const boolean = fieldFormats.getInstance('boolean');


[
Expand Down
11 changes: 2 additions & 9 deletions src/core_plugins/kibana/public/field_formats/__tests__/_color.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import expect from 'expect.js';
import ngMock from 'ng_mock';
import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats';
import { fieldFormats } from 'ui/registry/field_formats';
describe('Color Format', function () {
let fieldFormats;
let ColorFormat;

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
fieldFormats = Private(RegistryFieldFormatsProvider);
ColorFormat = fieldFormats.getType('color');
}));
const ColorFormat = fieldFormats.getType('color');

describe('field is a number', () => {
it('should add colors if the value is in range', function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import _ from 'lodash';
import expect from 'expect.js';
import ngMock from 'ng_mock';
import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats';
import chrome from 'ui/chrome';
import { fieldFormats } from 'ui/registry/field_formats';
import { FieldFormat } from '../../../../../ui/field_formats/field_format';

let fieldFormats;
let config;
let getConfig;
const config = chrome.getUiSettingsClient();


const formatIds = [
'bytes',
Expand All @@ -27,12 +26,7 @@ const formatIds = [
// eslint-disable-next-line @elastic/kibana-custom/no-default-export
export default describe('conformance', function () {

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private, $injector) {
fieldFormats = Private(RegistryFieldFormatsProvider);
config = $injector.get('config');
getConfig = (...args) => config.get(...args);
}));
const getConfig = (...args) => config.get(...args);

formatIds.forEach(function (id) {
let instance;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import expect from 'expect.js';
import ngMock from 'ng_mock';
import moment from 'moment-timezone';
import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats';
import { fieldFormats } from 'ui/registry/field_formats';
describe('Date Format', function () {
let fieldFormats;
let settings;
let convert;
let $scope;
Expand All @@ -14,7 +13,6 @@ describe('Date Format', function () {
$scope = $rootScope;
settings = config;

fieldFormats = Private(RegistryFieldFormatsProvider);
const getConfig = (...args) => config.get(...args);
const DateFormat = fieldFormats.getType('date');
const date = new DateFormat({}, getConfig);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import expect from 'expect.js';
import ngMock from 'ng_mock';
import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats';
import { fieldFormats } from 'ui/registry/field_formats';

describe('Duration Format', function () {
let fieldFormats;
let DurationFormat;

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
fieldFormats = Private(RegistryFieldFormatsProvider);
DurationFormat = fieldFormats.getType('duration');
}));

const DurationFormat = fieldFormats.getType('duration');

test({ inputFormat: 'seconds', outputFormat: 'humanize' })
(-60, 'minus a minute')
Expand Down
11 changes: 3 additions & 8 deletions src/core_plugins/kibana/public/field_formats/__tests__/_ip.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import expect from 'expect.js';
import ngMock from 'ng_mock';
import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats';
import { fieldFormats } from 'ui/registry/field_formats';
describe('IP Address Format', function () {
let ip;
beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
const fieldFormats = Private(RegistryFieldFormatsProvider);
ip = fieldFormats.getInstance('ip');
}));

const ip = fieldFormats.getInstance('ip');

it('converts a value from a decimal to a string', function () {
expect(ip.convert(1186489492)).to.be('70.184.100.148');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,20 @@ import $ from 'jquery';
import _ from 'lodash';
import expect from 'expect.js';
import ngMock from 'ng_mock';
import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats';
import { fieldFormats } from 'ui/registry/field_formats';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';
import FixturesHitsProvider from 'fixtures/hits';
describe('_source formatting', function () {

let fieldFormats;

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
fieldFormats = Private(RegistryFieldFormatsProvider);
}));

describe('Source format', function () {
let indexPattern;
let hits;
let format;
let convertHtml;

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
hits = Private(FixturesHitsProvider);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
import expect from 'expect.js';
import ngMock from 'ng_mock';
import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats';
import { fieldFormats } from 'ui/registry/field_formats';
describe('String Format', function () {
let StringFormat;

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
const fieldFormats = Private(RegistryFieldFormatsProvider);
StringFormat = fieldFormats.getType('string');
}));
const StringFormat = fieldFormats.getType('string');

it('convert a string to lower case', function () {
const string = new StringFormat({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import expect from 'expect.js';
import ngMock from 'ng_mock';
import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats';
import { fieldFormats } from 'ui/registry/field_formats';
describe('String Truncate Format', function () {
let fieldFormats;

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
fieldFormats = Private(RegistryFieldFormatsProvider);
}));

it('truncate large string', function () {
const Truncate = fieldFormats.getType('truncate');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import $ from 'jquery';
import expect from 'expect.js';
import ngMock from 'ng_mock';
import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats';
import { fieldFormats } from 'ui/registry/field_formats';
describe('Url Format', function () {

let fieldFormats;

beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {
fieldFormats = Private(RegistryFieldFormatsProvider);
}));

const unwrap = $el => {
expect($el.is('span[ng-non-bindable]')).to.be.ok();
Expand Down
28 changes: 14 additions & 14 deletions src/core_plugins/kibana/public/field_formats/register.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats';
import { fieldFormats } from 'ui/registry/field_formats';
import { createUrlFormat } from '../../common/field_formats/types/url';
import { createBytesFormat } from '../../common/field_formats/types/bytes';
import { createDateFormat } from '../../common/field_formats/types/date';
Expand All @@ -13,16 +13,16 @@ import { createColorFormat } from '../../common/field_formats/types/color';
import { createTruncateFormat } from '../../common/field_formats/types/truncate';
import { createBoolFormat } from '../../common/field_formats/types/boolean';

RegistryFieldFormatsProvider.register(createUrlFormat);
RegistryFieldFormatsProvider.register(createBytesFormat);
RegistryFieldFormatsProvider.register(createDateFormat);
RegistryFieldFormatsProvider.register(createRelativeDateFormat);
RegistryFieldFormatsProvider.register(createDurationFormat);
RegistryFieldFormatsProvider.register(createIpFormat);
RegistryFieldFormatsProvider.register(createNumberFormat);
RegistryFieldFormatsProvider.register(createPercentFormat);
RegistryFieldFormatsProvider.register(createStringFormat);
RegistryFieldFormatsProvider.register(createSourceFormat);
RegistryFieldFormatsProvider.register(createColorFormat);
RegistryFieldFormatsProvider.register(createTruncateFormat);
RegistryFieldFormatsProvider.register(createBoolFormat);
fieldFormats.register(createUrlFormat);
fieldFormats.register(createBytesFormat);
fieldFormats.register(createDateFormat);
fieldFormats.register(createRelativeDateFormat);
fieldFormats.register(createDurationFormat);
fieldFormats.register(createIpFormat);
fieldFormats.register(createNumberFormat);
fieldFormats.register(createPercentFormat);
fieldFormats.register(createStringFormat);
fieldFormats.register(createSourceFormat);
fieldFormats.register(createColorFormat);
fieldFormats.register(createTruncateFormat);
fieldFormats.register(createBoolFormat);
4 changes: 2 additions & 2 deletions src/test_utils/public/stub_index_pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import Promise from 'bluebird';
import { IndexPatternProvider, getRoutes } from 'ui/index_patterns/_index_pattern';
import { formatHit } from 'ui/index_patterns/_format_hit';
import { getComputedFields } from 'ui/index_patterns/_get_computed_fields';
import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats';
import { fieldFormats } from 'ui/registry/field_formats';
import { IndexPatternsFlattenHitProvider } from 'ui/index_patterns/_flatten_hit';
import { IndexPatternsFieldListProvider } from 'ui/index_patterns/_field_list';

export default function (Private) {
const fieldFormats = Private(RegistryFieldFormatsProvider);

const flattenHit = Private(IndexPatternsFlattenHitProvider);
const FieldList = Private(IndexPatternsFieldListProvider);
const IndexPattern = Private(IndexPatternProvider);
Expand Down
6 changes: 3 additions & 3 deletions src/ui/public/agg_response/geo_json/_tooltip_formatter.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import $ from 'jquery';
import _ from 'lodash';
import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats';
import { fieldFormats } from 'ui/registry/field_formats';

export function TileMapTooltipFormatterProvider($compile, $rootScope) {

export function TileMapTooltipFormatterProvider($compile, $rootScope, Private) {

const fieldFormats = Private(RegistryFieldFormatsProvider);
const $tooltipScope = $rootScope.$new();
const $el = $('<div>').html(require('ui/agg_response/geo_json/_tooltip.html'));
$compile($el)($tooltipScope);
Expand Down
4 changes: 2 additions & 2 deletions src/ui/public/agg_table/agg_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import 'ui/agg_table/agg_table.less';
import _ from 'lodash';
import { uiModules } from 'ui/modules';
import aggTableTemplate from 'ui/agg_table/agg_table.html';
import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats';
import { fieldFormats } from 'ui/registry/field_formats';

uiModules
.get('kibana', ['RecursionHelper'])
.directive('kbnAggTable', function ($filter, config, Private, RecursionHelper) {
const fieldFormats = Private(RegistryFieldFormatsProvider);

const numberFormatter = fieldFormats.getDefaultInstance('number').getConverterFor('text');

return {
Expand Down
8 changes: 3 additions & 5 deletions src/ui/public/agg_types/__tests__/agg_type.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,20 @@ import ngMock from 'ng_mock';
import 'ui/private';
import { AggParams } from 'ui/agg_types/agg_params';
import { VisProvider } from 'ui/vis';
import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats';
import { fieldFormats } from 'ui/registry/field_formats';
import { AggTypesAggTypeProvider } from 'ui/agg_types/agg_type';
import FixturesStubbedLogstashIndexPatternProvider from 'fixtures/stubbed_logstash_index_pattern';

describe('AggType Class', function () {
let AggType;
let indexPattern;
let fieldFormat;
let Vis;


beforeEach(ngMock.module('kibana'));
beforeEach(ngMock.inject(function (Private) {

Vis = Private(VisProvider);
fieldFormat = Private(RegistryFieldFormatsProvider);
AggType = Private(AggTypesAggTypeProvider);
indexPattern = Private(FixturesStubbedLogstashIndexPatternProvider);
}));
Expand Down Expand Up @@ -89,7 +87,7 @@ describe('AggType Class', function () {

let aggConfig = vis.aggs.byTypeName.date_histogram[0];

expect(aggType.getFormat(aggConfig)).to.be(fieldFormat.getDefaultInstance('date'));
expect(aggType.getFormat(aggConfig)).to.be(fieldFormats.getDefaultInstance('date'));

vis = new Vis(indexPattern, {
type: 'metric',
Expand All @@ -102,7 +100,7 @@ describe('AggType Class', function () {
});
aggConfig = vis.aggs.byTypeName.count[0];

expect(aggType.getFormat(aggConfig)).to.be(fieldFormat.getDefaultInstance('string'));
expect(aggType.getFormat(aggConfig)).to.be(fieldFormats.getDefaultInstance('string'));
});

it('can be overridden via config', function () {
Expand Down
6 changes: 3 additions & 3 deletions src/ui/public/agg_types/agg_type.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import _ from 'lodash';
import { AggParams } from 'ui/agg_types/agg_params';
import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats';
import { fieldFormats } from 'ui/registry/field_formats';

export function AggTypesAggTypeProvider() {

export function AggTypesAggTypeProvider(Private) {
const fieldFormats = Private(RegistryFieldFormatsProvider);


/**
Expand Down
3 changes: 1 addition & 2 deletions src/ui/public/agg_types/buckets/date_range.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ import 'ui/directives/validate_date_math';
import 'ui/directives/documentation_href';
import { AggTypesBucketsBucketAggTypeProvider } from 'ui/agg_types/buckets/_bucket_agg_type';
import { AggTypesBucketsCreateFilterDateRangeProvider } from 'ui/agg_types/buckets/create_filter/date_range';
import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats';
import { fieldFormats } from 'ui/registry/field_formats';
import dateRangesTemplate from 'ui/agg_types/controls/date_ranges.html';

export function AggTypesBucketsDateRangeProvider(Private) {
const BucketAggType = Private(AggTypesBucketsBucketAggTypeProvider);
const createFilter = Private(AggTypesBucketsCreateFilterDateRangeProvider);
const fieldFormats = Private(RegistryFieldFormatsProvider);


return new BucketAggType({
Expand Down
4 changes: 2 additions & 2 deletions src/ui/public/agg_types/metrics/cardinality.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AggTypesMetricsMetricAggTypeProvider } from 'ui/agg_types/metrics/metric_agg_type';
import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats';
import { fieldFormats } from 'ui/registry/field_formats';

export function AggTypesMetricsCardinalityProvider(Private) {
const MetricAggType = Private(AggTypesMetricsMetricAggTypeProvider);
const fieldFormats = Private(RegistryFieldFormatsProvider);


return new MetricAggType({
name: 'cardinality',
Expand Down
4 changes: 2 additions & 2 deletions src/ui/public/agg_types/metrics/count.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AggTypesMetricsMetricAggTypeProvider } from 'ui/agg_types/metrics/metric_agg_type';
import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats';
import { fieldFormats } from 'ui/registry/field_formats';

export function AggTypesMetricsCountProvider(Private) {
const MetricAggType = Private(AggTypesMetricsMetricAggTypeProvider);
const fieldFormats = Private(RegistryFieldFormatsProvider);


return new MetricAggType({
name: 'count',
Expand Down
4 changes: 2 additions & 2 deletions src/ui/public/agg_types/metrics/metric_agg_type.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import _ from 'lodash';
import { AggTypesAggTypeProvider } from 'ui/agg_types/agg_type';
import { RegistryFieldFormatsProvider } from 'ui/registry/field_formats';
import { fieldFormats } from 'ui/registry/field_formats';

export function AggTypesMetricsMetricAggTypeProvider(Private) {
const AggType = Private(AggTypesAggTypeProvider);
const fieldFormats = Private(RegistryFieldFormatsProvider);


_.class(MetricAggType).inherits(AggType);
function MetricAggType(config) {
Expand Down
Loading

0 comments on commit adabbf3

Please sign in to comment.