|
|
|
|
@ -1,14 +1,21 @@ |
|
|
|
|
import React from 'react'; |
|
|
|
|
|
|
|
|
|
import { |
|
|
|
|
DataLink, |
|
|
|
|
dataLinksOverrideProcessor, |
|
|
|
|
FieldConfigPropertyItem, |
|
|
|
|
FieldType, |
|
|
|
|
NumberFieldConfigSettings, |
|
|
|
|
numberOverrideProcessor, |
|
|
|
|
standardEditorsRegistry, |
|
|
|
|
StandardEditorsRegistryItem, |
|
|
|
|
ThresholdsConfig, |
|
|
|
|
ThresholdsFieldConfigSettings, |
|
|
|
|
ThresholdsMode, |
|
|
|
|
thresholdsOverrideProcessor, |
|
|
|
|
ValueMapping, |
|
|
|
|
ValueMappingFieldConfigSettings, |
|
|
|
|
valueMappingsOverrideProcessor, |
|
|
|
|
DataLink, |
|
|
|
|
dataLinksOverrideProcessor, |
|
|
|
|
NumberFieldConfigSettings, |
|
|
|
|
numberOverrideProcessor, |
|
|
|
|
StringFieldConfigSettings, |
|
|
|
|
stringOverrideProcessor, |
|
|
|
|
identityOverrideProcessor, |
|
|
|
|
@ -19,29 +26,186 @@ import { |
|
|
|
|
displayNameOverrideProcessor, |
|
|
|
|
FieldNamePickerConfigSettings, |
|
|
|
|
} from '@grafana/data'; |
|
|
|
|
import { RadioButtonGroup, TimeZonePicker, Switch } from '@grafana/ui'; |
|
|
|
|
import { FieldNamePicker } from '@grafana/ui/src/components/MatchersUI/FieldNamePicker'; |
|
|
|
|
import { ThresholdsValueEditor } from 'app/features/dimensions/editors/ThresholdsEditor/thresholds'; |
|
|
|
|
import { ValueMappingsEditor } from 'app/features/dimensions/editors/ValueMappingsEditor/ValueMappingsEditor'; |
|
|
|
|
|
|
|
|
|
import { DashboardPicker, DashboardPickerOptions } from './DashboardPicker'; |
|
|
|
|
import { ColorValueEditor } from './color'; |
|
|
|
|
import { FieldColorEditor } from './fieldColor'; |
|
|
|
|
import { DataLinksValueEditor } from './links'; |
|
|
|
|
import { MultiSelectValueEditor } from './multiSelect'; |
|
|
|
|
import { NumberValueEditor } from './number'; |
|
|
|
|
import { SelectValueEditor } from './select'; |
|
|
|
|
import { SliderValueEditor } from './slider'; |
|
|
|
|
import { StatsPickerEditor } from './stats'; |
|
|
|
|
import { StringValueEditor } from './string'; |
|
|
|
|
import { StringArrayEditor } from './strings'; |
|
|
|
|
import { UnitValueEditor } from './units'; |
|
|
|
|
|
|
|
|
|
import { |
|
|
|
|
NumberValueEditor, |
|
|
|
|
SliderValueEditor, |
|
|
|
|
RadioButtonGroup, |
|
|
|
|
StringValueEditor, |
|
|
|
|
StringArrayEditor, |
|
|
|
|
SelectValueEditor, |
|
|
|
|
MultiSelectValueEditor, |
|
|
|
|
TimeZonePicker, |
|
|
|
|
} from '../components'; |
|
|
|
|
import { FieldNamePicker } from '../components/MatchersUI/FieldNamePicker'; |
|
|
|
|
import { ColorValueEditor } from '../components/OptionsUI/color'; |
|
|
|
|
import { FieldColorEditor } from '../components/OptionsUI/fieldColor'; |
|
|
|
|
import { DataLinksValueEditor } from '../components/OptionsUI/links'; |
|
|
|
|
import { StatsPickerEditor } from '../components/OptionsUI/stats'; |
|
|
|
|
import { UnitValueEditor } from '../components/OptionsUI/units'; |
|
|
|
|
import { Switch } from '../components/Switch/Switch'; |
|
|
|
|
/** |
|
|
|
|
* Returns collection of standard option editors definitions |
|
|
|
|
*/ |
|
|
|
|
export const getAllOptionEditors = () => { |
|
|
|
|
const number: StandardEditorsRegistryItem<number> = { |
|
|
|
|
id: 'number', |
|
|
|
|
name: 'Number', |
|
|
|
|
description: 'Allows numeric values input', |
|
|
|
|
editor: NumberValueEditor as any, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const slider: StandardEditorsRegistryItem<number> = { |
|
|
|
|
id: 'slider', |
|
|
|
|
name: 'Slider', |
|
|
|
|
description: 'Allows numeric values input', |
|
|
|
|
editor: SliderValueEditor as any, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const text: StandardEditorsRegistryItem<string> = { |
|
|
|
|
id: 'text', |
|
|
|
|
name: 'Text', |
|
|
|
|
description: 'Allows string values input', |
|
|
|
|
editor: StringValueEditor as any, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const strings: StandardEditorsRegistryItem<string[]> = { |
|
|
|
|
id: 'strings', |
|
|
|
|
name: 'String array', |
|
|
|
|
description: 'An array of strings', |
|
|
|
|
editor: StringArrayEditor as any, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const boolean: StandardEditorsRegistryItem<boolean> = { |
|
|
|
|
id: 'boolean', |
|
|
|
|
name: 'Boolean', |
|
|
|
|
description: 'Allows boolean values input', |
|
|
|
|
editor(props) { |
|
|
|
|
return <Switch {...props} onChange={(e) => props.onChange(e.currentTarget.checked)} />; |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const select: StandardEditorsRegistryItem<any> = { |
|
|
|
|
id: 'select', |
|
|
|
|
name: 'Select', |
|
|
|
|
description: 'Allows option selection', |
|
|
|
|
editor: SelectValueEditor as any, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const multiSelect: StandardEditorsRegistryItem<any> = { |
|
|
|
|
id: 'multi-select', |
|
|
|
|
name: 'Multi select', |
|
|
|
|
description: 'Allows for multiple option selection', |
|
|
|
|
editor: MultiSelectValueEditor as any, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const radio: StandardEditorsRegistryItem<any> = { |
|
|
|
|
id: 'radio', |
|
|
|
|
name: 'Radio', |
|
|
|
|
description: 'Allows option selection', |
|
|
|
|
editor(props) { |
|
|
|
|
return <RadioButtonGroup {...props} options={props.item.settings?.options} />; |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const unit: StandardEditorsRegistryItem<string> = { |
|
|
|
|
id: 'unit', |
|
|
|
|
name: 'Unit', |
|
|
|
|
description: 'Allows unit input', |
|
|
|
|
editor: UnitValueEditor as any, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const color: StandardEditorsRegistryItem<string> = { |
|
|
|
|
id: 'color', |
|
|
|
|
name: 'Color', |
|
|
|
|
description: 'Allows color selection', |
|
|
|
|
editor(props) { |
|
|
|
|
return <ColorValueEditor value={props.value} onChange={props.onChange} />; |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const fieldColor: StandardEditorsRegistryItem<FieldColor> = { |
|
|
|
|
id: 'fieldColor', |
|
|
|
|
name: 'Field Color', |
|
|
|
|
description: 'Field color selection', |
|
|
|
|
editor: FieldColorEditor as any, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const links: StandardEditorsRegistryItem<DataLink[]> = { |
|
|
|
|
id: 'links', |
|
|
|
|
name: 'Links', |
|
|
|
|
description: 'Allows defining data links', |
|
|
|
|
editor: DataLinksValueEditor as any, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const statsPicker: StandardEditorsRegistryItem<string[], StatsPickerConfigSettings> = { |
|
|
|
|
id: 'stats-picker', |
|
|
|
|
name: 'Stats Picker', |
|
|
|
|
editor: StatsPickerEditor as any, |
|
|
|
|
description: '', |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const timeZone: StandardEditorsRegistryItem<TimeZone> = { |
|
|
|
|
id: 'timezone', |
|
|
|
|
name: 'Time Zone', |
|
|
|
|
description: 'Time zone selection', |
|
|
|
|
editor: TimeZonePicker as any, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const fieldName: StandardEditorsRegistryItem<string, FieldNamePickerConfigSettings> = { |
|
|
|
|
id: 'field-name', |
|
|
|
|
name: 'Field name', |
|
|
|
|
description: 'Allows selecting a field name from a data frame', |
|
|
|
|
editor: FieldNamePicker as any, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const dashboardPicker: StandardEditorsRegistryItem<string, DashboardPickerOptions> = { |
|
|
|
|
id: 'dashboard-uid', |
|
|
|
|
name: 'Dashboard', |
|
|
|
|
description: 'Select dashboard', |
|
|
|
|
editor: DashboardPicker as any, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const mappings: StandardEditorsRegistryItem<ValueMapping[]> = { |
|
|
|
|
id: 'mappings', |
|
|
|
|
name: 'Mappings', |
|
|
|
|
description: 'Allows defining value mappings', |
|
|
|
|
editor: ValueMappingsEditor as any, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const thresholds: StandardEditorsRegistryItem<ThresholdsConfig> = { |
|
|
|
|
id: 'thresholds', |
|
|
|
|
name: 'Thresholds', |
|
|
|
|
description: 'Allows defining thresholds', |
|
|
|
|
editor: ThresholdsValueEditor as any, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
return [ |
|
|
|
|
text, |
|
|
|
|
number, |
|
|
|
|
slider, |
|
|
|
|
boolean, |
|
|
|
|
radio, |
|
|
|
|
select, |
|
|
|
|
unit, |
|
|
|
|
links, |
|
|
|
|
statsPicker, |
|
|
|
|
strings, |
|
|
|
|
timeZone, |
|
|
|
|
fieldColor, |
|
|
|
|
color, |
|
|
|
|
multiSelect, |
|
|
|
|
fieldName, |
|
|
|
|
dashboardPicker, |
|
|
|
|
mappings, |
|
|
|
|
thresholds, |
|
|
|
|
]; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns collection of common field config properties definitions |
|
|
|
|
*/ |
|
|
|
|
export const getStandardFieldConfigs = () => { |
|
|
|
|
export const getAllStandardFieldConfigs = () => { |
|
|
|
|
const category = ['Standard options']; |
|
|
|
|
const displayName: FieldConfigPropertyItem<any, string, StringFieldConfigSettings> = { |
|
|
|
|
id: 'displayName', |
|
|
|
|
@ -180,141 +344,41 @@ export const getStandardFieldConfigs = () => { |
|
|
|
|
category, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
return [unit, min, max, decimals, displayName, color, noValue, links]; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns collection of standard option editors definitions |
|
|
|
|
* |
|
|
|
|
* @internal |
|
|
|
|
*/ |
|
|
|
|
export const getStandardOptionEditors = () => { |
|
|
|
|
const number: StandardEditorsRegistryItem<number> = { |
|
|
|
|
id: 'number', |
|
|
|
|
name: 'Number', |
|
|
|
|
description: 'Allows numeric values input', |
|
|
|
|
editor: NumberValueEditor as any, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const slider: StandardEditorsRegistryItem<number> = { |
|
|
|
|
id: 'slider', |
|
|
|
|
name: 'Slider', |
|
|
|
|
description: 'Allows numeric values input', |
|
|
|
|
editor: SliderValueEditor as any, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const text: StandardEditorsRegistryItem<string> = { |
|
|
|
|
id: 'text', |
|
|
|
|
name: 'Text', |
|
|
|
|
description: 'Allows string values input', |
|
|
|
|
editor: StringValueEditor as any, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const strings: StandardEditorsRegistryItem<string[]> = { |
|
|
|
|
id: 'strings', |
|
|
|
|
name: 'String array', |
|
|
|
|
description: 'An array of strings', |
|
|
|
|
editor: StringArrayEditor as any, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const boolean: StandardEditorsRegistryItem<boolean> = { |
|
|
|
|
id: 'boolean', |
|
|
|
|
name: 'Boolean', |
|
|
|
|
description: 'Allows boolean values input', |
|
|
|
|
editor(props) { |
|
|
|
|
return <Switch {...props} onChange={(e) => props.onChange(e.currentTarget.checked)} />; |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const select: StandardEditorsRegistryItem<any> = { |
|
|
|
|
id: 'select', |
|
|
|
|
name: 'Select', |
|
|
|
|
description: 'Allows option selection', |
|
|
|
|
editor: SelectValueEditor as any, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const multiSelect: StandardEditorsRegistryItem<any> = { |
|
|
|
|
id: 'multi-select', |
|
|
|
|
name: 'Multi select', |
|
|
|
|
description: 'Allows for multiple option selection', |
|
|
|
|
editor: MultiSelectValueEditor as any, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const radio: StandardEditorsRegistryItem<any> = { |
|
|
|
|
id: 'radio', |
|
|
|
|
name: 'Radio', |
|
|
|
|
description: 'Allows option selection', |
|
|
|
|
editor(props) { |
|
|
|
|
return <RadioButtonGroup {...props} options={props.item.settings?.options} />; |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const unit: StandardEditorsRegistryItem<string> = { |
|
|
|
|
id: 'unit', |
|
|
|
|
name: 'Unit', |
|
|
|
|
description: 'Allows unit input', |
|
|
|
|
editor: UnitValueEditor as any, |
|
|
|
|
const mappings: FieldConfigPropertyItem<any, ValueMapping[], ValueMappingFieldConfigSettings> = { |
|
|
|
|
id: 'mappings', |
|
|
|
|
path: 'mappings', |
|
|
|
|
name: 'Value mappings', |
|
|
|
|
description: 'Modify the display text based on input value', |
|
|
|
|
|
|
|
|
|
editor: standardEditorsRegistry.get('mappings').editor as any, |
|
|
|
|
override: standardEditorsRegistry.get('mappings').editor as any, |
|
|
|
|
process: valueMappingsOverrideProcessor, |
|
|
|
|
settings: {}, |
|
|
|
|
defaultValue: [], |
|
|
|
|
shouldApply: (x) => x.type !== FieldType.time, |
|
|
|
|
category: ['Value mappings'], |
|
|
|
|
getItemsCount: (value?) => (value ? value.length : 0), |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const color: StandardEditorsRegistryItem<string> = { |
|
|
|
|
id: 'color', |
|
|
|
|
name: 'Color', |
|
|
|
|
description: 'Allows color selection', |
|
|
|
|
editor(props) { |
|
|
|
|
return <ColorValueEditor value={props.value} onChange={props.onChange} />; |
|
|
|
|
const thresholds: FieldConfigPropertyItem<any, ThresholdsConfig, ThresholdsFieldConfigSettings> = { |
|
|
|
|
id: 'thresholds', |
|
|
|
|
path: 'thresholds', |
|
|
|
|
name: 'Thresholds', |
|
|
|
|
editor: standardEditorsRegistry.get('thresholds').editor as any, |
|
|
|
|
override: standardEditorsRegistry.get('thresholds').editor as any, |
|
|
|
|
process: thresholdsOverrideProcessor, |
|
|
|
|
settings: {}, |
|
|
|
|
defaultValue: { |
|
|
|
|
mode: ThresholdsMode.Absolute, |
|
|
|
|
steps: [ |
|
|
|
|
{ value: -Infinity, color: 'green' }, |
|
|
|
|
{ value: 80, color: 'red' }, |
|
|
|
|
], |
|
|
|
|
}, |
|
|
|
|
shouldApply: () => true, |
|
|
|
|
category: ['Thresholds'], |
|
|
|
|
getItemsCount: (value) => (value ? value.steps.length : 0), |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const fieldColor: StandardEditorsRegistryItem<FieldColor> = { |
|
|
|
|
id: 'fieldColor', |
|
|
|
|
name: 'Field Color', |
|
|
|
|
description: 'Field color selection', |
|
|
|
|
editor: FieldColorEditor as any, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const links: StandardEditorsRegistryItem<DataLink[]> = { |
|
|
|
|
id: 'links', |
|
|
|
|
name: 'Links', |
|
|
|
|
description: 'Allows defining data links', |
|
|
|
|
editor: DataLinksValueEditor as any, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const statsPicker: StandardEditorsRegistryItem<string[], StatsPickerConfigSettings> = { |
|
|
|
|
id: 'stats-picker', |
|
|
|
|
name: 'Stats Picker', |
|
|
|
|
editor: StatsPickerEditor as any, |
|
|
|
|
description: '', |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const timeZone: StandardEditorsRegistryItem<TimeZone> = { |
|
|
|
|
id: 'timezone', |
|
|
|
|
name: 'Time Zone', |
|
|
|
|
description: 'Time zone selection', |
|
|
|
|
editor: TimeZonePicker as any, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const fieldName: StandardEditorsRegistryItem<string, FieldNamePickerConfigSettings> = { |
|
|
|
|
id: 'field-name', |
|
|
|
|
name: 'Field name', |
|
|
|
|
description: 'Allows selecting a field name from a data frame', |
|
|
|
|
editor: FieldNamePicker as any, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
return [ |
|
|
|
|
text, |
|
|
|
|
number, |
|
|
|
|
slider, |
|
|
|
|
boolean, |
|
|
|
|
radio, |
|
|
|
|
select, |
|
|
|
|
unit, |
|
|
|
|
links, |
|
|
|
|
statsPicker, |
|
|
|
|
strings, |
|
|
|
|
timeZone, |
|
|
|
|
fieldColor, |
|
|
|
|
color, |
|
|
|
|
multiSelect, |
|
|
|
|
fieldName, |
|
|
|
|
]; |
|
|
|
|
return [unit, min, max, decimals, displayName, color, noValue, links, mappings, thresholds]; |
|
|
|
|
}; |