mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: fix some typings in @grafana/data (#60009)
fix some typings in @grafana/data
This commit is contained in:
parent
2e3c4a7626
commit
9bbc2c4cbb
@ -51,21 +51,18 @@ exports[`better eslint`] = {
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "3"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "4"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "5"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "6"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "7"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "8"]
|
||||
[0, 0, 0, "Do not use any type assertions.", "5"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "6"]
|
||||
],
|
||||
"packages/grafana-data/src/dataframe/CircularDataFrame.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
||||
],
|
||||
"packages/grafana-data/src/dataframe/DataFrameJSON.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "1"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "2"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "3"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "4"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "5"]
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "4"]
|
||||
],
|
||||
"packages/grafana-data/src/dataframe/DataFrameView.test.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||
@ -91,23 +88,18 @@ exports[`better eslint`] = {
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "3"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "4"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "5"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "5"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "6"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "7"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "7"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "8"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "9"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "9"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "10"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "11"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "11"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "12"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "13"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "13"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "14"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "15"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "16"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "17"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "18"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "19"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "20"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "21"]
|
||||
[0, 0, 0, "Do not use any type assertions.", "16"]
|
||||
],
|
||||
"packages/grafana-data/src/dataframe/dimensions.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
||||
@ -119,10 +111,7 @@ exports[`better eslint`] = {
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "3"]
|
||||
],
|
||||
"packages/grafana-data/src/dataframe/frameComparisons.ts:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "2"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "3"]
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"]
|
||||
],
|
||||
"packages/grafana-data/src/dataframe/processDataFrame.test.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
||||
@ -142,21 +131,16 @@ exports[`better eslint`] = {
|
||||
[0, 0, 0, "Do not use any type assertions.", "11"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "12"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "13"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "14"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "15"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "14"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "15"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "16"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "17"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "17"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "18"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "19"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "20"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "21"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "22"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "23"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "24"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "25"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "26"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "27"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "28"]
|
||||
[0, 0, 0, "Do not use any type assertions.", "21"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "22"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "23"]
|
||||
],
|
||||
"packages/grafana-data/src/datetime/datemath.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||
@ -196,13 +180,9 @@ exports[`better eslint`] = {
|
||||
],
|
||||
"packages/grafana-data/src/datetime/rangeutil.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "3"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "4"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "5"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "6"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "7"]
|
||||
[0, 0, 0, "Do not use any type assertions.", "1"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "2"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "3"]
|
||||
],
|
||||
"packages/grafana-data/src/datetime/timezones.ts:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"],
|
||||
@ -233,37 +213,17 @@ exports[`better eslint`] = {
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "4"]
|
||||
],
|
||||
"packages/grafana-data/src/field/displayProcessor.test.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "2"]
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
||||
],
|
||||
"packages/grafana-data/src/field/displayProcessor.ts:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "3"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "4"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "5"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "6"]
|
||||
],
|
||||
"packages/grafana-data/src/field/fieldColor.test.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
||||
],
|
||||
"packages/grafana-data/src/field/fieldComparers.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "3"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "4"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "5"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "6"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "7"]
|
||||
[0, 0, 0, "Do not use any type assertions.", "1"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "2"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "3"]
|
||||
],
|
||||
"packages/grafana-data/src/field/fieldDisplay.test.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "3"]
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
|
||||
],
|
||||
"packages/grafana-data/src/field/fieldOverrides.test.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||
@ -309,10 +269,6 @@ exports[`better eslint`] = {
|
||||
[0, 0, 0, "Do not use any type assertions.", "4"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "5"]
|
||||
],
|
||||
"packages/grafana-data/src/field/getFieldDisplayValuesProxy.ts:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"]
|
||||
],
|
||||
"packages/grafana-data/src/field/overrides/processors.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
|
||||
@ -348,10 +304,7 @@ exports[`better eslint`] = {
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "7"]
|
||||
],
|
||||
"packages/grafana-data/src/field/templateProxies.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "1"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "3"]
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
||||
],
|
||||
"packages/grafana-data/src/geo/layer.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||
@ -374,16 +327,8 @@ exports[`better eslint`] = {
|
||||
],
|
||||
"packages/grafana-data/src/panel/registryFactories.ts:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "2"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "3"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "4"]
|
||||
],
|
||||
"packages/grafana-data/src/text/sanitize.ts:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"]
|
||||
],
|
||||
"packages/grafana-data/src/text/string.ts:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"]
|
||||
[0, 0, 0, "Do not use any type assertions.", "1"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "2"]
|
||||
],
|
||||
"packages/grafana-data/src/text/text.ts:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"]
|
||||
@ -391,22 +336,13 @@ exports[`better eslint`] = {
|
||||
"packages/grafana-data/src/themes/colorManipulator.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "3"]
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "2"]
|
||||
],
|
||||
"packages/grafana-data/src/themes/createColors.ts:5381": [
|
||||
[0, 0, 0, "Do not use any type assertions.", "0"]
|
||||
],
|
||||
"packages/grafana-data/src/transformations/fieldReducer.test.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
||||
],
|
||||
"packages/grafana-data/src/transformations/fieldReducer.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "1"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "2"],
|
||||
[0, 0, 0, "Do not use any type assertions.", "3"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "4"],
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "5"]
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
||||
],
|
||||
"packages/grafana-data/src/transformations/matchers/predicates.ts:5381": [
|
||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||
|
@ -6,7 +6,7 @@ import { vectorToArray } from '../vector/vectorToArray';
|
||||
import { guessFieldTypeFromNameAndValue, toDataFrameDTO } from './processDataFrame';
|
||||
|
||||
/** @public */
|
||||
export type ValueConverter<T = any> = (val: any) => T;
|
||||
export type ValueConverter<T = any> = (val: unknown) => T;
|
||||
|
||||
const NOOP: ValueConverter = (v) => v;
|
||||
|
||||
@ -67,7 +67,7 @@ export class ArrayDataFrame<T = any> extends FunctionalVector<T> implements Data
|
||||
/**
|
||||
* Add a field for each property in the object. This will guess the type
|
||||
*/
|
||||
setFieldsFromObject(obj: any) {
|
||||
setFieldsFromObject(obj: Record<string, unknown>) {
|
||||
this.fields = Object.keys(obj).map((name) => {
|
||||
return {
|
||||
name,
|
||||
|
@ -111,7 +111,7 @@ export interface FieldValueEntityLookup {
|
||||
NegInf?: number[];
|
||||
}
|
||||
|
||||
const ENTITY_MAP: Record<keyof FieldValueEntityLookup, any> = {
|
||||
const ENTITY_MAP: Record<keyof FieldValueEntityLookup, number | undefined> = {
|
||||
Inf: Infinity,
|
||||
NegInf: -Infinity,
|
||||
Undef: undefined,
|
||||
|
@ -13,7 +13,7 @@ export type MutableField<T = any> = Field<T, MutableVector<T>>;
|
||||
|
||||
type MutableVectorCreator = (buffer?: any[]) => MutableVector;
|
||||
|
||||
export const MISSING_VALUE: any = undefined; // Treated as connected in new graph panel
|
||||
export const MISSING_VALUE = undefined; // Treated as connected in new graph panel
|
||||
|
||||
export class MutableDataFrame<T = any> extends FunctionalVector<T> implements DataFrame, MutableVector<T> {
|
||||
name?: string;
|
||||
@ -67,7 +67,7 @@ export class MutableDataFrame<T = any> extends FunctionalVector<T> implements Da
|
||||
return this.first.length;
|
||||
}
|
||||
|
||||
addFieldFor(value: any, name?: string): MutableField {
|
||||
addFieldFor(value: unknown, name?: string): MutableField {
|
||||
return this.addField({
|
||||
name: name || '', // Will be filled in
|
||||
type: guessFieldTypeFromValue(value),
|
||||
@ -79,7 +79,7 @@ export class MutableDataFrame<T = any> extends FunctionalVector<T> implements Da
|
||||
|
||||
if (f.values) {
|
||||
if (Array.isArray(f.values)) {
|
||||
buffer = f.values as any[];
|
||||
buffer = f.values;
|
||||
} else {
|
||||
buffer = (f.values as Vector).toArray();
|
||||
}
|
||||
@ -181,7 +181,7 @@ export class MutableDataFrame<T = any> extends FunctionalVector<T> implements Da
|
||||
/**
|
||||
* This will add each value to the corresponding column
|
||||
*/
|
||||
appendRow(row: any[]) {
|
||||
appendRow(row: unknown[]) {
|
||||
// Add any extra columns
|
||||
for (let i = this.fields.length; i < row.length; i++) {
|
||||
this.addField({
|
||||
@ -233,7 +233,7 @@ export class MutableDataFrame<T = any> extends FunctionalVector<T> implements Da
|
||||
|
||||
set(index: number, value: T) {
|
||||
if (index > this.length) {
|
||||
throw new Error('Unable ot set value beyond current length');
|
||||
throw new Error('Unable to set value beyond current length');
|
||||
}
|
||||
|
||||
const obj = (value as any) || {};
|
||||
|
@ -43,11 +43,14 @@ export function compareDataFrameStructures(a: DataFrame, b: DataFrame, skipConfi
|
||||
return false;
|
||||
}
|
||||
|
||||
const cfgA = fA.config as any;
|
||||
const cfgB = fB.config as any;
|
||||
const cfgA = fA.config;
|
||||
const cfgB = fB.config;
|
||||
|
||||
let aKeys = Object.keys(cfgA);
|
||||
let bKeys = Object.keys(cfgB);
|
||||
// need to type assert on the object keys here
|
||||
// see e.g. https://github.com/Microsoft/TypeScript/issues/12870
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
let aKeys = Object.keys(cfgA) as Array<keyof typeof cfgA>;
|
||||
let bKeys = Object.keys(cfgB) as Array<keyof typeof cfgB>;
|
||||
|
||||
if (aKeys.length !== bKeys.length) {
|
||||
return false;
|
||||
|
@ -180,7 +180,7 @@ const NUMBER = /^\s*(-?(\d*\.?\d+|\d+\.?\d*)(e[-+]?\d+)?|NAN)\s*$/i;
|
||||
/**
|
||||
* Given a name and value, this will pick a reasonable field type
|
||||
*/
|
||||
export function guessFieldTypeFromNameAndValue(name: string, v: any): FieldType {
|
||||
export function guessFieldTypeFromNameAndValue(name: string, v: unknown): FieldType {
|
||||
if (name) {
|
||||
name = name.toLowerCase();
|
||||
if (name === 'date' || name === 'time') {
|
||||
@ -193,7 +193,7 @@ export function guessFieldTypeFromNameAndValue(name: string, v: any): FieldType
|
||||
/**
|
||||
* Check the field type to see what the contents are
|
||||
*/
|
||||
export function getFieldTypeFromValue(v: any): FieldType {
|
||||
export function getFieldTypeFromValue(v: unknown): FieldType {
|
||||
if (v instanceof Date || isDateTime(v)) {
|
||||
return FieldType.time;
|
||||
}
|
||||
@ -218,7 +218,7 @@ export function getFieldTypeFromValue(v: any): FieldType {
|
||||
*
|
||||
* NOTE: this is will try to see if string values can be mapped to other types (like number)
|
||||
*/
|
||||
export function guessFieldTypeFromValue(v: any): FieldType {
|
||||
export function guessFieldTypeFromValue(v: unknown): FieldType {
|
||||
if (v instanceof Date || isDateTime(v)) {
|
||||
return FieldType.time;
|
||||
}
|
||||
@ -299,9 +299,9 @@ export const guessFieldTypes = (series: DataFrame, guessDefined = false): DataFr
|
||||
return series;
|
||||
};
|
||||
|
||||
export const isTableData = (data: any): data is DataFrame => data && data.hasOwnProperty('columns');
|
||||
export const isTableData = (data: unknown): data is DataFrame => Boolean(data && data.hasOwnProperty('columns'));
|
||||
|
||||
export const isDataFrame = (data: any): data is DataFrame => data && data.hasOwnProperty('fields');
|
||||
export const isDataFrame = (data: unknown): data is DataFrame => Boolean(data && data.hasOwnProperty('fields'));
|
||||
|
||||
/**
|
||||
* Inspect any object and return the results as a DataFrame
|
||||
|
@ -86,11 +86,11 @@ const hiddenRangeOptions: TimeOption[] = [
|
||||
{ from: 'now', to: 'now+5y', display: 'Next 5 years' },
|
||||
];
|
||||
|
||||
const rangeIndex: any = {};
|
||||
each(rangeOptions, (frame: any) => {
|
||||
const rangeIndex: Record<string, any> = {};
|
||||
each(rangeOptions, (frame) => {
|
||||
rangeIndex[frame.from + ' to ' + frame.to] = frame;
|
||||
});
|
||||
each(hiddenRangeOptions, (frame: any) => {
|
||||
each(hiddenRangeOptions, (frame) => {
|
||||
rangeIndex[frame.from + ' to ' + frame.to] = frame;
|
||||
});
|
||||
|
||||
@ -100,7 +100,7 @@ each(hiddenRangeOptions, (frame: any) => {
|
||||
// now/d to now
|
||||
// now/d
|
||||
// if no to <expr> then to now is assumed
|
||||
export function describeTextRange(expr: any) {
|
||||
export function describeTextRange(expr: string) {
|
||||
const isLast = expr.indexOf('+') !== 0;
|
||||
if (expr.indexOf('now') === -1) {
|
||||
expr = (isLast ? 'now-' : 'now') + expr;
|
||||
@ -211,7 +211,7 @@ export const convertRawToRange = (raw: RawTimeRange, timeZone?: TimeZone, fiscal
|
||||
|
||||
function isRelativeTime(v: DateTime | string) {
|
||||
if (typeof v === 'string') {
|
||||
return (v as string).indexOf('now') >= 0;
|
||||
return v.indexOf('now') >= 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -21,7 +21,10 @@ function assertSame(input: any, processors: DisplayProcessor[], match: DisplayVa
|
||||
processors.forEach((processor) => {
|
||||
const value = processor(input);
|
||||
for (const key of Object.keys(match)) {
|
||||
expect((value as any)[key]).toEqual((match as any)[key]);
|
||||
// need to type assert on the object keys here
|
||||
// see e.g. https://github.com/Microsoft/TypeScript/issues/12870
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
expect(value[key as keyof typeof match]).toEqual(match[key as keyof typeof match]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ export function getDisplayProcessor(options?: DisplayProcessorOptions): DisplayP
|
||||
const formatFunc = getValueFormat(unit || 'none');
|
||||
const scaleFunc = getScaleCalculator(field, options.theme);
|
||||
|
||||
return (value: any, adjacentDecimals?: DecimalCount) => {
|
||||
return (value: unknown, adjacentDecimals?: DecimalCount) => {
|
||||
const { mappings } = config;
|
||||
const isStringUnit = unit === 'string';
|
||||
|
||||
@ -186,12 +186,12 @@ export function getDisplayProcessor(options?: DisplayProcessorOptions): DisplayP
|
||||
};
|
||||
}
|
||||
|
||||
function toStringProcessor(value: any): DisplayValue {
|
||||
function toStringProcessor(value: unknown): DisplayValue {
|
||||
return { text: toString(value), numeric: anyToNumber(value) };
|
||||
}
|
||||
|
||||
export function getRawDisplayProcessor(): DisplayProcessor {
|
||||
return (value: any) => ({
|
||||
return (value: unknown) => ({
|
||||
text: getFieldTypeFromValue(value) === 'other' ? `${JSON.stringify(value, getCircularReplacer())}` : `${value}`,
|
||||
numeric: null as unknown as number,
|
||||
});
|
||||
|
@ -12,7 +12,7 @@ function getTestField(mode: string): Field {
|
||||
config: {
|
||||
color: {
|
||||
mode: mode,
|
||||
} as any,
|
||||
},
|
||||
},
|
||||
state: {},
|
||||
};
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { isNumber } from 'lodash';
|
||||
|
||||
import { dateTime } from '../datetime';
|
||||
import { dateTime, isDateTime } from '../datetime';
|
||||
import { Field, FieldType } from '../types/dataFrame';
|
||||
import { Vector } from '../types/vector';
|
||||
|
||||
@ -25,7 +25,7 @@ export const fieldIndexComparer = (field: Field, reverse = false): IndexComparer
|
||||
};
|
||||
|
||||
/** @public */
|
||||
export const timeComparer = (a: any, b: any): number => {
|
||||
export const timeComparer = (a: unknown, b: unknown): number => {
|
||||
if (!a || !b) {
|
||||
return falsyComparer(a, b);
|
||||
}
|
||||
@ -34,12 +34,14 @@ export const timeComparer = (a: any, b: any): number => {
|
||||
return numericComparer(a, b);
|
||||
}
|
||||
|
||||
if (dateTime(a).isBefore(b)) {
|
||||
return -1;
|
||||
}
|
||||
if (isDateTime(a) && isDateTime(b)) {
|
||||
if (dateTime(a).isBefore(b)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dateTime(b).isBefore(a)) {
|
||||
return 1;
|
||||
if (dateTime(b).isBefore(a)) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -62,7 +64,7 @@ export const booleanComparer = (a: boolean, b: boolean): number => {
|
||||
return falsyComparer(a, b);
|
||||
};
|
||||
|
||||
const falsyComparer = (a: any, b: any): number => {
|
||||
const falsyComparer = (a: unknown, b: unknown): number => {
|
||||
if (!a && b) {
|
||||
return 1;
|
||||
}
|
||||
@ -74,7 +76,7 @@ const falsyComparer = (a: any, b: any): number => {
|
||||
return 0;
|
||||
};
|
||||
|
||||
const timeIndexComparer = (values: Vector<any>, reverse: boolean): IndexComparer => {
|
||||
const timeIndexComparer = (values: Vector<unknown>, reverse: boolean): IndexComparer => {
|
||||
return (a: number, b: number): number => {
|
||||
const vA = values.get(a);
|
||||
const vB = values.get(b);
|
||||
@ -82,26 +84,26 @@ const timeIndexComparer = (values: Vector<any>, reverse: boolean): IndexComparer
|
||||
};
|
||||
};
|
||||
|
||||
const booleanIndexComparer = (values: Vector<any>, reverse: boolean): IndexComparer => {
|
||||
const booleanIndexComparer = (values: Vector<boolean>, reverse: boolean): IndexComparer => {
|
||||
return (a: number, b: number): number => {
|
||||
const vA: boolean = values.get(a);
|
||||
const vB: boolean = values.get(b);
|
||||
const vA = values.get(a);
|
||||
const vB = values.get(b);
|
||||
return reverse ? booleanComparer(vB, vA) : booleanComparer(vA, vB);
|
||||
};
|
||||
};
|
||||
|
||||
const numericIndexComparer = (values: Vector<any>, reverse: boolean): IndexComparer => {
|
||||
const numericIndexComparer = (values: Vector<number>, reverse: boolean): IndexComparer => {
|
||||
return (a: number, b: number): number => {
|
||||
const vA: number = values.get(a);
|
||||
const vB: number = values.get(b);
|
||||
const vA = values.get(a);
|
||||
const vB = values.get(b);
|
||||
return reverse ? numericComparer(vB, vA) : numericComparer(vA, vB);
|
||||
};
|
||||
};
|
||||
|
||||
const stringIndexComparer = (values: Vector<any>, reverse: boolean): IndexComparer => {
|
||||
const stringIndexComparer = (values: Vector<string>, reverse: boolean): IndexComparer => {
|
||||
return (a: number, b: number): number => {
|
||||
const vA: string = values.get(a);
|
||||
const vB: string = values.get(b);
|
||||
const vA = values.get(a);
|
||||
const vB = values.get(b);
|
||||
return reverse ? stringComparer(vB, vA) : stringComparer(vA, vB);
|
||||
};
|
||||
};
|
||||
|
@ -321,7 +321,7 @@ describe('FieldDisplay', () => {
|
||||
});
|
||||
|
||||
const cache = { numeric: 10, text: 'Value' };
|
||||
options.data![0].fields[1].display = (v: any) => {
|
||||
options.data![0].fields[1].display = () => {
|
||||
return cache;
|
||||
};
|
||||
|
||||
@ -528,5 +528,5 @@ function createDisplayOptions(extend: Partial<GetFieldDisplayValuesOptions> = {}
|
||||
theme: createTheme(),
|
||||
};
|
||||
|
||||
return merge<GetFieldDisplayValuesOptions, any>(options, extend);
|
||||
return merge(options, extend);
|
||||
}
|
||||
|
@ -19,38 +19,41 @@ export function getFieldDisplayValuesProxy(options: {
|
||||
rowIndex: number;
|
||||
timeZone?: TimeZone;
|
||||
}): Record<string, DisplayValue> {
|
||||
return new Proxy({} as Record<string, DisplayValue>, {
|
||||
get: (obj: any, key: string): DisplayValue | undefined => {
|
||||
// 1. Match the name
|
||||
let field = options.frame.fields.find((f) => key === f.name);
|
||||
if (!field) {
|
||||
// 2. Match the array index
|
||||
const k = toNumber(key);
|
||||
field = options.frame.fields[k];
|
||||
}
|
||||
if (!field) {
|
||||
// 3. Match the config displayName
|
||||
field = options.frame.fields.find((f) => key === f.config.displayName);
|
||||
}
|
||||
if (!field) {
|
||||
// 4. Match the name label
|
||||
field = options.frame.fields.find((f) => {
|
||||
if (f.labels) {
|
||||
return key === f.labels.name;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
if (!field) {
|
||||
return undefined;
|
||||
}
|
||||
// TODO: we could supply the field here for the getDisplayProcessor fallback but we would also need theme which
|
||||
// we do not have access to here
|
||||
const displayProcessor = field.display ?? getDisplayProcessor();
|
||||
const raw = field.values.get(options.rowIndex);
|
||||
const disp = displayProcessor(raw);
|
||||
disp.toString = () => formattedValueToString(disp);
|
||||
return disp;
|
||||
},
|
||||
});
|
||||
return new Proxy(
|
||||
{},
|
||||
{
|
||||
get: (obj, key): DisplayValue | undefined => {
|
||||
// 1. Match the name
|
||||
let field = options.frame.fields.find((f) => key === f.name);
|
||||
if (!field) {
|
||||
// 2. Match the array index
|
||||
const k = toNumber(key);
|
||||
field = options.frame.fields[k];
|
||||
}
|
||||
if (!field) {
|
||||
// 3. Match the config displayName
|
||||
field = options.frame.fields.find((f) => key === f.config.displayName);
|
||||
}
|
||||
if (!field) {
|
||||
// 4. Match the name label
|
||||
field = options.frame.fields.find((f) => {
|
||||
if (f.labels) {
|
||||
return key === f.labels.name;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
if (!field) {
|
||||
return undefined;
|
||||
}
|
||||
// TODO: we could supply the field here for the getDisplayProcessor fallback but we would also need theme which
|
||||
// we do not have access to here
|
||||
const displayProcessor = field.display ?? getDisplayProcessor();
|
||||
const raw = field.values.get(options.rowIndex);
|
||||
const disp = displayProcessor(raw);
|
||||
disp.toString = () => formattedValueToString(disp);
|
||||
return disp;
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -9,9 +9,9 @@ import { getFieldDisplayName } from './fieldState';
|
||||
*/
|
||||
export function getTemplateProxyForField(field: Field, frame?: DataFrame, frames?: DataFrame[]): any {
|
||||
return new Proxy(
|
||||
{} as any, // This object shows up in test snapshots
|
||||
{}, // This object shows up in test snapshots
|
||||
{
|
||||
get: (obj: Field, key: string, reciever: any) => {
|
||||
get: (obj, key) => {
|
||||
if (key === 'name') {
|
||||
return field.name;
|
||||
}
|
||||
@ -33,7 +33,7 @@ export function getTemplateProxyForField(field: Field, frame?: DataFrame, frames
|
||||
},
|
||||
};
|
||||
}
|
||||
return undefined; // (field as any)[key]; // any property?
|
||||
return undefined;
|
||||
},
|
||||
}
|
||||
);
|
||||
|
@ -50,8 +50,8 @@ export function createFieldConfigRegistry<TFieldConfigOptions>(
|
||||
}
|
||||
}
|
||||
if (config.standardOptions) {
|
||||
const customDefault: any = config.standardOptions[fieldConfigProp.id as FieldConfigProperty]?.defaultValue;
|
||||
const customSettings: any = config.standardOptions[fieldConfigProp.id as FieldConfigProperty]?.settings;
|
||||
const customDefault = config.standardOptions[fieldConfigProp.id as FieldConfigProperty]?.defaultValue;
|
||||
const customSettings = config.standardOptions[fieldConfigProp.id as FieldConfigProperty]?.settings;
|
||||
if (customDefault) {
|
||||
fieldConfigProp = {
|
||||
...fieldConfigProp,
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { sanitizeUrl as braintreeSanitizeUrl } from '@braintree/sanitize-url';
|
||||
import * as xss from 'xss';
|
||||
|
||||
const XSSWL = Object.keys(xss.whiteList).reduce((acc, element) => {
|
||||
const XSSWL = Object.keys(xss.whiteList).reduce<xss.IWhiteList>((acc, element) => {
|
||||
acc[element] = xss.whiteList[element]?.concat(['class', 'style']);
|
||||
return acc;
|
||||
}, {} as xss.IWhiteList);
|
||||
}, {});
|
||||
|
||||
const sanitizeXSS = new xss.FilterXSS({
|
||||
whiteList: XSSWL,
|
||||
|
@ -73,7 +73,7 @@ export function stringToMs(str: string): number {
|
||||
}
|
||||
|
||||
export function toNumberString(value: number | undefined | null): string {
|
||||
if (value !== null && value !== undefined && Number.isFinite(value as number)) {
|
||||
if (value !== null && value !== undefined && Number.isFinite(value)) {
|
||||
return value.toString();
|
||||
}
|
||||
return '';
|
||||
|
@ -177,7 +177,7 @@ export function decomposeColor(color: string | DecomposeColor): DecomposeColor {
|
||||
*/
|
||||
export function recomposeColor(color: DecomposeColor) {
|
||||
const { type, colorSpace } = color;
|
||||
let values: any = color.values;
|
||||
let values = color.values;
|
||||
|
||||
if (type.indexOf('rgb') !== -1) {
|
||||
// Only convert the first 3 values to int (i.e. not alpha)
|
||||
|
@ -10,7 +10,7 @@ import { fieldReducers, ReducerID, reduceField } from './fieldReducer';
|
||||
/**
|
||||
* Run a reducer and get back the value
|
||||
*/
|
||||
function reduce(field: Field, id: string): any {
|
||||
function reduce(field: Field, id: string) {
|
||||
return reduceField({ field, reducers: [id] })[id];
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Libraries
|
||||
import { isNumber } from 'lodash';
|
||||
|
||||
import { NullValueMode, Field, FieldState, FieldCalcs, FieldType } from '../types/index';
|
||||
import { NullValueMode, Field, FieldCalcs, FieldType } from '../types/index';
|
||||
import { Registry, RegistryItem } from '../utils/Registry';
|
||||
|
||||
export enum ReducerID {
|
||||
@ -72,7 +72,7 @@ export function reduceField(options: ReduceFieldOptions): FieldCalcs {
|
||||
}
|
||||
}
|
||||
if (!field.state) {
|
||||
field.state = {} as FieldState;
|
||||
field.state = {};
|
||||
}
|
||||
|
||||
const queue = fieldReducers.list(reducers);
|
||||
@ -81,7 +81,7 @@ export function reduceField(options: ReduceFieldOptions): FieldCalcs {
|
||||
// This lets the concrete implementations assume at least one row
|
||||
const data = field.values;
|
||||
if (data.length < 1) {
|
||||
const calcs = { ...field.state.calcs } as FieldCalcs;
|
||||
const calcs: FieldCalcs = { ...field.state.calcs };
|
||||
for (const reducer of queue) {
|
||||
calcs[reducer.id] = reducer.emptyInputResult !== null ? reducer.emptyInputResult : null;
|
||||
}
|
||||
@ -266,7 +266,7 @@ export const fieldReducers = new Registry<FieldReducerInfo>(() => [
|
||||
]);
|
||||
|
||||
export function doStandardCalcs(field: Field, ignoreNulls: boolean, nullAsZero: boolean): FieldCalcs {
|
||||
const calcs = {
|
||||
const calcs: FieldCalcs = {
|
||||
sum: 0,
|
||||
max: -Number.MAX_VALUE,
|
||||
min: Number.MAX_VALUE,
|
||||
@ -288,7 +288,7 @@ export function doStandardCalcs(field: Field, ignoreNulls: boolean, nullAsZero:
|
||||
|
||||
// Just used for calculations -- not exposed as a stat
|
||||
previousDeltaUp: true,
|
||||
} as FieldCalcs;
|
||||
};
|
||||
|
||||
const data = field.values;
|
||||
calcs.count = ignoreNulls ? data.length : data.toArray().filter((val) => val != null).length;
|
||||
@ -466,7 +466,7 @@ function calculateChangeCount(field: Field, ignoreNulls: boolean, nullAsZero: bo
|
||||
const data = field.values;
|
||||
let count = 0;
|
||||
let first = true;
|
||||
let last: any = null;
|
||||
let last = null;
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
let currentValue = data.get(i);
|
||||
if (currentValue === null) {
|
||||
@ -489,7 +489,7 @@ function calculateChangeCount(field: Field, ignoreNulls: boolean, nullAsZero: bo
|
||||
|
||||
function calculateDistinctCount(field: Field, ignoreNulls: boolean, nullAsZero: boolean): FieldCalcs {
|
||||
const data = field.values;
|
||||
const distinct = new Set<any>();
|
||||
const distinct = new Set();
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
let currentValue = data.get(i);
|
||||
if (currentValue === null) {
|
||||
|
Loading…
Reference in New Issue
Block a user