Performance: Standardize lodash imports to use destructured members (#33040)

* Performance: Standardize lodash imports to use destructured members
Changes lodash imports of the form `import x from 'lodash/x'` to
`import { x } from 'lodash'` to reduce bundle size.

* Remove unnecessary _ import from Graph component

* Enforce lodash import style

* Fix remaining lodash imports
This commit is contained in:
kay delaney
2021-04-21 08:38:00 +01:00
committed by GitHub
parent 2bb7eb18d1
commit bad048b7ba
299 changed files with 1135 additions and 1137 deletions

View File

@@ -1,4 +1,4 @@
import _ from 'lodash';
import { cloneDeep, map as _map, reduce, get, has, extend, omit, pick, isString } from 'lodash';
import {
dateMath,
@@ -120,12 +120,12 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
classicQuery(options: any): Observable<DataQueryResponse> {
let timeFilter = this.getTimeFilter(options);
const scopedVars = options.scopedVars;
const targets = _.cloneDeep(options.targets);
const targets = cloneDeep(options.targets);
const queryTargets: any[] = [];
let i, y;
let allQueries = _.map(targets, (target) => {
let allQueries = _map(targets, (target) => {
if (target.hide) {
return '';
}
@@ -353,7 +353,7 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
return '';
}
return _.reduce(
return reduce(
params,
(memo, value, key) => {
if (value === null || value === undefined) {
@@ -410,7 +410,7 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
return this._seriesQuery(query)
.toPromise()
.then((res: any) => {
const error = _.get(res, 'results[0].error');
const error = get(res, 'results[0].error');
if (error) {
return { status: 'error', message: error };
}
@@ -440,13 +440,13 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
const { q } = data;
if (method === 'POST' && _.has(data, 'q')) {
if (method === 'POST' && has(data, 'q')) {
// verb is POST and 'q' param is defined
_.extend(params, _.omit(data, ['q']));
data = this.serializeParams(_.pick(data, ['q']));
extend(params, omit(data, ['q']));
data = this.serializeParams(pick(data, ['q']));
} else if (method === 'GET' || method === 'POST') {
// verb is GET, or POST without 'q' param
_.extend(params, data);
extend(params, data);
data = null;
}
@@ -540,7 +540,7 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
}
getInfluxTime(date: any, roundUp: any, timezone: any) {
if (_.isString(date)) {
if (isString(date)) {
if (date === 'now') {
return 'now()';
}