Skip to content

Commit 22c8a6d

Browse files
committed
Optimized page loading and bundle size
1 parent ffd436d commit 22c8a6d

17 files changed

Lines changed: 88 additions & 84 deletions

File tree

x-pack/plugins/monitoring/public/alerts/thread_pool_rejections_alert/index.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import React from 'react';
88
import { i18n } from '@kbn/i18n';
99
import { EuiSpacer } from '@elastic/eui';
1010
import { Expression, Props } from '../components/duration/expression';
11-
12-
import { AlertTypeModel } from '../../../../triggers_actions_ui/public';
13-
11+
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
12+
import { AlertTypeModel } from '../../../../triggers_actions_ui/public/types';
1413
import { CommonAlertParamDetails } from '../../../common/types';
1514

1615
interface ThreadPoolTypes {

x-pack/plugins/monitoring/public/angular/providers/private.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@
8181
*
8282
* @param {[type]} prov [description]
8383
*/
84-
import _ from 'lodash';
84+
import { partial, uniqueId, isObject } from 'lodash';
8585

86-
const nextId = _.partial(_.uniqueId, 'privateProvider#');
86+
const nextId = partial(uniqueId, 'privateProvider#');
8787

8888
function name(fn) {
8989
return fn.name || fn.toString().split('\n').shift();
@@ -141,7 +141,7 @@ export function PrivateProvider() {
141141

142142
const context = {};
143143
let instance = $injector.invoke(prov, context, locals);
144-
if (!_.isObject(instance)) instance = context;
144+
if (!isObject(instance)) instance = context;
145145

146146
privPath.pop();
147147
return instance;
@@ -155,7 +155,7 @@ export function PrivateProvider() {
155155

156156
if ($delegateId != null && $delegateProv != null) {
157157
instance = instantiate(prov, {
158-
$decorate: _.partial(get, $delegateId, $delegateProv),
158+
$decorate: partial(get, $delegateId, $delegateProv),
159159
});
160160
} else {
161161
instance = instantiate(prov);

x-pack/plugins/monitoring/public/components/chart/chart_target.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import _ from 'lodash';
7+
import { get, isEqual, filter } from 'lodash';
88
import $ from 'jquery';
99
import React from 'react';
1010
import { eventBus } from './event_bus';
@@ -50,12 +50,12 @@ export class ChartTarget extends React.Component {
5050
}
5151

5252
UNSAFE_componentWillReceiveProps(newProps) {
53-
if (this.plot && !_.isEqual(newProps, this.props)) {
53+
if (this.plot && !isEqual(newProps, this.props)) {
5454
const { series, timeRange } = newProps;
5555

5656
const xaxisOptions = this.plot.getAxes().xaxis.options;
57-
xaxisOptions.min = _.get(timeRange, 'min');
58-
xaxisOptions.max = _.get(timeRange, 'max');
57+
xaxisOptions.min = get(timeRange, 'min');
58+
xaxisOptions.max = get(timeRange, 'max');
5959

6060
this.plot.setData(this.filterData(series, newProps.seriesToShow));
6161
this.plot.setupGrid();
@@ -73,7 +73,7 @@ export class ChartTarget extends React.Component {
7373
}
7474

7575
filterData(data, seriesToShow) {
76-
return _(data).filter(this.filterByShow(seriesToShow)).value();
76+
return filter(data, this.filterByShow(seriesToShow)).value();
7777
}
7878

7979
async getOptions() {
@@ -128,7 +128,7 @@ export class ChartTarget extends React.Component {
128128
this.handleThorPlotHover = (_event, pos, item, originalPlot) => {
129129
if (this.plot !== originalPlot) {
130130
// the crosshair is set for the original chart already
131-
this.plot.setCrosshair({ x: _.get(pos, 'x') });
131+
this.plot.setCrosshair({ x: get(pos, 'x') });
132132
}
133133
this.props.updateLegend(pos, item);
134134
};

x-pack/plugins/monitoring/public/components/chart/timeseries_visualization.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import _ from 'lodash';
7+
import { debounce, keys, has, includes, isFunction, difference, assign } from 'lodash';
88
import React from 'react';
99
import { getLastValue } from './get_last_value';
1010
import { TimeseriesContainer } from './timeseries_container';
@@ -17,7 +17,7 @@ export class TimeseriesVisualization extends React.Component {
1717
constructor(props) {
1818
super(props);
1919

20-
this.debouncedUpdateLegend = _.debounce(this.updateLegend, DEBOUNCE_SLOW_MS);
20+
this.debouncedUpdateLegend = debounce(this.updateLegend, DEBOUNCE_SLOW_MS);
2121
this.debouncedUpdateLegend = this.debouncedUpdateLegend.bind(this);
2222

2323
this.toggleFilter = this.toggleFilter.bind(this);
@@ -26,18 +26,18 @@ export class TimeseriesVisualization extends React.Component {
2626

2727
this.state = {
2828
values: {},
29-
seriesToShow: _.keys(values),
29+
seriesToShow: keys(values),
3030
ignoreVisibilityUpdates: false,
3131
};
3232
}
3333

3434
filterLegend(id) {
35-
if (!_.has(this.state.values, id)) {
35+
if (!has(this.state.values, id)) {
3636
return [];
3737
}
3838

39-
const notAllShown = _.keys(this.state.values).length !== this.state.seriesToShow.length;
40-
const isCurrentlyShown = _.includes(this.state.seriesToShow, id);
39+
const notAllShown = keys(this.state.values).length !== this.state.seriesToShow.length;
40+
const isCurrentlyShown = includes(this.state.seriesToShow, id);
4141
const seriesToShow = [];
4242

4343
if (notAllShown && isCurrentlyShown) {
@@ -59,7 +59,7 @@ export class TimeseriesVisualization extends React.Component {
5959
toggleFilter(_event, id) {
6060
const seriesToShow = this.filterLegend(id);
6161

62-
if (_.isFunction(this.props.onFilter)) {
62+
if (isFunction(this.props.onFilter)) {
6363
this.props.onFilter(seriesToShow);
6464
}
6565
}
@@ -94,21 +94,21 @@ export class TimeseriesVisualization extends React.Component {
9494
getValuesByX(this.props.series, pos.x, setValueCallback);
9595
}
9696
} else {
97-
_.assign(values, this.getLastValues());
97+
assign(values, this.getLastValues());
9898
}
9999

100100
this.setState({ values });
101101
}
102102

103103
UNSAFE_componentWillReceiveProps(props) {
104104
const values = this.getLastValues(props);
105-
const currentKeys = _.keys(this.state.values);
106-
const keys = _.keys(values);
107-
const diff = _.difference(keys, currentKeys);
105+
const currentKeys = keys(this.state.values);
106+
const valueKeys = keys(values);
107+
const diff = difference(valueKeys, currentKeys);
108108
const nextState = { values: values };
109109

110110
if (diff.length && !this.state.ignoreVisibilityUpdates) {
111-
nextState.seriesToShow = keys;
111+
nextState.seriesToShow = valueKeys;
112112
}
113113

114114
this.setState(nextState);

x-pack/plugins/monitoring/public/components/elasticsearch/nodes/nodes.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
EuiHealth,
2828
} from '@elastic/eui';
2929
import { i18n } from '@kbn/i18n';
30-
import _ from 'lodash';
30+
import { get } from 'lodash';
3131
import { ELASTICSEARCH_SYSTEM_ID } from '../../../../common/constants';
3232
import { FormattedMessage } from '@kbn/i18n/react';
3333
import { ListingCallOut } from '../../setup_mode/listing_callout';
@@ -58,7 +58,7 @@ const getNodeTooltip = (node) => {
5858
return null;
5959
};
6060

61-
const getSortHandler = (type) => (item) => _.get(item, [type, 'summary', 'lastVal']);
61+
const getSortHandler = (type) => (item) => get(item, [type, 'summary', 'lastVal']);
6262
const getColumns = (showCgroupMetricsElasticsearch, setupMode, clusterUuid, alerts) => {
6363
const cols = [];
6464

@@ -87,7 +87,7 @@ const getColumns = (showCgroupMetricsElasticsearch, setupMode, clusterUuid, aler
8787

8888
let setupModeStatus = null;
8989
if (isSetupModeFeatureEnabled(SetupModeFeature.MetricbeatMigration)) {
90-
const list = _.get(setupMode, 'data.byUuid', {});
90+
const list = get(setupMode, 'data.byUuid', {});
9191
const status = list[node.resolver] || {};
9292
const instance = {
9393
uuid: node.resolver,
@@ -396,7 +396,7 @@ export function ElasticsearchNodes({ clusterStatus, showCgroupMetricsElasticsear
396396
setupMode.data.totalUniqueInstanceCount
397397
) {
398398
const finishMigrationAction =
399-
_.get(setupMode.meta, 'liveClusterUuid') === clusterUuid
399+
get(setupMode.meta, 'liveClusterUuid') === clusterUuid
400400
? setupMode.shortcutToFinishMigration
401401
: setupMode.openFlyout;
402402

x-pack/plugins/monitoring/public/components/elasticsearch/shard_allocation/components/unassigned.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import _ from 'lodash';
7+
import { sortBy } from 'lodash';
88
import React from 'react';
99
import { Shard } from './shard';
1010
import { i18n } from '@kbn/i18n';
@@ -36,7 +36,7 @@ export class Unassigned extends React.Component {
3636
};
3737

3838
render() {
39-
const shards = _.sortBy(this.props.shards, 'shard').map(this.createShard);
39+
const shards = sortBy(this.props.shards, 'shard').map(this.createShard);
4040
return (
4141
<td className="monUnassigned" data-test-subj="clusterView-Unassigned">
4242
<EuiFlexGroup wrap className="monUnassigned__children">

x-pack/plugins/monitoring/public/components/elasticsearch/shard_allocation/lib/has_primary_children.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import _ from 'lodash';
7+
import { some } from 'lodash';
88

99
export function hasPrimaryChildren(item) {
10-
return _.some(item.children, { primary: true });
10+
return some(item.children, { primary: true });
1111
}

x-pack/plugins/monitoring/public/components/elasticsearch/shard_allocation/lib/vents.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import _ from 'lodash';
7+
import { each, isArray } from 'lodash';
88

99
export const _vents = {};
1010
export const vents = {
1111
vents: _vents,
1212
on: function (id, cb) {
13-
if (!_.isArray(_vents[id])) {
13+
if (!isArray(_vents[id])) {
1414
_vents[id] = [];
1515
}
1616
_vents[id].push(cb);
@@ -22,7 +22,7 @@ export const vents = {
2222
const args = Array.prototype.slice.call(arguments);
2323
const id = args.shift();
2424
if (_vents[id]) {
25-
_.each(_vents[id], function (cb) {
25+
each(_vents[id], function (cb) {
2626
cb.apply(null, args);
2727
});
2828
}

x-pack/plugins/monitoring/public/components/elasticsearch/shard_allocation/transformers/indices_by_nodes.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import _ from 'lodash';
7+
import { find, reduce, values } from 'lodash';
88
import { decorateShards } from '../lib/decorate_shards';
99

1010
export function indicesByNodes() {
@@ -39,7 +39,7 @@ export function indicesByNodes() {
3939
return obj;
4040
}
4141

42-
let nodeObj = _.find(obj[index].children, { id: node });
42+
let nodeObj = find(obj[index].children, { id: node });
4343
if (!nodeObj) {
4444
nodeObj = {
4545
id: node,
@@ -55,7 +55,7 @@ export function indicesByNodes() {
5555
return obj;
5656
}
5757

58-
const data = _.reduce(
58+
const data = reduce(
5959
decorateShards(shards, nodes),
6060
function (obj, shard) {
6161
obj = createIndex(obj, shard);
@@ -65,8 +65,7 @@ export function indicesByNodes() {
6565
{}
6666
);
6767

68-
return _(data)
69-
.values()
68+
return values(data)
7069
.sortBy((index) => [!index.unassignedPrimaries, /^\./.test(index.name), index.name])
7170
.value();
7271
};

x-pack/plugins/monitoring/public/components/elasticsearch/shard_allocation/transformers/nodes_by_indices.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import _ from 'lodash';
7+
import { find, some, reduce, values } from 'lodash';
88
import { hasPrimaryChildren } from '../lib/has_primary_children';
99
import { decorateShards } from '../lib/decorate_shards';
1010

@@ -32,7 +32,7 @@ export function nodesByIndices() {
3232
if (!obj[node]) {
3333
createNode(obj, nodes[node], node);
3434
}
35-
let indexObj = _.find(obj[node].children, { id: index });
35+
let indexObj = find(obj[node].children, { id: index });
3636
if (!indexObj) {
3737
indexObj = {
3838
id: index,
@@ -51,7 +51,7 @@ export function nodesByIndices() {
5151
}
5252

5353
let data = {};
54-
if (_.some(shards, isUnassigned)) {
54+
if (some(shards, isUnassigned)) {
5555
data.unassigned = {
5656
name: 'Unassigned',
5757
master: false,
@@ -60,10 +60,9 @@ export function nodesByIndices() {
6060
};
6161
}
6262

63-
data = _.reduce(decorateShards(shards, nodes), createIndexAddShard, data);
63+
data = reduce(decorateShards(shards, nodes), createIndexAddShard, data);
6464

65-
return _(data)
66-
.values()
65+
return values(data)
6766
.sortBy(function (node) {
6867
return [node.name !== 'Unassigned', !node.master, node.name];
6968
})

0 commit comments

Comments
 (0)