Skip to content

Commit 10b32c2

Browse files
[ui/public/utils] Copy rarely used items to where they are consumed (#53819)
* [ui/public/utils] Copy rarely used items to where they are consumed Closes: #52841 * sort_prefix_first 👉x-pack/legacy/plugins/kuery_autocomplete * numeric 👉src/legacy/core_plugins/kibana/public/management * diff_object + tests 👉ui/state_management * function + tests 👉ui/state_management (function.js was removed!) * key_map 👉ui/directives * leastCommonMultiple 👉ui/vis * string_utils 👉ui/saved_objects * collection * parse_interval * it -> test * fix CI * fix PR comments Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent d1df426 commit 10b32c2

47 files changed

Lines changed: 756 additions & 769 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/legacy/core_plugins/kibana/public/management/sections/objects/_view.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { uiModules } from 'ui/modules';
2929
import { fatalError, toastNotifications } from 'ui/notify';
3030
import 'ui/accessibility/kbn_ui_ace_keyboard_mode';
3131
import { SavedObjectsClientProvider } from 'ui/saved_objects';
32-
import { isNumeric } from 'ui/utils/numeric';
32+
import { isNumeric } from './lib/numeric';
3333
import { canViewInApp } from './lib/in_app_url';
3434

3535
import { castEsToKbnFieldTypeName } from '../../../../../../../plugins/data/public';

src/legacy/ui/public/utils/sort_prefix_first.ts renamed to src/legacy/core_plugins/kibana/public/management/sections/objects/lib/case_conversion.test.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,20 @@
1717
* under the License.
1818
*/
1919

20-
import { partition } from 'lodash';
20+
import { keysToCamelCaseShallow } from './case_conversion';
2121

22-
export function sortPrefixFirst(array: any[], prefix?: string | number, property?: string): any[] {
23-
if (!prefix) {
24-
return array;
25-
}
26-
const lowerCasePrefix = ('' + prefix).toLowerCase();
22+
describe('keysToCamelCaseShallow', () => {
23+
test("should convert all of an object's keys to camel case", () => {
24+
const data = {
25+
camelCase: 'camelCase',
26+
'kebab-case': 'kebabCase',
27+
snake_case: 'snakeCase',
28+
};
2729

28-
const partitions = partition(array, entry => {
29-
const value = ('' + (property ? entry[property] : entry)).toLowerCase();
30-
return value.startsWith(lowerCasePrefix);
30+
const result = keysToCamelCaseShallow(data);
31+
32+
expect(result.camelCase).toBe('camelCase');
33+
expect(result.kebabCase).toBe('kebabCase');
34+
expect(result.snakeCase).toBe('snakeCase');
3135
});
32-
return [...partitions[0], ...partitions[1]];
33-
}
36+
});

src/legacy/ui/public/utils/parse_interval.d.ts renamed to src/legacy/core_plugins/kibana/public/management/sections/objects/lib/case_conversion.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
* under the License.
1818
*/
1919

20-
import moment from 'moment';
20+
import { mapKeys, camelCase } from 'lodash';
2121

22-
export function parseInterval(interval: string): moment.Duration | null;
22+
export function keysToCamelCaseShallow(object: Record<string, any>) {
23+
return mapKeys(object, (value, key) => camelCase(key));
24+
}

src/legacy/core_plugins/kibana/public/management/sections/objects/lib/find_objects.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818
*/
1919

2020
import { kfetch } from 'ui/kfetch';
21-
import { keysToCamelCaseShallow } from 'ui/utils/case_conversion';
21+
import { keysToCamelCaseShallow } from './case_conversion';
2222

2323
export async function findObjects(findOptions) {
2424
const response = await kfetch({
2525
method: 'GET',
2626
pathname: '/api/kibana/management/saved_objects/_find',
2727
query: findOptions,
2828
});
29+
2930
return keysToCamelCaseShallow(response);
3031
}

src/legacy/ui/public/utils/numeric.ts renamed to src/legacy/core_plugins/kibana/public/management/sections/objects/lib/numeric.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
* under the License.
1818
*/
1919

20-
import _ from 'lodash';
20+
import { isNaN } from 'lodash';
2121

2222
export function isNumeric(v: any): boolean {
23-
return !_.isNaN(v) && (typeof v === 'number' || (!Array.isArray(v) && !_.isNaN(parseFloat(v))));
23+
return !isNaN(v) && (typeof v === 'number' || (!Array.isArray(v) && !isNaN(parseFloat(v))));
2424
}

src/legacy/core_plugins/kibana/public/management/sections/settings/lib/get_category_name.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
* under the License.
1818
*/
1919

20-
import { StringUtils } from 'ui/utils/string_utils';
2120
import { i18n } from '@kbn/i18n';
2221

22+
const upperFirst = (str = '') => str.replace(/^./, str => str.toUpperCase());
23+
2324
const names = {
2425
general: i18n.translate('kbn.management.settings.categoryNames.generalLabel', {
2526
defaultMessage: 'General',
@@ -51,5 +52,5 @@ const names = {
5152
};
5253

5354
export function getCategoryName(category) {
54-
return category ? names[category] || StringUtils.upperFirst(category) : '';
55+
return category ? names[category] || upperFirst(category) : '';
5556
}

src/legacy/ui/public/utils/supports.js renamed to src/legacy/core_plugins/tile_map/public/css_filters.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,21 @@ import _ from 'lodash';
2222
/**
2323
* just a place to put feature detection checks
2424
*/
25-
export const supports = {
26-
cssFilters: (function() {
27-
const e = document.createElement('img');
28-
const rules = ['webkitFilter', 'mozFilter', 'msFilter', 'filter'];
29-
const test = 'grayscale(1)';
30-
rules.forEach(function(rule) {
31-
e.style[rule] = test;
32-
});
25+
export const supportsCssFilters = (function() {
26+
const e = document.createElement('img');
27+
const rules = ['webkitFilter', 'mozFilter', 'msFilter', 'filter'];
28+
const test = 'grayscale(1)';
3329

34-
document.body.appendChild(e);
35-
const styles = window.getComputedStyle(e);
36-
const can = _(styles)
37-
.pick(rules)
38-
.includes(test);
39-
document.body.removeChild(e);
30+
rules.forEach(function(rule) {
31+
e.style[rule] = test;
32+
});
4033

41-
return can;
42-
})(),
43-
};
34+
document.body.appendChild(e);
35+
const styles = window.getComputedStyle(e);
36+
const can = _(styles)
37+
.pick(rules)
38+
.includes(test);
39+
document.body.removeChild(e);
40+
41+
return can;
42+
})();

src/legacy/core_plugins/tile_map/public/tile_map_type.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import React from 'react';
2121
import { i18n } from '@kbn/i18n';
2222

23-
import { supports } from 'ui/utils/supports';
2423
import { Schemas } from 'ui/vis/editors/default/schemas';
2524
import { colorSchemas } from 'ui/vislib/components/color/truncated_colormaps';
2625
import { convertToGeoJson } from 'ui/vis/map/convert_to_geojson';
@@ -29,6 +28,7 @@ import { createTileMapVisualization } from './tile_map_visualization';
2928
import { Status } from '../../visualizations/public';
3029
import { TileMapOptions } from './components/tile_map_options';
3130
import { MapTypes } from './map_types';
31+
import { supportsCssFilters } from './css_filters';
3232

3333
export function createTileMapTypeDefinition(dependencies) {
3434
const CoordinateMapsVisualization = createTileMapVisualization(dependencies);
@@ -44,7 +44,7 @@ export function createTileMapTypeDefinition(dependencies) {
4444
defaultMessage: 'Plot latitude and longitude coordinates on a map',
4545
}),
4646
visConfig: {
47-
canDesaturate: !!supports.cssFilters,
47+
canDesaturate: Boolean(supportsCssFilters),
4848
defaults: {
4949
colorSchema: 'Yellow to Red',
5050
mapType: 'Scaled Circle Markers',

src/legacy/core_plugins/timelion/public/directives/saved_object_finder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919

2020
import _ from 'lodash';
2121
import rison from 'rison-node';
22-
import { keyMap } from 'ui/utils/key_map';
2322
import { uiModules } from 'ui/modules';
2423
import 'ui/directives/input_focus';
2524
import 'ui/directives/paginate';
2625
import savedObjectFinderTemplate from './saved_object_finder.html';
2726
import { savedSheetLoader } from '../services/saved_sheets';
27+
import { keyMap } from 'ui/directives/key_map';
2828

2929
const module = uiModules.get('kibana');
3030

src/legacy/core_plugins/vis_type_timeseries/public/lib/validate_interval.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
* under the License.
1818
*/
1919

20-
import { parseInterval } from 'ui/utils/parse_interval';
2120
import { GTE_INTERVAL_RE } from '../../common/interval_regexp';
2221
import { i18n } from '@kbn/i18n';
22+
import { parseInterval } from '../../../../../plugins/data/public';
2323

2424
export function validateInterval(bounds, panel, maxBuckets) {
2525
const { interval } = panel;

0 commit comments

Comments
 (0)