mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Apply field overrides in PanelChrome * Move applyFieldOverrides to panel query runner * Review updates * Make sure overrides are applied back on souce panel when exiting the new edit mode * TS ignores in est * Make field display work in viz repeater * Review updates * Review and test updates * Change the way overrides and trransformations are retrieved in PQR * Add fieldConfig property to PanelModel * Dashboard migration v1 * Use field config when exiting new panel edit mode * Gauge - use fieldConfig from panel model * FieldDisplayOptions - don's extend FieldConfigSource * Fix fieldDisplay ts * StatPanel updated * Stat panel defaults applied * Table2 panel options update * React graph updates * BarGauge updated * PieChart, Gauge, BarGauge and Stat updates * PieChart - remove field config defaults from options * FieldDisplayEditor - remove unused methos * PanelModel - remove debugger * Remove fieldConfig from field options when migrating dashboard * Update data links migrations * Update fieldDisaplay tests to respect new fieldConfig * Update dashboard schema version in snapshots * Fix BarGaugePanel test * Rebase fixes * Add onFieldConfigChange to PanelProps type * Update shared single stat migration * Pass PanelModel instead of options only for panel type change handler [breaking] * Renames * Don't mutate panel options * Migrations update * Remove obsolete snap * Minor updates after review * Fix null checks * Temporarily (until we decide to switch to new pane edit) bring back old aditors * Temporarily rename ValueMappingEditor and MappingRow to Legacy* * Migrations update * Updae setFieldConfigDefaults API * Update the way field config defaults are applied * Use standard field config for gauge, bar gauge and stat panels * refactoring * Revert dashboard fieldOptions migrations as those are handled by single stat migrator * Fix ts in tests * Strict null fix and some minor fixes Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
164 lines
5.2 KiB
TypeScript
164 lines
5.2 KiB
TypeScript
// Libraries
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import {
|
|
PanelOptionsGrid,
|
|
FieldDisplayEditor,
|
|
PanelOptionsGroup,
|
|
FormLabel,
|
|
Select,
|
|
FieldPropertiesEditor,
|
|
ThresholdsEditor,
|
|
LegacyValueMappingsEditor,
|
|
DataLinksEditor,
|
|
} from '@grafana/ui';
|
|
|
|
import {
|
|
PanelEditorProps,
|
|
FieldDisplayOptions,
|
|
FieldConfig,
|
|
ValueMapping,
|
|
ThresholdsConfig,
|
|
DataLink,
|
|
} from '@grafana/data';
|
|
|
|
import { StatPanelOptions, colorModes, graphModes, justifyModes } from './types';
|
|
import { orientationOptions } from '../gauge/types';
|
|
import {
|
|
getCalculationValueDataLinksVariableSuggestions,
|
|
getDataLinksVariableSuggestions,
|
|
} from '../../../features/panel/panellinks/link_srv';
|
|
|
|
export class StatPanelEditor extends PureComponent<PanelEditorProps<StatPanelOptions>> {
|
|
onThresholdsChanged = (thresholds: ThresholdsConfig) => {
|
|
const current = this.props.fieldConfig;
|
|
this.props.onFieldConfigChange({
|
|
...current,
|
|
defaults: {
|
|
...current.defaults,
|
|
thresholds,
|
|
},
|
|
});
|
|
};
|
|
|
|
onValueMappingsChanged = (mappings: ValueMapping[]) => {
|
|
const current = this.props.fieldConfig;
|
|
this.props.onFieldConfigChange({
|
|
...current,
|
|
defaults: {
|
|
...current.defaults,
|
|
mappings,
|
|
},
|
|
});
|
|
};
|
|
|
|
onDisplayOptionsChanged = (fieldOptions: FieldDisplayOptions) =>
|
|
this.props.onOptionsChange({
|
|
...this.props.options,
|
|
fieldOptions,
|
|
});
|
|
|
|
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 });
|
|
|
|
onDefaultsChange = (field: FieldConfig) => {
|
|
this.props.onFieldConfigChange({
|
|
...this.props.fieldConfig,
|
|
defaults: field,
|
|
});
|
|
};
|
|
|
|
onDataLinksChanged = (links: DataLink[]) => {
|
|
const current = this.props.fieldConfig;
|
|
this.props.onFieldConfigChange({
|
|
...current,
|
|
defaults: {
|
|
...current.defaults,
|
|
links,
|
|
},
|
|
});
|
|
};
|
|
|
|
render() {
|
|
const { options, fieldConfig } = this.props;
|
|
const { fieldOptions } = options;
|
|
const { defaults } = fieldConfig;
|
|
|
|
const suggestions = fieldOptions.values
|
|
? getDataLinksVariableSuggestions(this.props.data.series)
|
|
: getCalculationValueDataLinksVariableSuggestions(this.props.data.series);
|
|
|
|
return (
|
|
<>
|
|
<PanelOptionsGrid>
|
|
<PanelOptionsGroup title="Display">
|
|
<FieldDisplayEditor onChange={this.onDisplayOptionsChanged} value={fieldOptions} labelWidth={8} />
|
|
<div className="form-field">
|
|
<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>
|
|
<Select
|
|
width={12}
|
|
options={justifyModes}
|
|
defaultValue={justifyModes[0]}
|
|
onChange={this.onJustifyModeChanged}
|
|
value={justifyModes.find(item => item.value === options.justifyMode)}
|
|
/>
|
|
</div>
|
|
</PanelOptionsGroup>
|
|
<PanelOptionsGroup title="Field">
|
|
<FieldPropertiesEditor
|
|
showMinMax={true}
|
|
onChange={this.onDefaultsChange}
|
|
value={defaults}
|
|
showTitle={true}
|
|
/>
|
|
</PanelOptionsGroup>
|
|
|
|
<ThresholdsEditor onChange={this.onThresholdsChanged} thresholds={defaults.thresholds} />
|
|
</PanelOptionsGrid>
|
|
<LegacyValueMappingsEditor onChange={this.onValueMappingsChanged} valueMappings={defaults.mappings} />
|
|
|
|
<PanelOptionsGroup title="Data links">
|
|
<DataLinksEditor
|
|
value={defaults.links}
|
|
onChange={this.onDataLinksChanged}
|
|
suggestions={suggestions}
|
|
maxLinks={10}
|
|
/>
|
|
</PanelOptionsGroup>
|
|
</>
|
|
);
|
|
}
|
|
}
|