2019-03-14 13:20:24 -07:00
|
|
|
// Libraries
|
|
|
|
|
import React, { PureComponent } from 'react';
|
2019-10-04 12:01:42 +02:00
|
|
|
|
2019-03-14 13:20:24 -07:00
|
|
|
import {
|
|
|
|
|
ThresholdsEditor,
|
|
|
|
|
PanelOptionsGrid,
|
|
|
|
|
ValueMappingsEditor,
|
2019-05-04 01:08:48 -07:00
|
|
|
FieldDisplayEditor,
|
|
|
|
|
FieldPropertiesEditor,
|
2019-05-08 17:25:41 +02:00
|
|
|
PanelOptionsGroup,
|
2019-08-27 23:50:43 -07:00
|
|
|
DataLinksEditor,
|
2019-10-04 12:01:42 +02:00
|
|
|
FormLabel,
|
|
|
|
|
Select,
|
2019-03-14 13:20:24 -07:00
|
|
|
} from '@grafana/ui';
|
2019-10-04 12:01:42 +02:00
|
|
|
|
2019-12-28 17:32:58 -08:00
|
|
|
import {
|
|
|
|
|
ThresholdsConfig,
|
|
|
|
|
ValueMapping,
|
|
|
|
|
FieldConfig,
|
|
|
|
|
DataLink,
|
|
|
|
|
PanelEditorProps,
|
|
|
|
|
FieldDisplayOptions,
|
|
|
|
|
} from '@grafana/data';
|
2019-03-14 13:20:24 -07:00
|
|
|
|
2019-12-01 17:02:44 +01:00
|
|
|
import { StatPanelOptions, colorModes, graphModes, justifyModes } from './types';
|
|
|
|
|
import { orientationOptions } from '../gauge/types';
|
|
|
|
|
|
2019-08-27 23:50:43 -07:00
|
|
|
import {
|
|
|
|
|
getDataLinksVariableSuggestions,
|
|
|
|
|
getCalculationValueDataLinksVariableSuggestions,
|
|
|
|
|
} from 'app/features/panel/panellinks/link_srv';
|
2019-12-28 17:32:58 -08:00
|
|
|
import { config } from 'app/core/config';
|
2019-03-14 13:20:24 -07:00
|
|
|
|
2019-11-25 16:13:14 -08:00
|
|
|
export class StatPanelEditor extends PureComponent<PanelEditorProps<StatPanelOptions>> {
|
2019-12-28 17:32:58 -08:00
|
|
|
onThresholdsChanged = (thresholds: ThresholdsConfig) => {
|
2019-07-12 08:32:39 -07:00
|
|
|
const current = this.props.options.fieldOptions.defaults;
|
|
|
|
|
this.onDefaultsChange({
|
|
|
|
|
...current,
|
2019-03-14 13:20:24 -07:00
|
|
|
thresholds,
|
|
|
|
|
});
|
2019-07-12 08:32:39 -07:00
|
|
|
};
|
2019-03-14 13:20:24 -07:00
|
|
|
|
2019-07-12 08:32:39 -07:00
|
|
|
onValueMappingsChanged = (mappings: ValueMapping[]) => {
|
|
|
|
|
const current = this.props.options.fieldOptions.defaults;
|
|
|
|
|
this.onDefaultsChange({
|
|
|
|
|
...current,
|
2019-05-04 01:08:48 -07:00
|
|
|
mappings,
|
2019-03-14 13:20:24 -07:00
|
|
|
});
|
2019-07-12 08:32:39 -07:00
|
|
|
};
|
2019-03-14 13:20:24 -07:00
|
|
|
|
2019-05-04 01:08:48 -07:00
|
|
|
onDisplayOptionsChanged = (fieldOptions: FieldDisplayOptions) =>
|
2019-03-14 13:20:24 -07:00
|
|
|
this.props.onOptionsChange({
|
|
|
|
|
...this.props.options,
|
2019-05-04 01:08:48 -07:00
|
|
|
fieldOptions,
|
2019-03-14 13:20:24 -07:00
|
|
|
});
|
|
|
|
|
|
2019-12-01 17:02:44 +01:00
|
|
|
onColorModeChanged = ({ value }: any) => this.props.onOptionsChange({ ...this.props.options, colorMode: value });
|
|
|
|
|
onGraphModeChanged = ({ value }: any) => this.props.onOptionsChange({ ...this.props.options, graphMode: value });
|
|
|
|
|
onJustifyModeChanged = ({ value }: any) => this.props.onOptionsChange({ ...this.props.options, justifyMode: value });
|
|
|
|
|
onOrientationChange = ({ value }: any) => this.props.onOptionsChange({ ...this.props.options, orientation: value });
|
2019-10-04 12:01:42 +02:00
|
|
|
|
2019-08-15 09:18:51 -07:00
|
|
|
onDefaultsChange = (field: FieldConfig) => {
|
2019-05-04 01:08:48 -07:00
|
|
|
this.onDisplayOptionsChanged({
|
|
|
|
|
...this.props.options.fieldOptions,
|
2019-08-21 13:24:21 -07:00
|
|
|
defaults: field,
|
2019-05-04 01:08:48 -07:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2019-08-27 23:50:43 -07:00
|
|
|
onDataLinksChanged = (links: DataLink[]) => {
|
|
|
|
|
this.onDefaultsChange({
|
|
|
|
|
...this.props.options.fieldOptions.defaults,
|
|
|
|
|
links,
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2019-03-14 13:20:24 -07:00
|
|
|
render() {
|
|
|
|
|
const { options } = this.props;
|
2019-05-04 01:08:48 -07:00
|
|
|
const { fieldOptions } = options;
|
2019-07-12 08:32:39 -07:00
|
|
|
const { defaults } = fieldOptions;
|
2019-08-27 23:50:43 -07:00
|
|
|
const suggestions = fieldOptions.values
|
2019-09-13 16:38:21 +02:00
|
|
|
? getDataLinksVariableSuggestions(this.props.data.series)
|
|
|
|
|
: getCalculationValueDataLinksVariableSuggestions(this.props.data.series);
|
2019-03-14 13:20:24 -07:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<PanelOptionsGrid>
|
2019-05-08 17:25:41 +02:00
|
|
|
<PanelOptionsGroup title="Display">
|
2019-10-04 12:01:42 +02:00
|
|
|
<FieldDisplayEditor onChange={this.onDisplayOptionsChanged} value={fieldOptions} labelWidth={8} />
|
|
|
|
|
<div className="form-field">
|
2019-12-01 17:02:44 +01:00
|
|
|
<FormLabel width={8}>Orientation</FormLabel>
|
|
|
|
|
<Select
|
|
|
|
|
width={12}
|
|
|
|
|
options={orientationOptions}
|
|
|
|
|
defaultValue={orientationOptions[0]}
|
|
|
|
|
onChange={this.onOrientationChange}
|
|
|
|
|
value={orientationOptions.find(item => item.value === options.orientation)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="form-field">
|
|
|
|
|
<FormLabel width={8}>Color</FormLabel>
|
|
|
|
|
<Select
|
|
|
|
|
width={12}
|
|
|
|
|
options={colorModes}
|
|
|
|
|
defaultValue={colorModes[0]}
|
|
|
|
|
onChange={this.onColorModeChanged}
|
|
|
|
|
value={colorModes.find(item => item.value === options.colorMode)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="form-field">
|
|
|
|
|
<FormLabel width={8}>Graph</FormLabel>
|
|
|
|
|
<Select
|
|
|
|
|
width={12}
|
|
|
|
|
options={graphModes}
|
|
|
|
|
defaultValue={graphModes[0]}
|
|
|
|
|
onChange={this.onGraphModeChanged}
|
|
|
|
|
value={graphModes.find(item => item.value === options.graphMode)}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="form-field">
|
|
|
|
|
<FormLabel width={8}>Justify</FormLabel>
|
2019-10-04 12:01:42 +02:00
|
|
|
<Select
|
|
|
|
|
width={12}
|
2019-12-01 17:02:44 +01:00
|
|
|
options={justifyModes}
|
|
|
|
|
defaultValue={justifyModes[0]}
|
|
|
|
|
onChange={this.onJustifyModeChanged}
|
|
|
|
|
value={justifyModes.find(item => item.value === options.justifyMode)}
|
2019-10-04 12:01:42 +02:00
|
|
|
/>
|
|
|
|
|
</div>
|
2019-05-08 17:25:41 +02:00
|
|
|
</PanelOptionsGroup>
|
2019-05-04 01:08:48 -07:00
|
|
|
|
2019-11-25 13:26:18 -08:00
|
|
|
<PanelOptionsGroup title="Field">
|
|
|
|
|
<FieldPropertiesEditor
|
|
|
|
|
showMinMax={true}
|
|
|
|
|
onChange={this.onDefaultsChange}
|
|
|
|
|
value={defaults}
|
|
|
|
|
showTitle={true}
|
|
|
|
|
/>
|
2019-05-08 17:25:41 +02:00
|
|
|
</PanelOptionsGroup>
|
2019-05-04 01:08:48 -07:00
|
|
|
|
2019-12-28 17:32:58 -08:00
|
|
|
<ThresholdsEditor
|
|
|
|
|
onChange={this.onThresholdsChanged}
|
|
|
|
|
thresholds={defaults.thresholds}
|
|
|
|
|
showAlphaUI={config.featureToggles.newEdit}
|
|
|
|
|
/>
|
2019-03-14 13:20:24 -07:00
|
|
|
</PanelOptionsGrid>
|
|
|
|
|
|
2019-07-12 08:32:39 -07:00
|
|
|
<ValueMappingsEditor onChange={this.onValueMappingsChanged} valueMappings={defaults.mappings} />
|
2019-08-27 23:50:43 -07:00
|
|
|
|
|
|
|
|
<PanelOptionsGroup title="Data links">
|
|
|
|
|
<DataLinksEditor
|
|
|
|
|
value={defaults.links}
|
|
|
|
|
onChange={this.onDataLinksChanged}
|
|
|
|
|
suggestions={suggestions}
|
|
|
|
|
maxLinks={10}
|
|
|
|
|
/>
|
|
|
|
|
</PanelOptionsGroup>
|
2019-03-14 13:20:24 -07:00
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|