Value Mappings: remove unused operator property from interface (#25989)

pull/25853/head
Ryan McKinley 5 years ago committed by GitHub
parent c9751707c5
commit 73e82af4df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      packages/grafana-data/src/field/displayProcessor.test.ts
  2. 5
      packages/grafana-data/src/types/valueMapping.ts
  3. 32
      packages/grafana-data/src/utils/valueMappings.test.ts
  4. 22
      packages/grafana-ui/src/components/ValueMappingsEditor/ValueMappingsEditor.test.tsx
  5. 1
      packages/grafana-ui/src/components/ValueMappingsEditor/ValueMappingsEditor.tsx
  6. 1
      packages/grafana-ui/src/utils/standardEditors.tsx

@ -152,8 +152,8 @@ describe('Format value', () => {
it('should return formatted value if there are no matching value mappings', () => { it('should return formatted value if there are no matching value mappings', () => {
const valueMappings: ValueMapping[] = [ const valueMappings: ValueMapping[] = [
{ id: 0, operator: '', text: 'elva', type: MappingType.ValueToText, value: '11' }, { id: 0, text: 'elva', type: MappingType.ValueToText, value: '11' },
{ id: 1, operator: '', text: '1-9', type: MappingType.RangeToText, from: '1', to: '9' }, { id: 1, text: '1-9', type: MappingType.RangeToText, from: '1', to: '9' },
]; ];
const value = '10'; const value = '10';
const instance = getDisplayProcessorFromConfig({ decimals: 1, mappings: valueMappings }); const instance = getDisplayProcessorFromConfig({ decimals: 1, mappings: valueMappings });
@ -186,8 +186,8 @@ describe('Format value', () => {
it('should return mapped value if there are matching value mappings', () => { it('should return mapped value if there are matching value mappings', () => {
const valueMappings: ValueMapping[] = [ const valueMappings: ValueMapping[] = [
{ id: 0, operator: '', text: '1-20', type: MappingType.RangeToText, from: '1', to: '20' }, { id: 0, text: '1-20', type: MappingType.RangeToText, from: '1', to: '20' },
{ id: 1, operator: '', text: 'elva', type: MappingType.ValueToText, value: '11' }, { id: 1, text: 'elva', type: MappingType.ValueToText, value: '11' },
]; ];
const value = '11'; const value = '11';
const instance = getDisplayProcessorFromConfig({ decimals: 1, mappings: valueMappings }); const instance = getDisplayProcessorFromConfig({ decimals: 1, mappings: valueMappings });
@ -196,9 +196,7 @@ describe('Format value', () => {
}); });
it('should return mapped value and leave numeric value in tact if value mapping maps to empty string', () => { it('should return mapped value and leave numeric value in tact if value mapping maps to empty string', () => {
const valueMappings: ValueMapping[] = [ const valueMappings: ValueMapping[] = [{ id: 1, text: '', type: MappingType.ValueToText, value: '1' }];
{ id: 1, operator: '', text: '', type: MappingType.ValueToText, value: '1' },
];
const value = '1'; const value = '1';
const instance = getDisplayProcessorFromConfig({ decimals: 1, mappings: valueMappings }); const instance = getDisplayProcessorFromConfig({ decimals: 1, mappings: valueMappings });

@ -4,9 +4,8 @@ export enum MappingType {
} }
interface BaseMap { interface BaseMap {
id: number; id: number; // this could/should just be the array index
operator: string; text: string; // the final display value
text: string;
type: MappingType; type: MappingType;
} }

@ -11,8 +11,8 @@ describe('Format value with value mappings', () => {
it('should return undefined with no matching valuemappings', () => { it('should return undefined with no matching valuemappings', () => {
const valueMappings: ValueMapping[] = [ const valueMappings: ValueMapping[] = [
{ id: 0, operator: '', text: 'elva', type: MappingType.ValueToText, value: '11' }, { id: 0, text: 'elva', type: MappingType.ValueToText, value: '11' },
{ id: 1, operator: '', text: '1-9', type: MappingType.RangeToText, from: '1', to: '9' }, { id: 1, text: '1-9', type: MappingType.RangeToText, from: '1', to: '9' },
]; ];
const value = '10'; const value = '10';
@ -21,8 +21,8 @@ describe('Format value with value mappings', () => {
it('should return first matching mapping with lowest id', () => { it('should return first matching mapping with lowest id', () => {
const valueMappings: ValueMapping[] = [ const valueMappings: ValueMapping[] = [
{ id: 0, operator: '', text: '1-20', type: MappingType.RangeToText, from: '1', to: '20' }, { id: 0, text: '1-20', type: MappingType.RangeToText, from: '1', to: '20' },
{ id: 1, operator: '', text: 'tio', type: MappingType.ValueToText, value: '10' }, { id: 1, text: 'tio', type: MappingType.ValueToText, value: '10' },
]; ];
const value = '10'; const value = '10';
@ -31,8 +31,8 @@ describe('Format value with value mappings', () => {
it('should return if value is null and value to text mapping value is null', () => { it('should return if value is null and value to text mapping value is null', () => {
const valueMappings: ValueMapping[] = [ const valueMappings: ValueMapping[] = [
{ id: 0, operator: '', text: '1-20', type: MappingType.RangeToText, from: '1', to: '20' }, { id: 0, text: '1-20', type: MappingType.RangeToText, from: '1', to: '20' },
{ id: 1, operator: '', text: '<NULL>', type: MappingType.ValueToText, value: 'null' }, { id: 1, text: '<NULL>', type: MappingType.ValueToText, value: 'null' },
]; ];
const value = null; const value = null;
@ -41,8 +41,8 @@ describe('Format value with value mappings', () => {
it('should return if value is null and range to text mapping from and to is null', () => { it('should return if value is null and range to text mapping from and to is null', () => {
const valueMappings: ValueMapping[] = [ const valueMappings: ValueMapping[] = [
{ id: 0, operator: '', text: '<NULL>', type: MappingType.RangeToText, from: 'null', to: 'null' }, { id: 0, text: '<NULL>', type: MappingType.RangeToText, from: 'null', to: 'null' },
{ id: 1, operator: '', text: 'elva', type: MappingType.ValueToText, value: '11' }, { id: 1, text: 'elva', type: MappingType.ValueToText, value: '11' },
]; ];
const value = null; const value = null;
@ -51,8 +51,8 @@ describe('Format value with value mappings', () => {
it('should return rangeToText mapping where value equals to', () => { it('should return rangeToText mapping where value equals to', () => {
const valueMappings: ValueMapping[] = [ const valueMappings: ValueMapping[] = [
{ id: 0, operator: '', text: '1-10', type: MappingType.RangeToText, from: '1', to: '10' }, { id: 0, text: '1-10', type: MappingType.RangeToText, from: '1', to: '10' },
{ id: 1, operator: '', text: 'elva', type: MappingType.ValueToText, value: '11' }, { id: 1, text: 'elva', type: MappingType.ValueToText, value: '11' },
]; ];
const value = '10'; const value = '10';
@ -61,8 +61,8 @@ describe('Format value with value mappings', () => {
it('should return rangeToText mapping where value equals from', () => { it('should return rangeToText mapping where value equals from', () => {
const valueMappings: ValueMapping[] = [ const valueMappings: ValueMapping[] = [
{ id: 0, operator: '', text: '10-20', type: MappingType.RangeToText, from: '10', to: '20' }, { id: 0, text: '10-20', type: MappingType.RangeToText, from: '10', to: '20' },
{ id: 1, operator: '', text: 'elva', type: MappingType.ValueToText, value: '11' }, { id: 1, text: 'elva', type: MappingType.ValueToText, value: '11' },
]; ];
const value = '10'; const value = '10';
@ -71,8 +71,8 @@ describe('Format value with value mappings', () => {
it('should return rangeToText mapping where value is between from and to', () => { it('should return rangeToText mapping where value is between from and to', () => {
const valueMappings: ValueMapping[] = [ const valueMappings: ValueMapping[] = [
{ id: 0, operator: '', text: '1-20', type: MappingType.RangeToText, from: '1', to: '20' }, { id: 0, text: '1-20', type: MappingType.RangeToText, from: '1', to: '20' },
{ id: 1, operator: '', text: 'elva', type: MappingType.ValueToText, value: '11' }, { id: 1, text: 'elva', type: MappingType.ValueToText, value: '11' },
]; ];
const value = '10'; const value = '10';
@ -81,8 +81,8 @@ describe('Format value with value mappings', () => {
it('should map value text to mapping', () => { it('should map value text to mapping', () => {
const valueMappings: ValueMapping[] = [ const valueMappings: ValueMapping[] = [
{ id: 0, operator: '', text: '1-20', type: MappingType.RangeToText, from: '1', to: '20' }, { id: 0, text: '1-20', type: MappingType.RangeToText, from: '1', to: '20' },
{ id: 1, operator: '', text: 'ELVA', type: MappingType.ValueToText, value: 'elva' }, { id: 1, text: 'ELVA', type: MappingType.ValueToText, value: 'elva' },
]; ];
const value = 'elva'; const value = 'elva';

@ -12,8 +12,8 @@ const setup = (spy?: any, propOverrides?: object) => {
} }
}, },
valueMappings: [ valueMappings: [
{ id: 1, operator: '', type: MappingType.ValueToText, value: '20', text: 'Ok' }, { id: 1, type: MappingType.ValueToText, value: '20', text: 'Ok' },
{ id: 2, operator: '', type: MappingType.RangeToText, from: '21', to: '30', text: 'Meh' }, { id: 2, type: MappingType.RangeToText, from: '21', to: '30', text: 'Meh' },
], ],
}; };
@ -35,9 +35,7 @@ describe('On remove mapping', () => {
const remove = wrapper.find('button[aria-label="ValueMappingsEditor remove button"]'); const remove = wrapper.find('button[aria-label="ValueMappingsEditor remove button"]');
remove.at(0).simulate('click'); remove.at(0).simulate('click');
expect(onChangeSpy).toBeCalledWith([ expect(onChangeSpy).toBeCalledWith([{ id: 2, type: MappingType.RangeToText, from: '21', to: '30', text: 'Meh' }]);
{ id: 2, operator: '', type: MappingType.RangeToText, from: '21', to: '30', text: 'Meh' },
]);
}); });
it('should remove mapping at index 1', () => { it('should remove mapping at index 1', () => {
@ -47,9 +45,7 @@ describe('On remove mapping', () => {
const remove = wrapper.find('button[aria-label="ValueMappingsEditor remove button"]'); const remove = wrapper.find('button[aria-label="ValueMappingsEditor remove button"]');
remove.at(1).simulate('click'); remove.at(1).simulate('click');
expect(onChangeSpy).toBeCalledWith([ expect(onChangeSpy).toBeCalledWith([{ id: 1, type: MappingType.ValueToText, value: '20', text: 'Ok' }]);
{ id: 1, operator: '', type: MappingType.ValueToText, value: '20', text: 'Ok' },
]);
}); });
}); });
@ -62,9 +58,9 @@ describe('Next id to add', () => {
add.at(0).simulate('click'); add.at(0).simulate('click');
expect(onChangeSpy).toBeCalledWith([ expect(onChangeSpy).toBeCalledWith([
{ id: 1, operator: '', type: MappingType.ValueToText, value: '20', text: 'Ok' }, { id: 1, type: MappingType.ValueToText, value: '20', text: 'Ok' },
{ id: 2, operator: '', type: MappingType.RangeToText, from: '21', to: '30', text: 'Meh' }, { id: 2, type: MappingType.RangeToText, from: '21', to: '30', text: 'Meh' },
{ id: 3, operator: '', type: MappingType.ValueToText, from: '', to: '', text: '' }, { id: 3, type: MappingType.ValueToText, from: '', to: '', text: '' },
]); ]);
}); });
@ -73,8 +69,6 @@ describe('Next id to add', () => {
const wrapper = setup(onChangeSpy, { valueMappings: [] }); const wrapper = setup(onChangeSpy, { valueMappings: [] });
const add = wrapper.find('*[aria-label="ValueMappingsEditor add mapping button"]'); const add = wrapper.find('*[aria-label="ValueMappingsEditor add mapping button"]');
add.at(0).simulate('click'); add.at(0).simulate('click');
expect(onChangeSpy).toBeCalledWith([ expect(onChangeSpy).toBeCalledWith([{ id: 0, type: MappingType.ValueToText, from: '', to: '', text: '' }]);
{ id: 0, operator: '', type: MappingType.ValueToText, from: '', to: '', text: '' },
]);
}); });
}); });

@ -15,7 +15,6 @@ export const ValueMappingsEditor: React.FC<Props> = ({ valueMappings, onChange,
type: MappingType.ValueToText, type: MappingType.ValueToText,
from: '', from: '',
to: '', to: '',
operator: '',
text: '', text: '',
}; };
const id = update && update.length > 0 ? Math.max(...update.map(v => v.id)) + 1 : 0; const id = update && update.length > 0 ? Math.max(...update.map(v => v.id)) + 1 : 0;

@ -155,6 +155,7 @@ export const getStandardFieldConfigs = () => {
id: 'mappings', id: 'mappings',
path: 'mappings', path: 'mappings',
name: 'Value mappings', name: 'Value mappings',
description: 'Modify the display text based on input value',
editor: standardEditorsRegistry.get('mappings').editor as any, editor: standardEditorsRegistry.get('mappings').editor as any,
override: standardEditorsRegistry.get('mappings').editor as any, override: standardEditorsRegistry.get('mappings').editor as any,

Loading…
Cancel
Save