Chore: Adds typings to lodash (#16590)

This commit is contained in:
Hugo Häggmark
2019-04-15 12:11:52 +02:00
committed by GitHub
parent b267e96087
commit 7eabc282e9
88 changed files with 149 additions and 145 deletions

View File

@@ -410,7 +410,7 @@ export default class CloudWatchDatasource implements DataSourceApi<CloudWatchQue
getExpandedVariables(target, dimensionKey, variable, templateSrv) {
/* if the all checkbox is marked we should add all values to the targets */
const allSelected = _.find(variable.options, { selected: true, text: 'All' });
const allSelected: any = _.find(variable.options, { selected: true, text: 'All' });
const selectedVariables = _.filter(variable.options, v => {
if (allSelected) {
return v.text !== 'All';
@@ -427,7 +427,7 @@ export default class CloudWatchDatasource implements DataSourceApi<CloudWatchQue
};
});
const useSelectedVariables =
selectedVariables.some(s => {
selectedVariables.some((s: any) => {
return s.value === currentVariables[0].value;
}) || currentVariables[0].value === '$__all';
return (useSelectedVariables ? selectedVariables : currentVariables).map(v => {

View File

@@ -33,7 +33,7 @@ export class ElasticConfigCtrl {
this.current.database.length === 0 ||
this.current.database.startsWith('[logstash-]')
) {
const def = _.find(this.indexPatternTypes, {
const def: any = _.find(this.indexPatternTypes, {
value: this.current.jsonData.interval,
});
this.current.database = def.example || 'es-index-name';

View File

@@ -204,7 +204,7 @@ export class ElasticDatasource {
// validate that the index exist and has date field
return this.getFields({ type: 'date' }).then(
dateFields => {
const timeField = _.find(dateFields, { text: this.timeField });
const timeField: any = _.find(dateFields, { text: this.timeField });
if (!timeField) {
return {
status: 'error',

View File

@@ -222,7 +222,7 @@ export class ElasticResponse {
}
private getMetricName(metric) {
let metricDef = _.find(queryDef.metricAggTypes, { value: metric });
let metricDef: any = _.find(queryDef.metricAggTypes, { value: metric });
if (!metricDef) {
metricDef = _.find(queryDef.extendedStats, { value: metric });
}
@@ -258,12 +258,12 @@ export class ElasticResponse {
if (series.field && queryDef.isPipelineAgg(series.metric)) {
if (series.metric && queryDef.isPipelineAggWithMultipleBucketPaths(series.metric)) {
const agg = _.find(target.metrics, { id: series.metricId });
const agg: any = _.find(target.metrics, { id: series.metricId });
if (agg && agg.settings.script) {
metricName = agg.settings.script;
for (const pv of agg.pipelineVariables) {
const appliedAgg = _.find(target.metrics, { id: pv.pipelineAgg });
const appliedAgg: any = _.find(target.metrics, { id: pv.pipelineAgg });
if (appliedAgg) {
metricName = metricName.replace('params.' + pv.name, queryDef.describeMetric(appliedAgg));
}
@@ -272,7 +272,7 @@ export class ElasticResponse {
metricName = 'Unset';
}
} else {
const appliedAgg = _.find(target.metrics, { id: series.field });
const appliedAgg: any = _.find(target.metrics, { id: series.field });
if (appliedAgg) {
metricName += ' ' + queryDef.describeMetric(appliedAgg);
} else {
@@ -343,7 +343,7 @@ export class ElasticResponse {
}
trimDatapoints(aggregations, target) {
const histogram = _.find(target.bucketAggs, { type: 'date_histogram' });
const histogram: any = _.find(target.bucketAggs, { type: 'date_histogram' });
const shouldDropFirstAndLast = histogram && histogram.settings && histogram.settings.trimEdges;
if (shouldDropFirstAndLast) {

View File

@@ -81,7 +81,7 @@ export class ElasticMetricAggCtrl {
$scope.agg.meta,
(memo, val, key) => {
if (val) {
const def = _.find($scope.extendedStats, { value: key });
const def: any = _.find($scope.extendedStats, { value: key });
memo.push(def.text);
}
return memo;

View File

@@ -66,7 +66,7 @@ export class ElasticQueryCtrl extends QueryCtrl {
text += 'Metrics: ';
_.each(metricAggs, (metric, index) => {
const aggDef = _.find(metricAggTypes, { value: metric.type });
const aggDef: any = _.find(metricAggTypes, { value: metric.type });
text += aggDef.text + '(';
if (aggDef.requiresField) {
text += metric.field;
@@ -77,12 +77,12 @@ export class ElasticQueryCtrl extends QueryCtrl {
text += '), ';
});
_.each(bucketAggs, (bucketAgg, index) => {
_.each(bucketAggs, (bucketAgg: any, index: number) => {
if (index === 0) {
text += ' Group by: ';
}
const aggDef = _.find(bucketAggTypes, { value: bucketAgg.type });
const aggDef: any = _.find(bucketAggTypes, { value: bucketAgg.type });
text += aggDef.text + '(';
if (aggDef.requiresField) {
text += bucketAgg.field;

View File

@@ -224,12 +224,12 @@ export function getOrderByOptions(target) {
}
export function describeOrder(order) {
const def = _.find(orderOptions, { value: order });
const def: any = _.find(orderOptions, { value: order });
return def.text;
}
export function describeMetric(metric) {
const def = _.find(metricAggTypes, { value: metric.type });
const def: any = _.find(metricAggTypes, { value: metric.type });
if (!def.requiresField && !isPipelineAgg(metric.type)) {
return def.text;
}
@@ -237,11 +237,11 @@ export function describeMetric(metric) {
}
export function describeOrderBy(orderBy, target) {
const def = _.find(orderByOptions, { value: orderBy });
const def: any = _.find(orderByOptions, { value: orderBy });
if (def) {
return def.text;
}
const metric = _.find(target.metrics, { id: orderBy });
const metric: any = _.find(target.metrics, { id: orderBy });
if (metric) {
return describeMetric(metric);
} else {

View File

@@ -144,7 +144,7 @@ export default class ResponseParser {
}
static findOrCreateBucket(data, target) {
let dataTarget = _.find(data, ['target', target]);
let dataTarget: any = _.find(data, ['target', target]);
if (!dataTarget) {
dataTarget = { target: target, datapoints: [] };
data.push(dataTarget);

View File

@@ -254,7 +254,7 @@ export default class ResponseParser {
}
static findOrCreateBucket(data, target): DataTarget {
let dataTarget = _.find(data, ['target', target]);
let dataTarget: any = _.find(data, ['target', target]);
if (!dataTarget) {
dataTarget = { target: target, datapoints: [], refId: '', query: '' };
data.push(dataTarget);

View File

@@ -136,7 +136,7 @@ export default class ResponseParser {
}
static parseMetadata(result: any, metricName: string) {
const metricData = _.find(result.data.value, o => {
const metricData: any = _.find(result.data.value, o => {
return _.get(o, 'name.value') === metricName;
});

View File

@@ -245,7 +245,7 @@ class QueryField extends React.Component<any, any> {
// Get the currently selected suggestion
const flattenedSuggestions = flattenSuggestions(suggestions);
const suggestion = _.find(
const suggestion: any = _.find(
flattenedSuggestions,
suggestion => suggestion.display === item || suggestion.text === item
);

View File

@@ -35,7 +35,7 @@ export function graphiteAddFunc($compile) {
minLength: 1,
items: 10,
updater: value => {
let funcDef = ctrl.datasource.getFuncDef(value);
let funcDef: any = ctrl.datasource.getFuncDef(value);
if (!funcDef) {
// try find close match
value = value.toLowerCase();

View File

@@ -77,7 +77,7 @@ export function graphiteFuncEditor($compile, templateSrv, popoverSrv) {
if (index < func.def.params.length) {
return func.def.params[index];
}
if (_.last(func.def.params).multiple) {
if ((_.last(func.def.params) as any).multiple) {
return _.assign({}, _.last(func.def.params), { optional: true });
}
return {};
@@ -170,14 +170,14 @@ export function graphiteFuncEditor($compile, templateSrv, popoverSrv) {
function addElementsAndCompile() {
$funcLink.appendTo(elem);
const defParams = _.clone(func.def.params);
const lastParam = _.last(func.def.params);
const defParams: any = _.clone(func.def.params);
const lastParam: any = _.last(func.def.params);
while (func.params.length >= defParams.length && lastParam && lastParam.multiple) {
defParams.push(_.assign({}, lastParam, { optional: true }));
}
_.each(defParams, (param, index) => {
_.each(defParams, (param: any, index: number) => {
if (param.optional && func.params.length < index) {
return false;
}

View File

@@ -61,7 +61,7 @@ export default class GraphiteQuery {
}
checkForSeriesByTag() {
const seriesByTagFunc = _.find(this.functions, func => func.def.name === 'seriesByTag');
const seriesByTagFunc: any = _.find(this.functions, func => func.def.name === 'seriesByTag');
if (seriesByTagFunc) {
this.seriesByTagUsed = true;
seriesByTagFunc.hidden = true;
@@ -135,7 +135,7 @@ export default class GraphiteQuery {
}
moveAliasFuncLast() {
const aliasFunc = _.find(this.functions, func => {
const aliasFunc: any = _.find(this.functions, func => {
return func.def.name.startsWith('alias');
});
@@ -158,6 +158,7 @@ export default class GraphiteQuery {
moveFunction(func, offset) {
const index = this.functions.indexOf(func);
// @ts-ignore
_.move(this.functions, index, index + offset);
}

View File

@@ -182,7 +182,7 @@ export class GraphiteQueryCtrl extends QueryCtrl {
});
}
removeTaggedEntry(altSegments) {
removeTaggedEntry(altSegments: any[]) {
altSegments = _.remove(altSegments, s => s.value === '_tagged');
}

View File

@@ -151,7 +151,7 @@ export default class InfluxSeries {
return table;
}
_.each(this.series, (series, seriesIndex) => {
_.each(this.series, (series: any, seriesIndex: number) => {
if (seriesIndex === 0) {
j = 0;
// Check that the first column is indeed 'time'

View File

@@ -44,7 +44,9 @@ export default class ResponseParser {
});
});
// @ts-ignore problems with typings for this _.map only accepts [] but this needs to be object
return _.map(res, value => {
// @ts-ignore
return { text: value.toString() };
});
}

View File

@@ -1,5 +1,4 @@
// Libraries
// @ts-ignore
import _ from 'lodash';
import moment from 'moment';

View File

@@ -9,7 +9,7 @@ class MixedDatasource implements DataSourceApi<DataQuery> {
query(options: DataQueryOptions<DataQuery>) {
const sets = _.groupBy(options.targets, 'datasource');
const promises = _.map(sets, (targets: DataQuery[]) => {
const promises: any = _.map(sets, (targets: DataQuery[]) => {
const dsName = targets[0].datasource;
if (dsName === '-- Mixed --') {
return Promise.resolve([]);

View File

@@ -59,7 +59,7 @@ export class MssqlQueryCtrl extends QueryCtrl {
this.lastQueryMeta = null;
this.lastQueryError = null;
const anySeriesFromQuery = _.find(dataList, { refId: this.target.refId });
const anySeriesFromQuery: any = _.find(dataList, { refId: this.target.refId });
if (anySeriesFromQuery) {
this.lastQueryMeta = anySeriesFromQuery.meta;
}

View File

@@ -149,17 +149,17 @@ export default class MysqlQuery {
buildValueColumn(column) {
let query = '';
const columnName = _.find(column, (g: any) => g.type === 'column');
const columnName: any = _.find(column, (g: any) => g.type === 'column');
query = columnName.params[0];
const aggregate = _.find(column, (g: any) => g.type === 'aggregate');
const aggregate: any = _.find(column, (g: any) => g.type === 'aggregate');
if (aggregate) {
const func = aggregate.params[0];
query = func + '(' + query + ')';
}
const alias = _.find(column, (g: any) => g.type === 'alias');
const alias: any = _.find(column, (g: any) => g.type === 'alias');
if (alias) {
query += ' AS ' + this.quoteIdentifier(alias.params[0]);
}

View File

@@ -253,7 +253,7 @@ export class MysqlQueryCtrl extends QueryCtrl {
this.lastQueryMeta = null;
this.lastQueryError = null;
const anySeriesFromQuery = _.find(dataList, { refId: this.target.refId });
const anySeriesFromQuery: any = _.find(dataList, { refId: this.target.refId });
if (anySeriesFromQuery) {
this.lastQueryMeta = anySeriesFromQuery.meta;
}

View File

@@ -72,7 +72,7 @@ export default class OpenTsDatasource {
return this.performTimeSeriesQuery(queries, start, end).then(response => {
const metricToTargetMapping = this.mapMetricsToTargets(response.data, options, this.tsdbVersion);
const result = _.map(response.data, (metricData, index) => {
const result = _.map(response.data, (metricData: any, index: number) => {
index = metricToTargetMapping[index];
if (index === -1) {
index = 0;
@@ -347,7 +347,7 @@ export default class OpenTsDatasource {
// TSDB returns datapoints has a hash of ts => value.
// Can't use _.pairs(invert()) because it stringifies keys/values
_.each(md.dps, (v, k) => {
_.each(md.dps, (v: any, k: number) => {
if (tsdbResolution === 2) {
dps.push([v, k * 1]);
} else {
@@ -466,7 +466,7 @@ export default class OpenTsDatasource {
if (tsdbVersion === 3) {
return metricData.query.index;
} else {
return _.findIndex(options.targets, target => {
return _.findIndex(options.targets as any[], target => {
if (target.filters && target.filters.length > 0) {
return target.metric === metricData.metric;
} else {

View File

@@ -149,11 +149,11 @@ export default class PostgresQuery {
buildValueColumn(column) {
let query = '';
const columnName = _.find(column, (g: any) => g.type === 'column');
const columnName: any = _.find(column, (g: any) => g.type === 'column');
query = columnName.params[0];
const aggregate = _.find(column, (g: any) => g.type === 'aggregate' || g.type === 'percentile');
const windows = _.find(column, (g: any) => g.type === 'window' || g.type === 'moving_window');
const aggregate: any = _.find(column, (g: any) => g.type === 'aggregate' || g.type === 'percentile');
const windows: any = _.find(column, (g: any) => g.type === 'window' || g.type === 'moving_window');
if (aggregate) {
const func = aggregate.params[0];
@@ -218,7 +218,7 @@ export default class PostgresQuery {
}
}
const alias = _.find(column, (g: any) => g.type === 'alias');
const alias: any = _.find(column, (g: any) => g.type === 'alias');
if (alias) {
query += ' AS ' + this.quoteIdentifier(alias.params[0]);
}

View File

@@ -284,7 +284,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
this.lastQueryMeta = null;
this.lastQueryError = null;
const anySeriesFromQuery = _.find(dataList, { refId: this.target.refId });
const anySeriesFromQuery: any = _.find(dataList, { refId: this.target.refId });
if (anySeriesFromQuery) {
this.lastQueryMeta = anySeriesFromQuery.meta;
}

View File

@@ -1,4 +1,3 @@
// @ts-ignore
import _ from 'lodash';
import React from 'react';
// @ts-ignore

View File

@@ -1,4 +1,3 @@
// @ts-ignore
import _ from 'lodash';
import moment from 'moment';

View File

@@ -23,7 +23,7 @@ describe('PrometheusDatasource', () => {
directUrl: 'direct',
user: 'test',
password: 'mupp',
jsonData: {},
jsonData: {} as any,
};
ctx.backendSrvMock = {};

View File

@@ -42,7 +42,7 @@ export default class StackdriverMetricFindQuery {
async handleServiceQuery() {
const metricDescriptors = await this.datasource.getMetricTypes(this.datasource.projectName);
const services = extractServicesFromMetricDescriptors(metricDescriptors);
const services: any[] = extractServicesFromMetricDescriptors(metricDescriptors);
return services.map(s => ({
text: s.serviceShortName,
value: s.service,

View File

@@ -34,7 +34,7 @@ export class StackdriverVariableQueryEditor extends PureComponent<VariableQueryP
async componentDidMount() {
const metricDescriptors = await this.props.datasource.getMetricTypes(this.props.datasource.projectName);
const services = extractServicesFromMetricDescriptors(metricDescriptors).map(m => ({
const services = extractServicesFromMetricDescriptors(metricDescriptors).map((m: any) => ({
value: m.service,
name: m.serviceShortName,
}));

View File

@@ -35,7 +35,7 @@ export class QueryEditor extends PureComponent<Props> {
// const scenarioList = await this.backendSrv.get('/api/tsdb/testdata/scenarios');
const scenarioList = await datasource.getScenarios();
const current = _.find(scenarioList, { id: query.scenarioId });
const current: any = _.find(scenarioList, { id: query.scenarioId });
this.setState({ scenarioList: scenarioList, current: current });
}

View File

@@ -3,6 +3,8 @@ import { DataQuery } from '@grafana/ui/src/types';
export interface TestDataQuery extends DataQuery {
alias?: string;
scenarioId: string;
stringInput: string;
points: any;
}
export interface Scenario {

View File

@@ -88,7 +88,7 @@ export class GraphLegend extends PureComponent<GraphLegendProps, LegendState> {
}
sortLegend() {
let seriesList = [...this.props.seriesList] || [];
let seriesList: TimeSeries[] = [...this.props.seriesList] || [];
if (this.props.sort) {
seriesList = _.sortBy(seriesList, series => {
let sort = series.stats[this.props.sort];
@@ -96,7 +96,7 @@ export class GraphLegend extends PureComponent<GraphLegendProps, LegendState> {
sort = -Infinity;
}
return sort;
});
}) as TimeSeries[];
if (this.props.sortDesc) {
seriesList = seriesList.reverse();
}

View File

@@ -156,7 +156,7 @@ export class DataProcessor {
}
const validOptions = this.getXAxisValueOptions({});
const found = _.find(validOptions, { value: this.panel.xaxis.values[0] });
const found: any = _.find(validOptions, { value: this.panel.xaxis.values[0] });
if (!found) {
this.panel.xaxis.values = ['total'];
}

View File

@@ -574,6 +574,7 @@ class GraphElement {
return [tickIndex + 1, point[1]];
});
});
// @ts-ignore, potential bug? is this _.flattenDeep?
ticks = _.flatten(ticks, true);
options.xaxis = {

View File

@@ -262,7 +262,7 @@ class GraphCtrl extends MetricsPanelCtrl {
};
onToggleAxis = info => {
let override = _.find(this.panel.seriesOverrides, { alias: info.alias });
let override: any = _.find(this.panel.seriesOverrides, { alias: info.alias });
if (!override) {
override = { alias: info.alias };
this.panel.seriesOverrides.push(override);

View File

@@ -36,7 +36,7 @@ coreModule.directive('colorLegend', () => {
const legendWidth = Math.floor(legendElem.outerWidth());
if (panel.color.mode === 'spectrum') {
const colorScheme = _.find(ctrl.colorSchemes, {
const colorScheme: any = _.find(ctrl.colorSchemes, {
value: panel.color.colorScheme,
});
const colorScale = getColorScale(colorScheme, contextSrv.user.lightTheme, legendWidth);
@@ -76,7 +76,7 @@ coreModule.directive('heatmapLegend', () => {
const minValue = cardStats.min;
if (panel.color.mode === 'spectrum') {
const colorScheme = _.find(ctrl.colorSchemes, {
const colorScheme: any = _.find(ctrl.colorSchemes, {
value: panel.color.colorScheme,
});
drawColorLegend(elem, colorScheme, rangeFrom, rangeTo, maxValue, minValue);

View File

@@ -253,7 +253,7 @@ function convertToHeatMap(seriesList, yBucketSize, xBucketSize, logBase = 1) {
// |* | --/ |1|,
// |____| |0|
//
_.forEach(heatmap, xBucket => {
_.forEach(heatmap, (xBucket: any) => {
if (logBase !== 1) {
xBucket.buckets = convertToLogScaleValueBuckets(xBucket, yBucketSize, logBase);
} else {

View File

@@ -81,7 +81,7 @@ export class HeatmapTooltip {
let boundBottom, boundTop, valuesNumber;
const xData = data.buckets[xBucketIndex];
// Search in special 'zero' bucket also
const yData = _.find(xData.buckets, (bucket, bucketIndex) => {
const yData: any = _.find(xData.buckets, (bucket, bucketIndex) => {
return bucket.bounds.bottom === yBucketIndex || bucketIndex === yBucketIndex.toString();
});
@@ -161,7 +161,7 @@ export class HeatmapTooltip {
getXBucketIndex(x, data) {
// First try to find X bucket by checking x pos is in the
// [bucket.x, bucket.x + xBucketSize] interval
const xBucket = _.find(data.buckets, bucket => {
const xBucket: any = _.find(data.buckets, bucket => {
return x > bucket.x && x - bucket.x <= data.xBucketSize;
});
return xBucket ? xBucket.x : getValueBucketBound(x, data.xBucketSize, 1);

View File

@@ -529,7 +529,7 @@ export class HeatmapRenderer {
const minValueAuto = Math.min(cardStats.min, 0);
const maxValue = _.isNil(this.panel.color.max) ? maxValueAuto : this.panel.color.max;
const minValue = _.isNil(this.panel.color.min) ? minValueAuto : this.panel.color.min;
const colorScheme = _.find(this.ctrl.colorSchemes, {
const colorScheme: any = _.find(this.ctrl.colorSchemes, {
value: this.panel.color.colorScheme,
});
this.colorScale = getColorScale(colorScheme, contextSrv.user.lightTheme, maxValue, minValue);

View File

@@ -52,7 +52,7 @@ export class TablePanelEditorCtrl {
addColumn() {
const columns = transformers[this.panel.transform].getColumns(this.panelCtrl.dataRaw);
const column = _.find(columns, { text: this.addColumnSegment.value });
const column: any = _.find(columns, { text: this.addColumnSegment.value });
if (column) {
this.panel.columns.push(column);

View File

@@ -101,7 +101,7 @@ export class TableRenderer {
}
// if is an epoch (numeric string and len > 12)
if (_.isString(v) && !isNaN(v) && v.length > 12) {
if (_.isString(v) && !isNaN(v as any) && v.length > 12) {
v = parseInt(v, 10);
}

View File

@@ -154,7 +154,7 @@ transformers['table'] = {
return columns;
},
transform: (data, panel, model) => {
transform: (data: any[], panel, model) => {
if (!data || data.length === 0) {
return;
}