mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* datalink on field * add dataFrame to view * Use scoped variables to pass series name and value time to data links interpolation * Use scoped variables to pass series name and value time to data links interpolation * Enable value specific variable suggestions when Gauge is displaying values * Fix prettier * Add basic context menu with data links to GaugePanel * Fix incorrect import in grafana/ui * Add custom cursor indicating datalinks available via context menu (in Gauge only now) * Add data links to SingleStat2 * Minor refactor * Retrieve data links in a lazy way * Update test to respect links retrieval being lazy * delay link creation * cleanup * Add origin to LinkModel and introduce field & panel links suppliers * Add value time and series name field link supplier * Remove links prop from visualization and implement common UI for data links context menu * Update snapshot * Rename className prop to clickTargetClassName * Simplify condition * Updated drilldown dashboard and minor changes * Use class name an onClick handler on the top level dom element in visualization * Enable series name interpolation when presented value is a calculation
122 lines
3.8 KiB
TypeScript
122 lines
3.8 KiB
TypeScript
// Libraries
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import {
|
|
ThresholdsEditor,
|
|
ValueMappingsEditor,
|
|
PanelOptionsGrid,
|
|
FieldDisplayEditor,
|
|
FieldDisplayOptions,
|
|
FieldPropertiesEditor,
|
|
PanelOptionsGroup,
|
|
FormLabel,
|
|
PanelEditorProps,
|
|
Select,
|
|
DataLinksEditor,
|
|
} from '@grafana/ui';
|
|
import { FieldConfig, DataLink } from '@grafana/data';
|
|
|
|
import { Threshold, ValueMapping } from '@grafana/data';
|
|
import { BarGaugeOptions, orientationOptions, displayModes } from './types';
|
|
import {
|
|
getDataLinksVariableSuggestions,
|
|
getCalculationValueDataLinksVariableSuggestions,
|
|
} from 'app/features/panel/panellinks/link_srv';
|
|
|
|
export class BarGaugePanelEditor extends PureComponent<PanelEditorProps<BarGaugeOptions>> {
|
|
onThresholdsChanged = (thresholds: Threshold[]) => {
|
|
const current = this.props.options.fieldOptions.defaults;
|
|
this.onDefaultsChange({
|
|
...current,
|
|
thresholds,
|
|
});
|
|
};
|
|
|
|
onValueMappingsChanged = (mappings: ValueMapping[]) => {
|
|
const current = this.props.options.fieldOptions.defaults;
|
|
this.onDefaultsChange({
|
|
...current,
|
|
mappings,
|
|
});
|
|
};
|
|
|
|
onDisplayOptionsChanged = (fieldOptions: FieldDisplayOptions) =>
|
|
this.props.onOptionsChange({
|
|
...this.props.options,
|
|
fieldOptions,
|
|
});
|
|
|
|
onDefaultsChange = (field: FieldConfig) => {
|
|
this.onDisplayOptionsChanged({
|
|
...this.props.options.fieldOptions,
|
|
defaults: field,
|
|
});
|
|
};
|
|
|
|
onOrientationChange = ({ value }: any) => this.props.onOptionsChange({ ...this.props.options, orientation: value });
|
|
onDisplayModeChange = ({ value }: any) => this.props.onOptionsChange({ ...this.props.options, displayMode: value });
|
|
|
|
onDataLinksChanged = (links: DataLink[]) => {
|
|
this.onDefaultsChange({
|
|
...this.props.options.fieldOptions.defaults,
|
|
links,
|
|
});
|
|
};
|
|
render() {
|
|
const { options } = this.props;
|
|
const { fieldOptions } = options;
|
|
const { defaults } = fieldOptions;
|
|
|
|
const suggestions = fieldOptions.values
|
|
? getDataLinksVariableSuggestions()
|
|
: getCalculationValueDataLinksVariableSuggestions();
|
|
const labelWidth = 6;
|
|
|
|
return (
|
|
<>
|
|
<PanelOptionsGrid>
|
|
<PanelOptionsGroup title="Display">
|
|
<FieldDisplayEditor onChange={this.onDisplayOptionsChanged} value={fieldOptions} labelWidth={labelWidth} />
|
|
<div className="form-field">
|
|
<FormLabel width={labelWidth}>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={labelWidth}>Mode</FormLabel>
|
|
<Select
|
|
width={12}
|
|
options={displayModes}
|
|
defaultValue={displayModes[0]}
|
|
onChange={this.onDisplayModeChange}
|
|
value={displayModes.find(item => item.value === options.displayMode)}
|
|
/>
|
|
</div>
|
|
</PanelOptionsGroup>
|
|
<PanelOptionsGroup title="Field">
|
|
<FieldPropertiesEditor showMinMax={true} onChange={this.onDefaultsChange} value={defaults} />
|
|
</PanelOptionsGroup>
|
|
|
|
<ThresholdsEditor onChange={this.onThresholdsChanged} thresholds={defaults.thresholds} />
|
|
</PanelOptionsGrid>
|
|
|
|
<ValueMappingsEditor onChange={this.onValueMappingsChanged} valueMappings={defaults.mappings} />
|
|
|
|
<PanelOptionsGroup title="Data links">
|
|
<DataLinksEditor
|
|
value={defaults.links}
|
|
onChange={this.onDataLinksChanged}
|
|
suggestions={suggestions}
|
|
maxLinks={10}
|
|
/>
|
|
</PanelOptionsGroup>
|
|
</>
|
|
);
|
|
}
|
|
}
|