New platform cleanup filters (#34555) (#35067)

* Delete label filter
* Delete risonDecode
* Deleted rison
* removed fieldType filter
* Deleted field type tests
* Replaced uriescape filter with use of encodeURIComponent
* Delete short dots filter
* Removed usages of moment filter (and moved it to watcher)
* Code review changes
This commit is contained in:
Liza Katz 2019-04-15 15:18:23 +03:00 committed by GitHub
parent 539905511a
commit 0ffe5e4f54
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 62 additions and 635 deletions

View file

@ -20,6 +20,7 @@
import _ from 'lodash';
import React from 'react';
import angular from 'angular';
import moment from 'moment';
import chrome from 'ui/chrome';
import dateMath from '@elastic/datemath';
@ -32,7 +33,6 @@ import * as filterActions from '../doc_table/actions/filter';
import 'ui/listen';
import 'ui/visualize';
import 'ui/fixed_scroll';
import 'ui/filters/moment';
import 'ui/index_patterns';
import 'ui/state_management/app_state';
import { timefilter } from 'ui/timefilter';
@ -792,6 +792,10 @@ function discoverController(
$scope.time = timefilter.getTime();
};
$scope.toMoment = function (datetime) {
return moment(datetime).format(config.get('dateFormat'));
};
$scope.updateRefreshInterval = function () {
$scope.refreshInterval = timefilter.getRefreshInterval();
};

View file

@ -29,7 +29,7 @@
<span
data-test-subj="docTableHeader-{{name}}"
>
{{name | shortDots}}
{{getShortDotsName(name)}}
<button
data-test-subj="docTableHeaderFieldSort_{{name}}"
id="docTableHeaderFieldSort{{name}}"

View file

@ -18,13 +18,13 @@
*/
import _ from 'lodash';
import 'ui/filters/short_dots';
import { shortenDottedString } from '../../../../common/utils/shorten_dotted_string';
import headerHtml from './table_header.html';
import { uiModules } from 'ui/modules';
const module = uiModules.get('app/discover');
module.directive('kbnTableHeader', function (shortDotsFilter, i18n) {
module.directive('kbnTableHeader', function (i18n) {
return {
restrict: 'A',
scope: {
@ -38,6 +38,11 @@ module.directive('kbnTableHeader', function (shortDotsFilter, i18n) {
template: headerHtml,
controller: function ($scope, config) {
$scope.hideTimeColumn = config.get('doc_table:hideTimeColumn');
$scope.isShortDots = config.get('shortDots:enable');
$scope.getShortDotsName = function getShortDotsName(columnName) {
return $scope.isShortDots ? shortenDottedString(columnName) : columnName;
};
$scope.isSortableColumn = function isSortableColumn(columnName) {
return (
@ -49,9 +54,10 @@ module.directive('kbnTableHeader', function (shortDotsFilter, i18n) {
$scope.tooltip = function (column) {
if (!$scope.isSortableColumn(column)) return '';
const name = $scope.isShortDots ? shortenDottedString(column) : column;
return i18n('kbn.docTable.tableHeader.sortByColumnTooltip', {
defaultMessage: 'Sort by {columnName}',
values: { columnName: shortDotsFilter(column) },
values: { columnName: name },
});
};

View file

@ -21,8 +21,6 @@ import _ from 'lodash';
import $ from 'jquery';
import rison from 'rison-node';
import 'plugins/kibana/doc_viewer';
import 'ui/filters/uriescape';
import 'ui/filters/short_dots';
import { noWhiteSpace } from '../../../../common/utils/no_white_space';
import openRowHtml from './table_row/open.html';
import detailsHtml from './table_row/details.html';
@ -95,6 +93,7 @@ module.directive('kbnTableRow', function ($compile, $httpParamSerializer, kbnUrl
$detailsTr.html(detailsHtml);
$detailsScope.row = $scope.row;
$detailsScope.uriEncodedId = encodeURIComponent($detailsScope.row._id);
$compile($detailsTr)($detailsScope);
};

View file

@ -30,7 +30,7 @@
<a
class="euiLink"
data-test-subj="docTableRowAction"
ng-href="#/doc/{{indexPattern.id}}/{{row._index}}/{{row._type}}/?id={{row._id | uriescape}}"
ng-href="#/doc/{{indexPattern.id}}/{{row._index}}/{{row._type}}/?id={{uriEncodedId}}"
i18n-id="kbn.docTable.tableRow.viewSingleDocumentLinkText"
i18n-default-message="View single document"
></a>

View file

@ -130,7 +130,7 @@
<span
tooltip="{{::'kbn.discover.howToChangeTheTimeTooltip' | i18n: {defaultMessage: 'To change the time, click the clock icon in the navigation bar'} }}"
>
{{timeRange.from | moment}} - {{timeRange.to | moment}}
{{toMoment(timeRange.from)}} - {{toMoment(timeRange.to)}}
</span>
&mdash;

View file

@ -17,7 +17,6 @@
* under the License.
*/
import '../filters/label';
import { IndexedArray } from '../indexed_array';
import { FieldParamType } from './param_types/field';
import { OptionedParamType } from './param_types/optioned';

View file

@ -20,7 +20,6 @@
import _ from 'lodash';
import chrome from '../../chrome';
import moment from 'moment-timezone';
import '../../filters/field_type';
import '../directives/validate_date_interval';
import { BucketAggType } from './_bucket_agg_type';
import { TimeBuckets } from '../../time_buckets';

View file

@ -23,7 +23,6 @@ import { FieldParamEditor } from '../controls/field';
import '../directives/scroll_bottom';
import { BaseParamType } from './base';
import '../filters/sort_prefix_first';
import '../../filters/field_type';
import { IndexedArray } from '../../indexed_array';
import { toastNotifications } from '../../notify';
import { createLegacyClass } from '../../utils/legacy_class';

View file

@ -19,7 +19,7 @@
import $ from 'jquery';
import { template } from 'lodash';
import '../filters/short_dots';
import { shortenDottedString } from '../../../core_plugins/kibana/common/utils/shorten_dotted_string';
import booleanFieldNameIcon from './field_name_icons/boolean_field_name_icon.html';
import conflictFieldNameIcon from './field_name_icons/conflict_field_name_icon.html';
import dateFieldNameIcon from './field_name_icons/date_field_name_icon.html';
@ -45,7 +45,7 @@ const compiledSourceFieldNameIcon = template(sourceFieldNameIcon);
const compiledStringFieldNameIcon = template(stringFieldNameIcon);
const compiledUnknownFieldNameIcon = template(unknownFieldNameIcon);
module.directive('fieldName', function ($compile, $rootScope, $filter, i18n) {
module.directive('fieldName', function ($compile, $rootScope, config, i18n) {
return {
restrict: 'AE',
scope: {
@ -126,7 +126,9 @@ module.directive('fieldName', function ($compile, $rootScope, $filter, i18n) {
const results = $scope.field ? !$scope.field.rowCount && !$scope.field.scripted : false;
const scripted = $scope.field ? $scope.field.scripted : false;
const displayName = $filter('shortDots')(name);
const isShortDots = config.get('shortDots:enable');
const displayName = isShortDots ? shortenDottedString(name) : name;
$el
.attr('title', name)

View file

@ -11,7 +11,7 @@
input-focus
disable-input-focus="disableAutoFocus"
ng-model="filter"
ng-attr-placeholder="{{ finder.properties.nouns | label }} Filter..."
ng-attr-placeholder="{{ finder.getLabel() }} Filter..."
ng-keydown="finder.filterKeyDown($event)"
name="filter"
type="text"

View file

@ -22,7 +22,7 @@ import rison from 'rison-node';
import { keyMap } from '../utils/key_map';
import { SavedObjectRegistryProvider } from '../saved_objects/saved_object_registry';
import { uiModules } from '../modules';
import '../filters/label';
import savedObjectFinderTemplate from './partials/saved_object_finder.html';
import './input_focus';
import './paginate';
@ -158,6 +158,10 @@ module.directive('savedObjectFinder', function ($location, kbnUrl, Private, conf
index: -1
};
self.getLabel = function () {
return _.words(self.properties.nouns).map(_.capitalize).join(' ');
};
//key handler for the filter text box
self.filterKeyDown = function ($event) {
switch (keyMap[$event.keyCode]) {

View file

@ -1,83 +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.
*/
import expect from '@kbn/expect';
import _ from 'lodash';
import ngMock from 'ng_mock';
import 'plugins/kibana/discover/index';
import '../field_type';
let filter;
let types;
const init = function () {
// Load the application
ngMock.module('kibana');
types = [
{ name: 's1', type: 'string' },
{ name: 's2', type: 'string' },
{ name: 's3', type: 'string' },
{ name: 'n1', type: 'number' },
{ name: 'n2', type: 'number' },
{ name: 'i1', type: 'ip' },
{ name: 'd1', type: 'date' },
];
// Create the scope
ngMock.inject(function ($filter) {
filter = $filter('fieldType');
});
};
describe('fieldType array filter', function () {
beforeEach(function () {
init();
});
it('should have a fieldType filter', function () {
expect(filter).to.not.be(null);
});
it('should have 3 string fields', function () {
expect(filter(types, 'string').length).to.be(3);
});
it('should have 2 number fields', function () {
expect(filter(types, 'number').length).to.be(2);
});
it('should have 1 ip field and 1 date field', function () {
expect(_.pluck(filter(types, ['date', 'ip']), 'name')).to.eql(['i1', 'd1']);
});
it('should return all fields when passed *', function () {
expect(filter(types, '*').length).to.be(7);
});
it('should allow negation', function () {
const resultNames = _.pluck(filter(types, '!string'), 'name');
expect(resultNames).to.eql(['n1', 'n2', 'i1', 'd1']);
});
});

View file

@ -1,54 +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.
*/
import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import 'plugins/kibana/discover/index';
// Load kibana and its applications
let filter;
const init = function () {
// Load the application
ngMock.module('kibana');
// Create the scope
ngMock.inject(function ($filter) {
filter = $filter('label');
});
};
describe('label filter', function () {
beforeEach(function () {
init();
});
it('should have a label filter', function () {
expect(filter).to.not.be(null);
});
it('should capitalize the first letter in a string', function () {
expect(filter('something')).to.be('Something');
});
it('should capitalize the first letter in every word', function () {
expect(filter('foo bar fizz buzz')).to.be('Foo Bar Fizz Buzz');
});
});

View file

@ -1,72 +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.
*/
import expect from '@kbn/expect';
import sinon from 'sinon';
import moment from 'moment';
import ngMock from 'ng_mock';
import '../moment';
let filter;
const anchor = '2014-01-01T06:06:06.666';
const init = function () {
// Load the application
ngMock.module('kibana');
// Create the scope
ngMock.inject(function ($filter) {
filter = $filter('moment');
});
};
describe('moment formatting filter', function () {
const sandbox = sinon.createSandbox();
beforeEach(function () {
sandbox.useFakeTimers(moment(anchor).valueOf());
init();
});
afterEach(function () {
sandbox.restore();
});
it('should have a moment filter', function () {
expect(filter).to.not.be(null);
});
// MMMM Do YYYY, HH:mm:ss.SSS
it('should format moments', function () {
expect(filter(moment())).to.be('Jan 1, 2014 @ 06:06:06.666');
});
it('should format dates', function () {
expect(filter(new Date())).to.be('Jan 1, 2014 @ 06:06:06.666');
});
it('should return the original value if passed anything other than a moment or Date', function () {
expect(filter('beer')).to.be('beer');
expect(filter(1)).to.be(1);
expect(filter([])).to.eql([]);
});
});

View file

@ -1,72 +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.
*/
import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import 'plugins/kibana/discover/index';
// Load kibana and its applications
let rison;
let risonDecode;
const init = function () {
// Load the application
ngMock.module('kibana');
// Create the scope
ngMock.inject(function ($filter) {
rison = $filter('rison');
risonDecode = $filter('risonDecode');
});
};
describe('rison filters', function () {
const testObj = {
time: {
from: 'now-15m',
to: 'now'
}
};
const testRison = '(time:(from:now-15m,to:now))';
beforeEach(function () {
init();
});
describe('rison', function () {
it('should have the filter', function () {
expect(rison).to.not.be(null);
});
it('should rison encode data', function () {
expect(rison(testObj)).to.be(testRison);
});
});
describe('risonDecode', function () {
it('should have the filter', function () {
expect(risonDecode).to.not.be(null);
});
it('should decode rison data', function () {
expect(risonDecode(testRison)).to.eql(testObj);
});
});
});

View file

@ -1,70 +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.
*/
import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import 'plugins/kibana/discover/index';
import '../short_dots';
let filter;
let config;
const init = function () {
// Load the application
ngMock.module('kibana');
// Create the scope
ngMock.inject(function ($filter, _config_) {
config = _config_;
filter = $filter('shortDots');
});
};
describe('shortDots filter', function () {
beforeEach(function () {
init();
});
it('should have a uriescape filter', function () {
expect(filter).to.not.be(null);
});
it('should shorten foo.bar.baz to f.b.baz when shortDots:enable is true', function () {
config.set('shortDots:enable', true);
expect(filter('foo.bar.baz')).to.be('f.b.baz');
});
it('should not shorten when shortDots:enable is false', function () {
config.set('shortDots:enable', false);
expect(filter('foo.bar.baz')).to.be('foo.bar.baz');
});
it('should not shorten floating point numbers in any case', function () {
config.set('shortDots:enable', false);
expect(filter(12345.6789)).to.be(12345.6789);
config.set('shortDots:enable', true);
expect(filter(12345.6789)).to.be(12345.6789);
});
});

View file

@ -1,52 +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.
*/
import expect from '@kbn/expect';
import ngMock from 'ng_mock';
import 'plugins/kibana/discover/index';
let filter;
const init = function () {
// Load the application
ngMock.module('kibana');
// Create the scope
ngMock.inject(function ($filter) {
filter = $filter('uriescape');
});
};
describe('uriescape filter', function () {
beforeEach(function () {
init();
});
it('should have a uriescape filter', function () {
expect(filter).to.not.be(null);
});
it('should encodeURIComponent a string', function () {
expect(filter('this and that')).to.be('this%20and%20that');
});
});

View file

@ -1,30 +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.
*/
import { propFilter } from './_prop_filter';
import { uiModules } from '../modules';
// Gets all fields of a given type.
// You may also pass "*" to get all types
// Or an array of types to get all fields of that type
uiModules
.get('kibana')
.filter('fieldType', function () {
return propFilter('type');
});

View file

@ -1,29 +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.
*/
import { uiModules } from '../modules';
import { words, capitalize } from 'lodash';
uiModules
.get('kibana')
.filter('label', function () {
return function (str) {
return words(str).map(capitalize).join(' ');
};
});

View file

@ -1,33 +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.
*/
import moment from 'moment';
import _ from 'lodash';
import { uiModules } from '../modules';
uiModules
.get('kibana')
.filter('moment', function (config) {
return function (datetime) {
const format = config.get('dateFormat');
if (moment.isMoment(datetime)) return datetime.format(format);
if (_.isDate(datetime)) return moment(datetime).format(format);
return datetime;
};
});

View file

@ -1,34 +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.
*/
import rison from 'rison-node';
import { uiModules } from '../modules';
const module = uiModules.get('kibana');
module.filter('rison', function () {
return function (str) {
return rison.encode(str);
};
});
module.filter('risonDecode', function () {
return function (str) {
return rison.decode(str);
};
});

View file

@ -1,46 +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.
*/
import _ from 'lodash';
import { shortenDottedString } from '../../../core_plugins/kibana/common/utils/shorten_dotted_string';
import { uiModules } from '../modules';
// Shorts dot notated strings
// e.g., foo.bar.baz becomes f.b.baz
// 'foo.bar.baz'.replace(/(.+?\.)/g,function(v) {return v[0]+'.';});
uiModules
.get('kibana')
.filter('shortDots', function (Private) {
return Private(shortDotsFilterProvider);
});
function shortDotsFilterProvider(config) {
let filter;
config.watch('shortDots:enable', updateFilter);
return wrapper;
function updateFilter(enabled) {
filter = enabled ? shortenDottedString : _.identity;
}
function wrapper(str) {
return filter(str);
}
}

View file

@ -1,27 +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.
*/
import { uiModules } from '../modules';
uiModules
.get('kibana')
.filter('uriescape', function () {
return function (str) {
return encodeURIComponent(str);
};
});

View file

@ -210,7 +210,7 @@ describe('kbnUrl', function () {
const wrappers = [ ['{{', '}}'], ['{{ ', ' }}'], ['{{', ' }}'], ['{{ ', '}}'], ['{{ ', ' }}']];
// make sure filters are evaluated via angular expressions
const objIndex = 4; // used to case one replace as an object
const filters = ['', 'uppercase', '', 'uppercase', 'rison'];
const filters = ['', 'uppercase', '', 'uppercase', ''];
// the words (template keys) used must all be unique
const words = _.uniq(faker.Lorem.words(10)).slice(0, urlParts.length).map(function (word, i) {

View file

@ -18,8 +18,6 @@
*/
import _ from 'lodash';
import '../filters/uriescape';
import '../filters/rison';
import { uiModules } from '../modules';
import { AppStateProvider } from '../state_management/app_state';
@ -121,12 +119,7 @@ export function KbnUrlProvider($injector, $location, $rootScope, $parse, Private
}));
}
// append uriescape filter if not included
if (expr.indexOf('uriescape') === -1) {
expr += '|uriescape';
}
return $parse(expr)(paramObj);
return encodeURIComponent($parse(expr)(paramObj));
});
};

View file

@ -15,7 +15,7 @@
i18n-id="xpack.ml.fieldDataCard.cardDate.earliestLabel"
i18n-default-message="earliest {earliestCardStats}"
i18n-values="{
earliestCardStats: (card.stats.earliest | moment),
earliestCardStats: (toMoment(card.stats.earliest)),
}"
></div>
<div
@ -23,7 +23,7 @@
i18n-id="xpack.ml.fieldDataCard.cardDate.latestLabel"
i18n-default-message="latest {latestCardStats}"
i18n-values="{
latestCardStats: (card.stats.latest | moment),
latestCardStats: (toMoment(card.stats.latest)),
}"
></div>
</div>

View file

@ -12,8 +12,8 @@
import _ from 'lodash';
import $ from 'jquery';
import moment from 'moment';
import chrome from 'ui/chrome';
import 'ui/filters/moment';
import template from './field_data_card.html';
import { ML_JOB_FIELD_TYPES } from 'plugins/ml/../common/constants/field_types';
@ -22,7 +22,7 @@ import { mlEscape } from 'plugins/ml/util/string_utils';
import { uiModules } from 'ui/modules';
const module = uiModules.get('apps/ml');
module.directive('mlFieldDataCard', function () {
module.directive('mlFieldDataCard', function (config) {
function link(scope, element) {
scope.ML_JOB_FIELD_TYPES = ML_JOB_FIELD_TYPES;
@ -55,6 +55,10 @@ module.directive('mlFieldDataCard', function () {
}, true);
}
scope.toMoment = function (datetime) {
return moment(datetime).format(config.get('dateFormat'));
};
scope.getCardUrl = function () {
const urlBasePath = chrome.getBasePath();
const baseCardPath = `${urlBasePath}/plugins/ml/components/field_data_card/content_types`;

View file

@ -5,7 +5,7 @@
*/
import moment from 'moment';
import 'ui/filters/moment';
import '../../directives/moment';
import { isNumber, forEach, merge } from 'lodash';
import { uiModules } from 'ui/modules';
import { TimeBuckets } from 'ui/time_buckets';

View file

@ -0,0 +1,20 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import moment from 'moment';
import _ from 'lodash';
import { uiModules } from 'ui/modules';
uiModules
.get('xpack/watcher')
.filter('moment', function (config) {
return function (datetime) {
const format = config.get('dateFormat');
if (moment.isMoment(datetime)) return datetime.format(format);
if (_.isDate(datetime)) return moment(datetime).format(format);
return datetime;
};
});

View file

@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import 'ui/filters/moment';
import '../../../../directives/moment';
import { uiModules } from 'ui/modules';
import 'ui/pager_control';
import 'ui/pager';

View file

@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import 'ui/filters/moment';
import '../../../../directives/moment';
import { uiModules } from 'ui/modules';
import template from './watch_history_table.html';
import 'plugins/watcher/components/watch_state_icon';