/
fieldOverrides.ts
153 lines (128 loc) · 4.66 KB
/
fieldOverrides.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import { ComponentType } from 'react';
import { StandardEditorProps, FieldConfigOptionsRegistry, StandardEditorContext } from '../field';
import { GrafanaTheme2 } from '../themes';
import {
MatcherConfig,
FieldConfig,
Field,
DataFrame,
TimeZone,
ScopedVars,
ValueLinkConfig,
LinkModel,
DataLink,
} from '../types';
import { OptionsEditorItem } from './OptionsUIRegistryBuilder';
import { OptionEditorConfig } from './options';
import { InterpolateFunction } from './panel';
export interface DynamicConfigValue {
id: string;
value?: any;
}
export interface ConfigOverrideRule {
matcher: MatcherConfig;
properties: DynamicConfigValue[];
}
/**
* Describes config override rules created when interacting with Grafana.
*
* @internal
*/
export interface SystemConfigOverrideRule extends ConfigOverrideRule {
__systemRef: string;
}
/**
* Guard functionality to check if an override rule is of type {@link SystemConfigOverrideRule}.
* It will only return true if the {@link SystemConfigOverrideRule} has the passed systemRef.
*
* @param ref system override reference
* @internal
*/
export function isSystemOverrideWithRef<T extends SystemConfigOverrideRule>(ref: string) {
return (override: ConfigOverrideRule): override is T => {
return '__systemRef' in override && override.__systemRef === ref;
};
}
/**
* Guard functionality to check if an override rule is of type {@link SystemConfigOverrideRule}.
* It will return true if the {@link SystemConfigOverrideRule} has any systemRef set.
*
* @internal
*/
export const isSystemOverride = (override: ConfigOverrideRule): override is SystemConfigOverrideRule => {
return '__systemRef' in override && typeof override.__systemRef === 'string';
};
export interface FieldConfigSource<TOptions = any> {
// Defaults applied to all numeric fields
defaults: FieldConfig<TOptions>;
// Rules to override individual values
overrides: ConfigOverrideRule[];
}
export interface FieldOverrideContext extends StandardEditorContext<any> {
field?: Field;
dataFrameIndex?: number; // The index for the selected field frame
}
/** @deprecated Use StandardEditorProps instead */
export type FieldConfigEditorProps<TValue, TSettings extends {}> = StandardEditorProps<TValue, TSettings>;
/** @deprecated Use StandardEditorProps instead */
export type FieldOverrideEditorProps<TValue, TSettings extends {}> = StandardEditorProps<TValue, TSettings>;
export interface FieldConfigEditorConfig<TOptions, TSettings = any, TValue = any>
extends OptionEditorConfig<TOptions, TSettings, TValue> {
/**
* Function that allows specifying whether or not this field config should apply to a given field.
* @param field
*/
shouldApply?: (field: Field) => boolean;
/** Indicates that option shoukd not be available in the Field config tab */
hideFromDefaults?: boolean;
/** Indicates that option should not be available for the overrides */
hideFromOverrides?: boolean;
}
export interface FieldConfigPropertyItem<TOptions = any, TValue = any, TSettings extends {} = any>
extends OptionsEditorItem<TOptions, TSettings, StandardEditorProps<TValue, TSettings>, TValue> {
// An editor that can be filled in with context info (template variables etc)
override: ComponentType<StandardEditorProps<TValue, TSettings>>;
/** true for plugin field config properties */
isCustom?: boolean;
/** Hides option from the Field config tab */
hideFromDefaults?: boolean;
/** Indicates that option should not be available for the overrides */
hideFromOverrides?: boolean;
/** Convert the override value to a well typed value */
process: (value: any, context: FieldOverrideContext, settings?: TSettings) => TValue | undefined | null;
/** Checks if field should be processed */
shouldApply: (field: Field) => boolean;
}
export type DataLinkPostProcessorOptions = {
frame: DataFrame;
field: Field;
dataLinkScopedVars: ScopedVars;
replaceVariables: InterpolateFunction;
timeZone?: TimeZone;
config: ValueLinkConfig;
link: DataLink;
linkModel: LinkModel;
};
export type DataLinkPostProcessor = (options: DataLinkPostProcessorOptions) => LinkModel<Field> | undefined;
export interface ApplyFieldOverrideOptions {
data?: DataFrame[];
fieldConfig: FieldConfigSource;
fieldConfigRegistry?: FieldConfigOptionsRegistry;
replaceVariables: InterpolateFunction;
theme: GrafanaTheme2;
timeZone?: TimeZone;
dataLinkPostProcessor?: DataLinkPostProcessor;
}
export enum FieldConfigProperty {
Unit = 'unit',
Min = 'min',
Max = 'max',
Decimals = 'decimals',
DisplayName = 'displayName',
NoValue = 'noValue',
Thresholds = 'thresholds',
Mappings = 'mappings',
Links = 'links',
Color = 'color',
Filterable = 'filterable',
}