mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Registry: add a reusable function registry (#17047)
This commit is contained in:
@@ -1,17 +1,18 @@
|
||||
import { VizOrientation, SelectOptionItem, SingleStatBaseOptions } from '@grafana/ui';
|
||||
import { VizOrientation, SingleStatBaseOptions } from '@grafana/ui';
|
||||
import { standardGaugeFieldOptions } from '../gauge/types';
|
||||
import { SelectableValue } from '@grafana/data';
|
||||
|
||||
export interface BarGaugeOptions extends SingleStatBaseOptions {
|
||||
displayMode: 'basic' | 'lcd' | 'gradient';
|
||||
}
|
||||
|
||||
export const displayModes: Array<SelectOptionItem<string>> = [
|
||||
export const displayModes: Array<SelectableValue<string>> = [
|
||||
{ value: 'gradient', label: 'Gradient' },
|
||||
{ value: 'lcd', label: 'Retro LCD' },
|
||||
{ value: 'basic', label: 'Basic' },
|
||||
];
|
||||
|
||||
export const orientationOptions: Array<SelectOptionItem<VizOrientation>> = [
|
||||
export const orientationOptions: Array<SelectableValue<VizOrientation>> = [
|
||||
{ value: VizOrientation.Horizontal, label: 'Horizontal' },
|
||||
{ value: VizOrientation.Vertical, label: 'Vertical' },
|
||||
];
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { Field, getFieldReducers } from '@grafana/data';
|
||||
import { PanelModel } from '@grafana/ui';
|
||||
import { Field, fieldReducers } from '@grafana/data';
|
||||
import { PanelModel, FieldDisplayOptions } from '@grafana/ui';
|
||||
import { GaugeOptions } from './types';
|
||||
import {
|
||||
sharedSingleStatMigrationCheck,
|
||||
migrateOldThresholds,
|
||||
} from '@grafana/ui/src/components/SingleStatShared/SingleStatBaseOptions';
|
||||
import { FieldDisplayOptions } from '@grafana/ui/src/utils/fieldDisplay';
|
||||
|
||||
export const gaugePanelMigrationCheck = (panel: PanelModel<GaugeOptions>): Partial<GaugeOptions> => {
|
||||
if (!panel.options) {
|
||||
@@ -33,7 +32,7 @@ export const gaugePanelMigrationCheck = (panel: PanelModel<GaugeOptions>): Parti
|
||||
|
||||
// Make sure the stats have a valid name
|
||||
if (valueOptions.stat) {
|
||||
fieldOptions.calcs = getFieldReducers([valueOptions.stat]).map(s => s.id);
|
||||
fieldOptions.calcs = [fieldReducers.get(valueOptions.stat).id];
|
||||
}
|
||||
field.min = old.minValue;
|
||||
field.max = old.maxValue;
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
import React, { PureComponent } from 'react';
|
||||
|
||||
// Components
|
||||
import { FormLabel, Select, PanelOptionsGroup, SelectOptionItem } from '@grafana/ui';
|
||||
import { FormLabel, Select, PanelOptionsGroup } from '@grafana/ui';
|
||||
|
||||
// Types
|
||||
import { SingleStatOptions } from './types';
|
||||
import { SelectableValue } from '@grafana/data';
|
||||
|
||||
const labelWidth = 6;
|
||||
|
||||
@@ -20,13 +21,13 @@ const fontSizeOptions = percents.map(v => {
|
||||
});
|
||||
|
||||
export class FontSizeEditor extends PureComponent<Props> {
|
||||
setPrefixFontSize = (v: SelectOptionItem<string>) =>
|
||||
setPrefixFontSize = (v: SelectableValue<string>) =>
|
||||
this.props.onChange({ ...this.props.options, prefixFontSize: v.value });
|
||||
|
||||
setValueFontSize = (v: SelectOptionItem<string>) =>
|
||||
setValueFontSize = (v: SelectableValue<string>) =>
|
||||
this.props.onChange({ ...this.props.options, valueFontSize: v.value });
|
||||
|
||||
setPostfixFontSize = (v: SelectOptionItem<string>) =>
|
||||
setPostfixFontSize = (v: SelectableValue<string>) =>
|
||||
this.props.onChange({ ...this.props.options, postfixFontSize: v.value });
|
||||
|
||||
render() {
|
||||
|
||||
@@ -2,19 +2,20 @@
|
||||
import React, { PureComponent, ChangeEvent } from 'react';
|
||||
|
||||
// Components
|
||||
import { PanelEditorProps, PanelOptionsGroup, Select, SelectOptionItem } from '@grafana/ui';
|
||||
import { PanelEditorProps, PanelOptionsGroup, Select } from '@grafana/ui';
|
||||
import { SelectableValue } from '@grafana/data';
|
||||
|
||||
// Types
|
||||
import { TextOptions, TextMode } from './types';
|
||||
|
||||
export class TextPanelEditor extends PureComponent<PanelEditorProps<TextOptions>> {
|
||||
modes: Array<SelectOptionItem<TextMode>> = [
|
||||
modes: Array<SelectableValue<TextMode>> = [
|
||||
{ value: 'markdown', label: 'Markdown' },
|
||||
{ value: 'text', label: 'Text' },
|
||||
{ value: 'html', label: 'HTML' },
|
||||
];
|
||||
|
||||
onModeChange = (item: SelectOptionItem<TextMode>) =>
|
||||
onModeChange = (item: SelectableValue<TextMode>) =>
|
||||
this.props.onOptionsChange({ ...this.props.options, mode: item.value });
|
||||
|
||||
onContentChange = (evt: ChangeEvent<HTMLTextAreaElement>) => {
|
||||
|
||||
Reference in New Issue
Block a user