Plugins: Adds back getMappedValue to @grafana/data (#34746)

* Plugins: Adds back getMappedValue to @grafana/data

* Chore: fixes doc errors

* Tests: fixes snapshot

* Tests: dummy change to restart Drone

* Tests: tries to fix snapshot
This commit is contained in:
Hugo Häggmark
2021-05-27 09:29:22 +02:00
committed by GitHub
parent 49126bebaa
commit 3a68409e5d
5 changed files with 225 additions and 3120 deletions

View File

@ -1,20 +1,20 @@
import { cloneDeep, isNumber, omit } from 'lodash';
import {
fieldReducers,
Threshold,
sortThresholds,
convertOldAngularValueMappings,
FieldColorModeId,
FieldConfig,
ReducerID,
ValueMapping,
MappingType,
VizOrientation,
fieldReducers,
PanelModel,
ReduceDataOptions,
ThresholdsMode,
ReducerID,
sortThresholds,
Threshold,
ThresholdsConfig,
ThresholdsMode,
validateFieldConfig,
FieldColorModeId,
ValueMapping,
VizOrientation,
} from '@grafana/data';
import { OptionsWithTextFormatting } from '../../options';
@ -325,41 +325,9 @@ export function migrateOldThresholds(thresholds?: any[]): Threshold[] | undefine
}
/**
* @deprecated use convertOldAngularValueMappings instead
* Convert the angular single stat mapping to new react style
*/
export function convertOldAngularValueMapping(panel: any): ValueMapping[] {
const mappings: ValueMapping[] = [];
// Guess the right type based on options
let mappingType = panel.mappingType;
if (!panel.mappingType) {
if (panel.valueMaps && panel.valueMaps.length) {
mappingType = 1;
} else if (panel.rangeMaps && panel.rangeMaps.length) {
mappingType = 2;
}
}
// check value to text mappings if its enabled
if (mappingType === 1) {
for (let i = 0; i < panel.valueMaps.length; i++) {
const map = panel.valueMaps[i];
mappings.push({
...map,
id: i, // used for order
type: MappingType.ValueToText,
});
}
} else if (mappingType === 2) {
for (let i = 0; i < panel.rangeMaps.length; i++) {
const map = panel.rangeMaps[i];
mappings.push({
...map,
id: i, // used for order
type: MappingType.RangeToText,
});
}
}
return mappings;
return convertOldAngularValueMappings(panel);
}