import React from 'react'; import { FieldConfigPropertyItem, FieldType, standardEditorsRegistry, StandardEditorsRegistryItem, ThresholdsConfig, ThresholdsFieldConfigSettings, ThresholdsMode, thresholdsOverrideProcessor, ValueMapping, ValueMappingFieldConfigSettings, valueMappingsOverrideProcessor, DataLink, dataLinksOverrideProcessor, NumberFieldConfigSettings, numberOverrideProcessor, StringFieldConfigSettings, stringOverrideProcessor, identityOverrideProcessor, TimeZone, FieldColor, FieldColorConfigSettings, StatsPickerConfigSettings, displayNameOverrideProcessor, FieldNamePickerConfigSettings, booleanOverrideProcessor, } 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'; /** * Returns collection of standard option editors definitions */ export const getAllOptionEditors = () => { const number: StandardEditorsRegistryItem = { id: 'number', name: 'Number', description: 'Allows numeric values input', editor: NumberValueEditor as any, }; const slider: StandardEditorsRegistryItem = { id: 'slider', name: 'Slider', description: 'Allows numeric values input', editor: SliderValueEditor as any, }; const text: StandardEditorsRegistryItem = { id: 'text', name: 'Text', description: 'Allows string values input', editor: StringValueEditor as any, }; const strings: StandardEditorsRegistryItem = { id: 'strings', name: 'String array', description: 'An array of strings', editor: StringArrayEditor as any, }; const boolean: StandardEditorsRegistryItem = { id: 'boolean', name: 'Boolean', description: 'Allows boolean values input', editor(props) { const { id, ...rest } = props; // Remove id from properties passed into switch return props.onChange(e.currentTarget.checked)} />; }, }; const select: StandardEditorsRegistryItem = { id: 'select', name: 'Select', description: 'Allows option selection', editor: SelectValueEditor as any, }; const multiSelect: StandardEditorsRegistryItem = { id: 'multi-select', name: 'Multi select', description: 'Allows for multiple option selection', editor: MultiSelectValueEditor as any, }; const radio: StandardEditorsRegistryItem = { id: 'radio', name: 'Radio', description: 'Allows option selection', editor(props) { return ; }, }; const unit: StandardEditorsRegistryItem = { id: 'unit', name: 'Unit', description: 'Allows unit input', editor: UnitValueEditor as any, }; const color: StandardEditorsRegistryItem = { id: 'color', name: 'Color', description: 'Allows color selection', editor(props) { return ; }, }; const fieldColor: StandardEditorsRegistryItem = { id: 'fieldColor', name: 'Field Color', description: 'Field color selection', editor: FieldColorEditor as any, }; const links: StandardEditorsRegistryItem = { id: 'links', name: 'Links', description: 'Allows defining data links', editor: DataLinksValueEditor as any, }; const statsPicker: StandardEditorsRegistryItem = { id: 'stats-picker', name: 'Stats Picker', editor: StatsPickerEditor as any, description: '', }; const timeZone: StandardEditorsRegistryItem = { id: 'timezone', name: 'Time zone', description: 'Time zone selection', editor: TimeZonePicker as any, }; const fieldName: StandardEditorsRegistryItem = { id: 'field-name', name: 'Field name', description: 'Allows selecting a field name from a data frame', editor: FieldNamePicker as any, }; const dashboardPicker: StandardEditorsRegistryItem = { id: 'dashboard-uid', name: 'Dashboard', description: 'Select dashboard', editor: DashboardPicker as any, }; const mappings: StandardEditorsRegistryItem = { id: 'mappings', name: 'Mappings', description: 'Allows defining value mappings', editor: ValueMappingsEditor as any, }; const thresholds: StandardEditorsRegistryItem = { 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 getAllStandardFieldConfigs = () => { const category = ['Standard options']; const displayName: FieldConfigPropertyItem = { id: 'displayName', path: 'displayName', name: 'Display name', description: 'Change the field or series name', editor: standardEditorsRegistry.get('text').editor as any, override: standardEditorsRegistry.get('text').editor as any, process: displayNameOverrideProcessor, settings: { placeholder: 'none', expandTemplateVars: true, }, shouldApply: () => true, category, }; const unit: FieldConfigPropertyItem = { id: 'unit', path: 'unit', name: 'Unit', description: '', editor: standardEditorsRegistry.get('unit').editor as any, override: standardEditorsRegistry.get('unit').editor as any, process: stringOverrideProcessor, settings: { placeholder: 'none', }, shouldApply: () => true, category, }; const min: FieldConfigPropertyItem = { id: 'min', path: 'min', name: 'Min', description: 'Leave empty to calculate based on all values', editor: standardEditorsRegistry.get('number').editor as any, override: standardEditorsRegistry.get('number').editor as any, process: numberOverrideProcessor, settings: { placeholder: 'auto', }, shouldApply: (field) => field.type === FieldType.number, category, }; const max: FieldConfigPropertyItem = { id: 'max', path: 'max', name: 'Max', description: 'Leave empty to calculate based on all values', editor: standardEditorsRegistry.get('number').editor as any, override: standardEditorsRegistry.get('number').editor as any, process: numberOverrideProcessor, settings: { placeholder: 'auto', }, shouldApply: (field) => field.type === FieldType.number, category, }; const decimals: FieldConfigPropertyItem = { id: 'decimals', path: 'decimals', name: 'Decimals', editor: standardEditorsRegistry.get('number').editor as any, override: standardEditorsRegistry.get('number').editor as any, process: numberOverrideProcessor, settings: { placeholder: 'auto', min: 0, max: 15, integer: true, }, shouldApply: (field) => field.type === FieldType.number, category, }; const noValue: FieldConfigPropertyItem = { id: 'noValue', path: 'noValue', name: 'No value', description: 'What to show when there is no value', editor: standardEditorsRegistry.get('text').editor as any, override: standardEditorsRegistry.get('text').editor as any, process: stringOverrideProcessor, settings: { placeholder: '-', }, // ??? any optionsUi with no value shouldApply: () => true, category, }; const links: FieldConfigPropertyItem = { id: 'links', path: 'links', name: 'Data links', editor: standardEditorsRegistry.get('links').editor as any, override: standardEditorsRegistry.get('links').editor as any, process: dataLinksOverrideProcessor, settings: { placeholder: '-', }, shouldApply: () => true, category: ['Data links'], getItemsCount: (value) => (value ? value.length : 0), }; const color: FieldConfigPropertyItem = { id: 'color', path: 'color', name: 'Color scheme', editor: standardEditorsRegistry.get('fieldColor').editor as any, override: standardEditorsRegistry.get('fieldColor').editor as any, process: identityOverrideProcessor, shouldApply: () => true, settings: { byValueSupport: true, preferThresholdsMode: true, }, category, }; const mappings: FieldConfigPropertyItem = { 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 thresholds: FieldConfigPropertyItem = { 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 filterable: FieldConfigPropertyItem<{}, boolean | undefined, {}> = { id: 'filterable', path: 'filterable', name: 'Ad-hoc filterable', hideFromDefaults: true, editor: standardEditorsRegistry.get('boolean').editor as any, override: standardEditorsRegistry.get('boolean').editor as any, process: booleanOverrideProcessor, shouldApply: () => true, settings: {}, category, }; return [unit, min, max, decimals, displayName, color, noValue, links, mappings, thresholds, filterable]; };