Chore: improve some types (#95728)
* fix some typings * fix some more * more type fixes * fix some graphite types * few influx fixes
This commit is contained in:
@@ -550,8 +550,11 @@ export function parseLabelsFromField(str: string): Labels {
|
||||
* @internal // not exported in yet
|
||||
*/
|
||||
export function getLastStreamingDataFramePacket(frame: DataFrame) {
|
||||
const pi = (frame as StreamingDataFrame).packetInfo;
|
||||
return pi?.action ? pi : undefined;
|
||||
if (frame instanceof StreamingDataFrame) {
|
||||
const pi = frame.packetInfo;
|
||||
return pi.action;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// mutable circular push
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { includes, isDate } from 'lodash';
|
||||
import { isDate } from 'lodash';
|
||||
|
||||
import { TimeZone } from '../types/time';
|
||||
|
||||
@@ -12,7 +12,11 @@ import {
|
||||
ISO_8601,
|
||||
} from './moment_wrapper';
|
||||
|
||||
const units: DurationUnit[] = ['y', 'M', 'w', 'd', 'h', 'm', 's', 'Q'];
|
||||
const units: string[] = ['y', 'M', 'w', 'd', 'h', 'm', 's', 'Q'] satisfies DurationUnit[];
|
||||
|
||||
const isDurationUnit = (value: string): value is DurationUnit => {
|
||||
return units.includes(value);
|
||||
};
|
||||
|
||||
/**
|
||||
* Determine if a string contains a relative date time.
|
||||
@@ -169,11 +173,9 @@ export function parseDateMath(
|
||||
isFiscal = true;
|
||||
}
|
||||
|
||||
const unit = unitString as DurationUnit;
|
||||
const unit = unitString;
|
||||
|
||||
if (!includes(units, unit)) {
|
||||
return undefined;
|
||||
} else {
|
||||
if (isDurationUnit(unit)) {
|
||||
if (type === 0) {
|
||||
if (isFiscal) {
|
||||
roundToFiscal(fiscalYearStartMonth, result, unit, roundUp);
|
||||
@@ -189,6 +191,8 @@ export function parseDateMath(
|
||||
} else if (type === 2) {
|
||||
result.subtract(num, unit);
|
||||
}
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { add, Duration, intervalToDuration, Interval, isAfter } from 'date-fns';
|
||||
|
||||
const durationMap: { [key in Required<keyof Duration>]: string[] } = {
|
||||
const durationMap: Record<string, string[]> = {
|
||||
years: ['y', 'Y', 'years'],
|
||||
months: ['M', 'months'],
|
||||
weeks: ['w', 'W', 'weeks'],
|
||||
@@ -8,7 +8,7 @@ const durationMap: { [key in Required<keyof Duration>]: string[] } = {
|
||||
hours: ['h', 'H', 'hours'],
|
||||
minutes: ['m', 'minutes'],
|
||||
seconds: ['s', 'S', 'seconds'],
|
||||
};
|
||||
} satisfies { [key in keyof Duration]: string[] };
|
||||
|
||||
/**
|
||||
* intervalToAbbreviatedDurationString converts interval to readable duration string
|
||||
@@ -26,7 +26,7 @@ export function intervalToAbbreviatedDurationString(interval: Interval, includeS
|
||||
}
|
||||
|
||||
const duration = intervalToDuration(interval);
|
||||
return (Object.entries(duration) as Array<[keyof Duration, number | undefined]>).reduce((str, [unit, value]) => {
|
||||
return Object.entries(duration).reduce((str, [unit, value]) => {
|
||||
if (value && value !== 0 && !(unit === 'seconds' && !includeSeconds && str)) {
|
||||
const padding = str !== '' ? ' ' : '';
|
||||
return str + `${padding}${value}${durationMap[unit][0]}`;
|
||||
|
||||
@@ -94,7 +94,7 @@ export type PanelOptionsSupplier<TOptions> = (
|
||||
|
||||
export class PanelPlugin<
|
||||
TOptions = any,
|
||||
TFieldConfigOptions extends object = any,
|
||||
TFieldConfigOptions extends object = {},
|
||||
> extends GrafanaPlugin<PanelPluginMeta> {
|
||||
private _defaults?: TOptions;
|
||||
private _fieldConfigDefaults: FieldConfigSource<TFieldConfigOptions> = {
|
||||
|
||||
@@ -16,7 +16,7 @@ export interface TransformerUIProps<T> {
|
||||
onChange: (options: T) => void;
|
||||
}
|
||||
|
||||
export interface TransformerRegistryItem<TOptions> extends RegistryItem {
|
||||
export interface TransformerRegistryItem<TOptions = any> extends RegistryItem {
|
||||
/**
|
||||
* Object describing transformer configuration
|
||||
*/
|
||||
@@ -50,4 +50,4 @@ export enum TransformerCategory {
|
||||
* Registry of transformation options that can be driven by
|
||||
* stored configuration files.
|
||||
*/
|
||||
export const standardTransformersRegistry = new Registry<TransformerRegistryItem<any>>();
|
||||
export const standardTransformersRegistry = new Registry<TransformerRegistryItem>();
|
||||
|
||||
@@ -43,11 +43,7 @@ function filterInput(data: DataFrame[], matcher?: FrameMatcher) {
|
||||
}
|
||||
|
||||
const postProcessTransform =
|
||||
(
|
||||
before: DataFrame[],
|
||||
info: TransformerRegistryItem<any>,
|
||||
matcher?: FrameMatcher
|
||||
): MonoTypeOperatorFunction<DataFrame[]> =>
|
||||
(before: DataFrame[], info: TransformerRegistryItem, matcher?: FrameMatcher): MonoTypeOperatorFunction<DataFrame[]> =>
|
||||
(source) =>
|
||||
source.pipe(
|
||||
map((after) => {
|
||||
|
||||
@@ -88,7 +88,7 @@ function reduceSeriesToRows(
|
||||
config: {},
|
||||
});
|
||||
|
||||
const labels: KeyValue<any[]> = {};
|
||||
const labels: KeyValue<unknown[]> = {};
|
||||
if (labelsToFields) {
|
||||
for (const key of distinctLabels) {
|
||||
labels[key] = new Array(size);
|
||||
@@ -101,7 +101,7 @@ function reduceSeriesToRows(
|
||||
}
|
||||
}
|
||||
|
||||
const calcs: KeyValue<any[]> = {};
|
||||
const calcs: KeyValue<unknown[]> = {};
|
||||
for (const info of calculators) {
|
||||
calcs[info.id] = new Array(size);
|
||||
fields.push({
|
||||
|
||||
@@ -59,11 +59,11 @@ interface OptionsUIRegistryBuilderAPI<
|
||||
config: OptionEditorConfig<TOptions, TSettings, TOption>
|
||||
): this;
|
||||
|
||||
addBooleanSwitch?<TSettings = any>(config: OptionEditorConfig<TOptions, TSettings, boolean>): this;
|
||||
addBooleanSwitch?<TSettings>(config: OptionEditorConfig<TOptions, TSettings, boolean>): this;
|
||||
|
||||
addUnitPicker?<TSettings = any>(config: OptionEditorConfig<TOptions, TSettings, string>): this;
|
||||
addUnitPicker?<TSettings>(config: OptionEditorConfig<TOptions, TSettings, string>): this;
|
||||
|
||||
addColorPicker?<TSettings = any>(config: OptionEditorConfig<TOptions, TSettings, string>): this;
|
||||
addColorPicker?<TSettings>(config: OptionEditorConfig<TOptions, TSettings, string>): this;
|
||||
|
||||
/**
|
||||
* Enables custom editor definition
|
||||
|
||||
@@ -82,7 +82,7 @@ export class AppPlugin<T extends KeyValue = KeyValue> extends GrafanaPlugin<AppP
|
||||
return this;
|
||||
}
|
||||
|
||||
setComponentsFromLegacyExports(pluginExports: any) {
|
||||
setComponentsFromLegacyExports(pluginExports: System.Module) {
|
||||
if (pluginExports.ConfigCtrl) {
|
||||
this.angularConfigCtrl = pluginExports.ConfigCtrl;
|
||||
}
|
||||
@@ -145,7 +145,7 @@ export class AppPlugin<T extends KeyValue = KeyValue> extends GrafanaPlugin<AppP
|
||||
this.addComponent({
|
||||
targets: [extension.extensionPointId],
|
||||
...extension,
|
||||
component: extension.component as ComponentType,
|
||||
component: extension.component,
|
||||
});
|
||||
|
||||
return this;
|
||||
|
||||
@@ -208,7 +208,6 @@ export interface GrafanaConfig {
|
||||
http2Enabled: boolean;
|
||||
dateFormats?: SystemDateFormatSettings;
|
||||
grafanaJavascriptAgent: GrafanaJavascriptAgentConfig;
|
||||
customTheme?: any;
|
||||
geomapDefaultBaseLayer?: MapLayerOptions;
|
||||
geomapDisableCustomBaseLayer?: boolean;
|
||||
unifiedAlertingEnabled: boolean;
|
||||
|
||||
@@ -114,7 +114,7 @@ export class DataSourcePlugin<
|
||||
return this;
|
||||
}
|
||||
|
||||
setComponentsFromLegacyExports(pluginExports: any) {
|
||||
setComponentsFromLegacyExports(pluginExports: System.Module) {
|
||||
this.angularConfigCtrl = pluginExports.ConfigCtrl;
|
||||
|
||||
this.components.QueryCtrl = pluginExports.QueryCtrl;
|
||||
|
||||
@@ -169,7 +169,7 @@ export interface PanelMenuItem {
|
||||
type?: 'submenu' | 'divider' | 'group';
|
||||
text: string;
|
||||
iconClassName?: IconName;
|
||||
onClick?: (event: React.MouseEvent<any>) => void;
|
||||
onClick?: (event: React.MouseEvent) => void;
|
||||
shortcut?: string;
|
||||
href?: string;
|
||||
subMenu?: PanelMenuItem[];
|
||||
|
||||
@@ -30,7 +30,7 @@ import { PanelOptionsEditorConfig, PanelOptionsEditorItem } from '../types/panel
|
||||
*/
|
||||
export class FieldConfigEditorBuilder<TOptions> extends OptionsUIRegistryBuilder<
|
||||
TOptions,
|
||||
StandardEditorProps<any, any>,
|
||||
StandardEditorProps,
|
||||
FieldConfigPropertyItem<TOptions>
|
||||
> {
|
||||
addNumberInput<TSettings>(config: FieldConfigEditorConfig<TOptions, TSettings & NumberFieldConfigSettings, number>) {
|
||||
@@ -84,7 +84,7 @@ export class FieldConfigEditorBuilder<TOptions> extends OptionsUIRegistryBuilder
|
||||
});
|
||||
}
|
||||
|
||||
addRadio<TOption, TSettings = any>(config: FieldConfigEditorConfig<TOptions, TSettings, TOption>) {
|
||||
addRadio<TOption, TSettings>(config: FieldConfigEditorConfig<TOptions, TSettings, TOption>) {
|
||||
return this.addCustomEditor({
|
||||
...config,
|
||||
id: config.path,
|
||||
@@ -97,7 +97,7 @@ export class FieldConfigEditorBuilder<TOptions> extends OptionsUIRegistryBuilder
|
||||
});
|
||||
}
|
||||
|
||||
addBooleanSwitch<TSettings = any>(config: FieldConfigEditorConfig<TOptions, TSettings, boolean>) {
|
||||
addBooleanSwitch<TSettings>(config: FieldConfigEditorConfig<TOptions, TSettings, boolean>) {
|
||||
return this.addCustomEditor({
|
||||
...config,
|
||||
id: config.path,
|
||||
@@ -109,7 +109,7 @@ export class FieldConfigEditorBuilder<TOptions> extends OptionsUIRegistryBuilder
|
||||
});
|
||||
}
|
||||
|
||||
addColorPicker<TSettings = any>(config: FieldConfigEditorConfig<TOptions, TSettings, string>) {
|
||||
addColorPicker<TSettings>(config: FieldConfigEditorConfig<TOptions, TSettings, string>) {
|
||||
return this.addCustomEditor({
|
||||
...config,
|
||||
id: config.path,
|
||||
@@ -121,9 +121,7 @@ export class FieldConfigEditorBuilder<TOptions> extends OptionsUIRegistryBuilder
|
||||
});
|
||||
}
|
||||
|
||||
addUnitPicker<TSettings = any>(
|
||||
config: FieldConfigEditorConfig<TOptions, TSettings & UnitFieldConfigSettings, string>
|
||||
) {
|
||||
addUnitPicker<TSettings>(config: FieldConfigEditorConfig<TOptions, TSettings & UnitFieldConfigSettings, string>) {
|
||||
return this.addCustomEditor({
|
||||
...config,
|
||||
id: config.path,
|
||||
@@ -135,7 +133,7 @@ export class FieldConfigEditorBuilder<TOptions> extends OptionsUIRegistryBuilder
|
||||
});
|
||||
}
|
||||
|
||||
addFieldNamePicker<TSettings = any>(
|
||||
addFieldNamePicker<TSettings>(
|
||||
config: FieldConfigEditorConfig<TOptions, TSettings & FieldNamePickerConfigSettings, string>
|
||||
): this {
|
||||
return this.addCustomEditor({
|
||||
@@ -149,7 +147,7 @@ export class FieldConfigEditorBuilder<TOptions> extends OptionsUIRegistryBuilder
|
||||
});
|
||||
}
|
||||
|
||||
addGenericEditor<TSettings = any>(
|
||||
addGenericEditor<TSettings>(
|
||||
config: FieldConfigEditorConfig<TOptions, TSettings & any>, // & any... i give up!
|
||||
editor: (props: StandardEditorProps<TSettings>) => JSX.Element
|
||||
): this {
|
||||
@@ -168,7 +166,7 @@ export class FieldConfigEditorBuilder<TOptions> extends OptionsUIRegistryBuilder
|
||||
export interface NestedValueAccess {
|
||||
getValue: (path: string) => any;
|
||||
onChange: (path: string, value: any) => void;
|
||||
getContext?: (parent: StandardEditorContext<any, any>) => StandardEditorContext<any, any>;
|
||||
getContext?: (parent: StandardEditorContext<any>) => StandardEditorContext<any>;
|
||||
}
|
||||
export interface NestedPanelOptions<TSub = any> {
|
||||
path: string;
|
||||
@@ -307,7 +305,7 @@ export class PanelOptionsEditorBuilder<TOptions> extends OptionsUIRegistryBuilde
|
||||
});
|
||||
}
|
||||
|
||||
addBooleanSwitch<TSettings = any>(config: PanelOptionsEditorConfig<TOptions, TSettings, boolean>) {
|
||||
addBooleanSwitch<TSettings>(config: PanelOptionsEditorConfig<TOptions, TSettings, boolean>) {
|
||||
return this.addCustomEditor({
|
||||
...config,
|
||||
id: config.path,
|
||||
@@ -315,7 +313,7 @@ export class PanelOptionsEditorBuilder<TOptions> extends OptionsUIRegistryBuilde
|
||||
});
|
||||
}
|
||||
|
||||
addColorPicker<TSettings = any>(config: PanelOptionsEditorConfig<TOptions, TSettings, string>): this {
|
||||
addColorPicker<TSettings>(config: PanelOptionsEditorConfig<TOptions, TSettings, string>): this {
|
||||
return this.addCustomEditor({
|
||||
...config,
|
||||
id: config.path,
|
||||
@@ -324,7 +322,7 @@ export class PanelOptionsEditorBuilder<TOptions> extends OptionsUIRegistryBuilde
|
||||
});
|
||||
}
|
||||
|
||||
addTimeZonePicker<TSettings = any>(config: PanelOptionsEditorConfig<TOptions, TSettings, string>): this {
|
||||
addTimeZonePicker<TSettings>(config: PanelOptionsEditorConfig<TOptions, TSettings, string>): this {
|
||||
return this.addCustomEditor({
|
||||
...config,
|
||||
id: config.path,
|
||||
@@ -333,7 +331,7 @@ export class PanelOptionsEditorBuilder<TOptions> extends OptionsUIRegistryBuilde
|
||||
});
|
||||
}
|
||||
|
||||
addUnitPicker<TSettings = any>(
|
||||
addUnitPicker<TSettings>(
|
||||
config: PanelOptionsEditorConfig<TOptions, TSettings & UnitFieldConfigSettings, string>
|
||||
): this {
|
||||
return this.addCustomEditor({
|
||||
@@ -343,7 +341,7 @@ export class PanelOptionsEditorBuilder<TOptions> extends OptionsUIRegistryBuilde
|
||||
});
|
||||
}
|
||||
|
||||
addFieldNamePicker<TSettings = any>(
|
||||
addFieldNamePicker<TSettings>(
|
||||
config: PanelOptionsEditorConfig<TOptions, TSettings & FieldNamePickerConfigSettings, string>
|
||||
): this {
|
||||
return this.addCustomEditor({
|
||||
@@ -353,7 +351,7 @@ export class PanelOptionsEditorBuilder<TOptions> extends OptionsUIRegistryBuilde
|
||||
});
|
||||
}
|
||||
|
||||
addDashboardPicker<TSettings = any>(
|
||||
addDashboardPicker<TSettings>(
|
||||
config: PanelOptionsEditorConfig<TOptions, TSettings & FieldNamePickerConfigSettings, string>
|
||||
): this {
|
||||
return this.addCustomEditor({
|
||||
|
||||
@@ -74,7 +74,7 @@ export function mapInternalLinkToExplore(options: LinkToExploreOptions): LinkMod
|
||||
/**
|
||||
* Generates href for internal derived field link.
|
||||
*/
|
||||
function generateInternalHref<T extends DataQuery = any>(
|
||||
function generateInternalHref<T extends DataQuery>(
|
||||
datasourceUid: string,
|
||||
query: T,
|
||||
range?: TimeRange,
|
||||
|
||||
@@ -140,7 +140,6 @@ export class GrafanaBootConfig implements GrafanaConfig {
|
||||
pluginCatalogPreinstalledPlugins: PreinstalledPlugin[] = [];
|
||||
pluginsCDNBaseURL = '';
|
||||
expressionsEnabled = false;
|
||||
customTheme?: undefined;
|
||||
awsAllowedAuthProviders: string[] = [];
|
||||
awsAssumeRoleEnabled = false;
|
||||
azure: AzureSettings = {
|
||||
|
||||
@@ -30,6 +30,8 @@ export const InfoBox = React.memo(
|
||||
const styles = useStyles2(getStyles);
|
||||
|
||||
return (
|
||||
// component is deprecated so no point fixing this
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
<Alert severity={severity} className={className} {...otherProps} ref={ref} title={title as string}>
|
||||
<div>{children}</div>
|
||||
{url && (
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { throttle } from 'lodash';
|
||||
|
||||
type Args = Parameters<typeof console.log>;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* */
|
||||
const throttledLog = throttle((...t: any[]) => {
|
||||
const throttledLog = throttle((...t: Args) => {
|
||||
console.log(...t);
|
||||
}, 500);
|
||||
|
||||
@@ -11,7 +13,7 @@ const throttledLog = throttle((...t: any[]) => {
|
||||
* @internal
|
||||
*/
|
||||
export interface Logger {
|
||||
logger: (...t: any[]) => void;
|
||||
logger: (...t: Args) => void;
|
||||
enable: () => void;
|
||||
disable: () => void;
|
||||
isEnabled: () => boolean;
|
||||
@@ -26,7 +28,7 @@ export const createLogger = (name: string): Logger => {
|
||||
}
|
||||
|
||||
return {
|
||||
logger: (id: string, throttle = false, ...t: any[]) => {
|
||||
logger: (id: string, throttle = false, ...t: Args) => {
|
||||
if (process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'test' || !loggingEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -35,21 +35,6 @@ const ThemeableStory = ({
|
||||
);
|
||||
};
|
||||
|
||||
// Temporary solution. When we update to Storybook V5 we will be able to pass data from decorator to story
|
||||
// https://github.com/storybooks/storybook/issues/340#issuecomment-456013702
|
||||
export const renderComponentWithTheme = (component: React.ComponentType<any>, props: any) => {
|
||||
return (
|
||||
<ThemeContext.Consumer>
|
||||
{(theme) => {
|
||||
return React.createElement(component, {
|
||||
...props,
|
||||
theme,
|
||||
});
|
||||
}}
|
||||
</ThemeContext.Consumer>
|
||||
);
|
||||
};
|
||||
|
||||
export const withTheme =
|
||||
(handleSassThemeChange: SassThemeChangeHandler): Decorator =>
|
||||
// eslint-disable-next-line react/display-name
|
||||
|
||||
Reference in New Issue
Block a user