1import { 2 DataLink, 3 Field, 4 FieldOverrideContext, 5 SelectableValue, 6 SliderMarks, 7 ThresholdsConfig, 8 ValueMapping, 9} from '../../types'; 10 11export const identityOverrideProcessor = <T>(value: T, _context: FieldOverrideContext, _settings: any) => { 12 return value; 13}; 14 15export interface NumberFieldConfigSettings { 16 placeholder?: string; 17 integer?: boolean; 18 min?: number; 19 max?: number; 20 step?: number; 21} 22 23export const numberOverrideProcessor = ( 24 value: any, 25 context: FieldOverrideContext, 26 settings?: NumberFieldConfigSettings 27) => { 28 if (value === undefined || value === null) { 29 return undefined; 30 } 31 32 return parseFloat(value); 33}; 34 35export const displayNameOverrideProcessor = ( 36 value: any, 37 context: FieldOverrideContext, 38 settings?: StringFieldConfigSettings 39) => { 40 // clear the cached display name 41 delete context.field?.state?.displayName; 42 return stringOverrideProcessor(value, context, settings); 43}; 44 45export interface SliderFieldConfigSettings { 46 min: number; 47 max: number; 48 step?: number; 49 included?: boolean; 50 marks?: SliderMarks; 51 ariaLabelForHandle?: string; 52} 53 54export interface DataLinksFieldConfigSettings {} 55 56export const dataLinksOverrideProcessor = ( 57 value: any, 58 _context: FieldOverrideContext, 59 _settings?: DataLinksFieldConfigSettings 60) => { 61 return value as DataLink[]; 62}; 63 64export interface ValueMappingFieldConfigSettings {} 65 66export const valueMappingsOverrideProcessor = ( 67 value: any, 68 _context: FieldOverrideContext, 69 _settings?: ValueMappingFieldConfigSettings 70) => { 71 return value as ValueMapping[]; // !!!! likely not !!!! 72}; 73 74export interface SelectFieldConfigSettings<T> { 75 allowCustomValue?: boolean; 76 77 /** The default options */ 78 options: Array<SelectableValue<T>>; 79 80 /** Optionally use the context to define the options */ 81 getOptions?: (context: FieldOverrideContext) => Promise<Array<SelectableValue<T>>>; 82} 83 84export const selectOverrideProcessor = ( 85 value: any, 86 _context: FieldOverrideContext, 87 _settings?: SelectFieldConfigSettings<any> 88) => { 89 return value; 90}; 91 92export interface StringFieldConfigSettings { 93 placeholder?: string; 94 maxLength?: number; 95 expandTemplateVars?: boolean; 96 useTextarea?: boolean; 97 rows?: number; 98} 99 100export const stringOverrideProcessor = ( 101 value: any, 102 context: FieldOverrideContext, 103 settings?: StringFieldConfigSettings 104) => { 105 if (value === null || value === undefined) { 106 return value; 107 } 108 if (settings && settings.expandTemplateVars && context.replaceVariables) { 109 return context.replaceVariables(value, context.field!.state!.scopedVars); 110 } 111 return `${value}`; 112}; 113 114export interface ThresholdsFieldConfigSettings { 115 // Anything? 116} 117 118export const thresholdsOverrideProcessor = ( 119 value: any, 120 _context: FieldOverrideContext, 121 _settings?: ThresholdsFieldConfigSettings 122) => { 123 return value as ThresholdsConfig; // !!!! likely not !!!! 124}; 125 126export interface UnitFieldConfigSettings {} 127 128export const unitOverrideProcessor = ( 129 value: boolean, 130 _context: FieldOverrideContext, 131 _settings?: UnitFieldConfigSettings 132) => { 133 return value; 134}; 135 136export const booleanOverrideProcessor = ( 137 value: boolean, 138 _context: FieldOverrideContext, 139 _settings?: ThresholdsFieldConfigSettings 140) => { 141 return value; // !!!! likely not !!!! 142}; 143 144export interface FieldColorConfigSettings { 145 /** 146 * When switching to a visualization that does not support by value coloring then Grafana will 147 * switch to a by series palette based color mode 148 */ 149 byValueSupport?: boolean; 150 /** 151 * When switching to a visualization that has this set to true then Grafana will change color mode 152 * to from thresholds if it was set to a by series palette 153 */ 154 preferThresholdsMode?: boolean; 155 /** 156 * Set to true if the visualization supports both by value and by series 157 * This will enable the Color by series UI option that sets the `color.seriesBy` option. 158 */ 159 bySeriesSupport?: boolean; 160} 161 162export interface StatsPickerConfigSettings { 163 /** 164 * Enable multi-selection in the stats picker 165 */ 166 allowMultiple: boolean; 167 /** 168 * Default stats to be use in the stats picker 169 */ 170 defaultStat?: string; 171} 172 173export interface FieldNamePickerConfigSettings { 174 /** 175 * Function is a predicate, to test each element of the array. 176 * Return a value that coerces to true to keep the field, or to false otherwise. 177 */ 178 filter?: (field: Field) => boolean; 179 180 /** 181 * Show this text when no values are found 182 */ 183 noFieldsMessage?: string; 184 185 /**addFieldNamePicker 186 * Sets the width to a pixel value. 187 */ 188 width?: number; 189 190 /** 191 * Placeholder text to display when nothing is selected. 192 */ 193 placeholderText?: string; 194} 195