Commit a45794d0 by Torkel Ödegaard Committed by GitHub

FieldConfigs: String select type & cell display mode added to table panel (#22274)

* FieldConfigs: Added string select field config

* FieldConfigs: Added string select field config

* Changed to generic select type
parent e591fbc3
import React, { FC } from 'react';
import { FieldOverrideContext, FieldOverrideEditorProps, FieldConfigEditorProps, SelectableValue } from '@grafana/data';
import Forms from '../Forms';
export interface SelectFieldConfigSettings<T> {
options: Array<SelectableValue<T>>;
}
export const selectOverrideProcessor = (
value: any,
context: FieldOverrideContext,
settings: SelectFieldConfigSettings<any>
) => {
return value;
};
export const SelectValueEditor: FC<FieldConfigEditorProps<string, SelectFieldConfigSettings<any>>> = ({
item,
value,
onChange,
}) => {
return <Forms.Select value={value || ''} onChange={e => onChange(e.value)} options={item.settings.options} />;
};
export const SelectOverrideEditor: FC<FieldOverrideEditorProps<string, SelectFieldConfigSettings<any>>> = ({
item,
value,
onChange,
}) => {
return <Forms.Select value={value || ''} onChange={e => onChange(e.value)} options={item.settings.options} />;
};
...@@ -130,6 +130,12 @@ export { ...@@ -130,6 +130,12 @@ export {
numberOverrideProcessor, numberOverrideProcessor,
NumberFieldConfigSettings, NumberFieldConfigSettings,
} from './FieldConfigs/number'; } from './FieldConfigs/number';
export {
selectOverrideProcessor,
SelectValueEditor,
SelectOverrideEditor,
SelectFieldConfigSettings,
} from './FieldConfigs/select';
// Next-gen forms // Next-gen forms
export { default as Forms } from './Forms'; export { default as Forms } from './Forms';
......
...@@ -4,25 +4,51 @@ import { ...@@ -4,25 +4,51 @@ import {
NumberOverrideEditor, NumberOverrideEditor,
numberOverrideProcessor, numberOverrideProcessor,
NumberFieldConfigSettings, NumberFieldConfigSettings,
selectOverrideProcessor,
SelectValueEditor,
SelectOverrideEditor,
SelectFieldConfigSettings,
} from '@grafana/ui'; } from '@grafana/ui';
const columWidth: FieldPropertyEditorItem<number, NumberFieldConfigSettings> = { export const tableFieldRegistry: FieldConfigEditorRegistry = new Registry<FieldPropertyEditorItem>(() => {
id: 'width', // Match field properties const columWidth: FieldPropertyEditorItem<number, NumberFieldConfigSettings> = {
name: 'Column Width', id: 'width', // Match field properties
description: 'column width (for table)', name: 'Column width',
description: 'column width (for table)',
editor: NumberValueEditor, editor: NumberValueEditor,
override: NumberOverrideEditor, override: NumberOverrideEditor,
process: numberOverrideProcessor, process: numberOverrideProcessor,
settings: { settings: {
placeholder: 'auto', placeholder: 'auto',
min: 20, min: 20,
max: 300, max: 300,
}, },
shouldApply: () => true,
};
export const tableFieldRegistry: FieldConfigEditorRegistry = new Registry<FieldPropertyEditorItem>(() => { shouldApply: () => true,
return [columWidth]; };
const cellDisplayMode: FieldPropertyEditorItem<string, SelectFieldConfigSettings<string>> = {
id: 'displayMode', // Match field properties
name: 'Cell display mode',
description: 'Color value, background, show as gauge, etc',
editor: SelectValueEditor,
override: SelectOverrideEditor,
process: selectOverrideProcessor,
settings: {
options: [
{ value: 'auto', label: 'Auto' },
{ value: 'color-background', label: 'Color background' },
{ value: 'gradient-gauge', label: 'Gradient gauge' },
{ value: 'lcd-gauge', label: 'LCD gauge' },
],
},
shouldApply: () => true,
};
return [columWidth, cellDisplayMode];
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment