mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Improve typings (#88282)
* remove some type assertions * some more type assertion fixes * nicer * shortcircuit while loop when hitting something that isn't an HTMLElement
This commit is contained in:
@@ -149,7 +149,7 @@ function convertGraphSeriesToDataFrame(graphSeries: GraphSeriesXY): DataFrame {
|
||||
}
|
||||
|
||||
function convertJSONDocumentDataToDataFrame(timeSeries: TimeSeries): DataFrame {
|
||||
const fields = [
|
||||
const fields: Field[] = [
|
||||
{
|
||||
name: timeSeries.target,
|
||||
type: FieldType.other,
|
||||
@@ -158,7 +158,7 @@ function convertJSONDocumentDataToDataFrame(timeSeries: TimeSeries): DataFrame {
|
||||
unit: timeSeries.unit,
|
||||
filterable: (timeSeries as any).filterable,
|
||||
},
|
||||
values: [] as TimeSeriesValue[][],
|
||||
values: [],
|
||||
},
|
||||
];
|
||||
|
||||
@@ -315,11 +315,11 @@ export function toDataFrame(data: any): DataFrame {
|
||||
if ('fields' in data) {
|
||||
// DataFrameDTO does not have length
|
||||
if ('length' in data && data.fields[0]?.values?.get) {
|
||||
return data as DataFrame;
|
||||
return data;
|
||||
}
|
||||
|
||||
// This will convert the array values into Vectors
|
||||
return createDataFrame(data as DataFrameDTO);
|
||||
return createDataFrame(data);
|
||||
}
|
||||
|
||||
// Handle legacy docs/json type
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/* eslint-disable id-blacklist, no-restricted-imports, @typescript-eslint/ban-types */
|
||||
import moment, { MomentInput, Moment } from 'moment-timezone';
|
||||
import moment, { Moment } from 'moment-timezone';
|
||||
|
||||
import { TimeZone } from '../types';
|
||||
|
||||
import { DateTimeOptions, getTimeZone } from './common';
|
||||
import { systemDateFormats } from './formats';
|
||||
import { DateTimeInput } from './moment_wrapper';
|
||||
import { DateTimeInput, toUtc, dateTimeAsMoment } from './moment_wrapper';
|
||||
|
||||
/**
|
||||
* The type describing the options that can be passed to the {@link dateTimeFormat}
|
||||
@@ -93,17 +93,17 @@ const getFormat = <T extends DateTimeOptionsWithFormat>(options?: T): string =>
|
||||
};
|
||||
|
||||
const toTz = (dateInUtc: DateTimeInput, timeZone: TimeZone): Moment => {
|
||||
const date = dateInUtc as MomentInput;
|
||||
const date = dateInUtc;
|
||||
const zone = moment.tz.zone(timeZone);
|
||||
|
||||
if (zone && zone.name) {
|
||||
return moment.utc(date).tz(zone.name);
|
||||
return dateTimeAsMoment(toUtc(date)).tz(zone.name);
|
||||
}
|
||||
|
||||
switch (timeZone) {
|
||||
case 'utc':
|
||||
return moment.utc(date);
|
||||
return dateTimeAsMoment(toUtc(date));
|
||||
default:
|
||||
return moment.utc(date).local();
|
||||
return dateTimeAsMoment(toUtc(date)).local();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/* eslint-disable id-blacklist, no-restricted-imports, @typescript-eslint/ban-types */
|
||||
import { lowerCase } from 'lodash';
|
||||
import moment, { MomentInput } from 'moment-timezone';
|
||||
import moment from 'moment-timezone';
|
||||
|
||||
import { DateTimeOptions, getTimeZone } from './common';
|
||||
import { parse, isValid } from './datemath';
|
||||
import { systemDateFormats } from './formats';
|
||||
import { DateTimeInput, DateTime, isDateTime } from './moment_wrapper';
|
||||
import { DateTimeInput, DateTime, isDateTime, dateTime, toUtc, dateTimeForTimeZone } from './moment_wrapper';
|
||||
|
||||
/**
|
||||
* The type that describes options that can be passed when parsing a date and time value.
|
||||
@@ -55,11 +55,11 @@ export const dateTimeParse: DateTimeParser<DateTimeOptionsWhenParsing> = (value,
|
||||
const parseString = (value: string, options?: DateTimeOptionsWhenParsing): DateTime => {
|
||||
if (value.indexOf('now') !== -1) {
|
||||
if (!isValid(value)) {
|
||||
return moment() as DateTime;
|
||||
return dateTime();
|
||||
}
|
||||
|
||||
const parsed = parse(value, options?.roundUp, options?.timeZone, options?.fiscalYearStartMonth);
|
||||
return parsed || (moment() as DateTime);
|
||||
return parsed || dateTime();
|
||||
}
|
||||
|
||||
const timeZone = getTimeZone(options);
|
||||
@@ -67,30 +67,30 @@ const parseString = (value: string, options?: DateTimeOptionsWhenParsing): DateT
|
||||
const format = options?.format ?? systemDateFormats.fullDate;
|
||||
|
||||
if (zone && zone.name) {
|
||||
return moment.tz(value, format, zone.name) as DateTime;
|
||||
return dateTimeForTimeZone(zone.name, value, format);
|
||||
}
|
||||
|
||||
switch (lowerCase(timeZone)) {
|
||||
case 'utc':
|
||||
return moment.utc(value, format) as DateTime;
|
||||
return toUtc(value, format);
|
||||
default:
|
||||
return moment(value, format) as DateTime;
|
||||
return dateTime(value, format);
|
||||
}
|
||||
};
|
||||
|
||||
const parseOthers = (value: DateTimeInput, options?: DateTimeOptionsWhenParsing): DateTime => {
|
||||
const date = value as MomentInput;
|
||||
const date = value;
|
||||
const timeZone = getTimeZone(options);
|
||||
const zone = moment.tz.zone(timeZone);
|
||||
|
||||
if (zone && zone.name) {
|
||||
return moment.tz(date, zone.name) as DateTime;
|
||||
return dateTimeForTimeZone(zone.name, date);
|
||||
}
|
||||
|
||||
switch (lowerCase(timeZone)) {
|
||||
case 'utc':
|
||||
return moment.utc(date) as DateTime;
|
||||
return toUtc(date);
|
||||
default:
|
||||
return moment(date) as DateTime;
|
||||
return dateTime(date);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -57,8 +57,8 @@ export const dataLinksOverrideProcessor = (
|
||||
value: any,
|
||||
_context: FieldOverrideContext,
|
||||
_settings?: DataLinksFieldConfigSettings
|
||||
) => {
|
||||
return value as DataLink[];
|
||||
): DataLink[] => {
|
||||
return value;
|
||||
};
|
||||
|
||||
export interface ValueMappingFieldConfigSettings {}
|
||||
@@ -67,8 +67,8 @@ export const valueMappingsOverrideProcessor = (
|
||||
value: any,
|
||||
_context: FieldOverrideContext,
|
||||
_settings?: ValueMappingFieldConfigSettings
|
||||
) => {
|
||||
return value as ValueMapping[]; // !!!! likely not !!!!
|
||||
): ValueMapping[] => {
|
||||
return value; // !!!! likely not !!!!
|
||||
};
|
||||
|
||||
export interface SelectFieldConfigSettings<T> {
|
||||
@@ -121,8 +121,8 @@ export const thresholdsOverrideProcessor = (
|
||||
value: any,
|
||||
_context: FieldOverrideContext,
|
||||
_settings?: ThresholdsFieldConfigSettings
|
||||
) => {
|
||||
return value as ThresholdsConfig; // !!!! likely not !!!!
|
||||
): ThresholdsConfig => {
|
||||
return value; // !!!! likely not !!!!
|
||||
};
|
||||
|
||||
export interface UnitFieldConfigSettings {
|
||||
|
||||
@@ -263,7 +263,7 @@ export class PanelPlugin<
|
||||
* @internal
|
||||
*/
|
||||
getPanelOptionsSupplier(): PanelOptionsSupplier<TOptions> {
|
||||
return this.optionsSupplier ?? ((() => {}) as PanelOptionsSupplier<TOptions>);
|
||||
return this.optionsSupplier ?? (() => {});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import { DataFrame } from '../../types';
|
||||
import { BootData, DataFrame } from '../../types';
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
grafanaBootData?: BootData;
|
||||
}
|
||||
}
|
||||
|
||||
export const transformationsVariableSupport = () => {
|
||||
return (window as any)?.grafanaBootData?.settings?.featureToggles?.transformationsVariableSupport;
|
||||
return window?.grafanaBootData?.settings?.featureToggles?.transformationsVariableSupport;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user