From 73e82af4df77931acedcce5a73e6a2267826f1d2 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Wed, 1 Jul 2020 12:52:36 -0700 Subject: [PATCH] Value Mappings: remove unused operator property from interface (#25989) --- .../src/field/displayProcessor.test.ts | 12 +++---- .../grafana-data/src/types/valueMapping.ts | 5 ++- .../src/utils/valueMappings.test.ts | 32 +++++++++---------- .../ValueMappingsEditor.test.tsx | 22 +++++-------- .../ValueMappingsEditor.tsx | 1 - .../grafana-ui/src/utils/standardEditors.tsx | 1 + 6 files changed, 32 insertions(+), 41 deletions(-) diff --git a/packages/grafana-data/src/field/displayProcessor.test.ts b/packages/grafana-data/src/field/displayProcessor.test.ts index 5064bc52f1e..8136cc8c2f4 100644 --- a/packages/grafana-data/src/field/displayProcessor.test.ts +++ b/packages/grafana-data/src/field/displayProcessor.test.ts @@ -152,8 +152,8 @@ describe('Format value', () => { it('should return formatted value if there are no matching value mappings', () => { const valueMappings: ValueMapping[] = [ - { id: 0, operator: '', text: 'elva', type: MappingType.ValueToText, value: '11' }, - { id: 1, operator: '', text: '1-9', type: MappingType.RangeToText, from: '1', to: '9' }, + { id: 0, text: 'elva', type: MappingType.ValueToText, value: '11' }, + { id: 1, text: '1-9', type: MappingType.RangeToText, from: '1', to: '9' }, ]; const value = '10'; 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', () => { const valueMappings: ValueMapping[] = [ - { id: 0, operator: '', text: '1-20', type: MappingType.RangeToText, from: '1', to: '20' }, - { id: 1, operator: '', text: 'elva', type: MappingType.ValueToText, value: '11' }, + { id: 0, text: '1-20', type: MappingType.RangeToText, from: '1', to: '20' }, + { id: 1, text: 'elva', type: MappingType.ValueToText, value: '11' }, ]; const value = '11'; 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', () => { - const valueMappings: ValueMapping[] = [ - { id: 1, operator: '', text: '', type: MappingType.ValueToText, value: '1' }, - ]; + const valueMappings: ValueMapping[] = [{ id: 1, text: '', type: MappingType.ValueToText, value: '1' }]; const value = '1'; const instance = getDisplayProcessorFromConfig({ decimals: 1, mappings: valueMappings }); diff --git a/packages/grafana-data/src/types/valueMapping.ts b/packages/grafana-data/src/types/valueMapping.ts index 46b4e1377cf..3a2b61a0703 100644 --- a/packages/grafana-data/src/types/valueMapping.ts +++ b/packages/grafana-data/src/types/valueMapping.ts @@ -4,9 +4,8 @@ export enum MappingType { } interface BaseMap { - id: number; - operator: string; - text: string; + id: number; // this could/should just be the array index + text: string; // the final display value type: MappingType; } diff --git a/packages/grafana-data/src/utils/valueMappings.test.ts b/packages/grafana-data/src/utils/valueMappings.test.ts index f1f465ee849..eee48dbe5e3 100644 --- a/packages/grafana-data/src/utils/valueMappings.test.ts +++ b/packages/grafana-data/src/utils/valueMappings.test.ts @@ -11,8 +11,8 @@ describe('Format value with value mappings', () => { it('should return undefined with no matching valuemappings', () => { const valueMappings: ValueMapping[] = [ - { id: 0, operator: '', text: 'elva', type: MappingType.ValueToText, value: '11' }, - { id: 1, operator: '', text: '1-9', type: MappingType.RangeToText, from: '1', to: '9' }, + { id: 0, text: 'elva', type: MappingType.ValueToText, value: '11' }, + { id: 1, text: '1-9', type: MappingType.RangeToText, from: '1', to: '9' }, ]; const value = '10'; @@ -21,8 +21,8 @@ describe('Format value with value mappings', () => { it('should return first matching mapping with lowest id', () => { const valueMappings: ValueMapping[] = [ - { id: 0, operator: '', text: '1-20', type: MappingType.RangeToText, from: '1', to: '20' }, - { id: 1, operator: '', text: 'tio', type: MappingType.ValueToText, value: '10' }, + { id: 0, text: '1-20', type: MappingType.RangeToText, from: '1', to: '20' }, + { id: 1, text: 'tio', type: MappingType.ValueToText, 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', () => { const valueMappings: ValueMapping[] = [ - { id: 0, operator: '', text: '1-20', type: MappingType.RangeToText, from: '1', to: '20' }, - { id: 1, operator: '', text: '', type: MappingType.ValueToText, value: 'null' }, + { id: 0, text: '1-20', type: MappingType.RangeToText, from: '1', to: '20' }, + { id: 1, text: '', type: MappingType.ValueToText, 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', () => { const valueMappings: ValueMapping[] = [ - { id: 0, operator: '', text: '', type: MappingType.RangeToText, from: 'null', to: 'null' }, - { id: 1, operator: '', text: 'elva', type: MappingType.ValueToText, value: '11' }, + { id: 0, text: '', type: MappingType.RangeToText, from: 'null', to: 'null' }, + { id: 1, text: 'elva', type: MappingType.ValueToText, value: '11' }, ]; const value = null; @@ -51,8 +51,8 @@ describe('Format value with value mappings', () => { it('should return rangeToText mapping where value equals to', () => { const valueMappings: ValueMapping[] = [ - { id: 0, operator: '', text: '1-10', type: MappingType.RangeToText, from: '1', to: '10' }, - { id: 1, operator: '', text: 'elva', type: MappingType.ValueToText, value: '11' }, + { id: 0, text: '1-10', type: MappingType.RangeToText, from: '1', to: '10' }, + { id: 1, text: 'elva', type: MappingType.ValueToText, value: '11' }, ]; const value = '10'; @@ -61,8 +61,8 @@ describe('Format value with value mappings', () => { it('should return rangeToText mapping where value equals from', () => { const valueMappings: ValueMapping[] = [ - { id: 0, operator: '', text: '10-20', type: MappingType.RangeToText, from: '10', to: '20' }, - { id: 1, operator: '', text: 'elva', type: MappingType.ValueToText, value: '11' }, + { id: 0, text: '10-20', type: MappingType.RangeToText, from: '10', to: '20' }, + { id: 1, text: 'elva', type: MappingType.ValueToText, value: '11' }, ]; 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', () => { const valueMappings: ValueMapping[] = [ - { id: 0, operator: '', text: '1-20', type: MappingType.RangeToText, from: '1', to: '20' }, - { id: 1, operator: '', text: 'elva', type: MappingType.ValueToText, value: '11' }, + { id: 0, text: '1-20', type: MappingType.RangeToText, from: '1', to: '20' }, + { id: 1, text: 'elva', type: MappingType.ValueToText, value: '11' }, ]; const value = '10'; @@ -81,8 +81,8 @@ describe('Format value with value mappings', () => { it('should map value text to mapping', () => { const valueMappings: ValueMapping[] = [ - { id: 0, operator: '', text: '1-20', type: MappingType.RangeToText, from: '1', to: '20' }, - { id: 1, operator: '', text: 'ELVA', type: MappingType.ValueToText, value: 'elva' }, + { id: 0, text: '1-20', type: MappingType.RangeToText, from: '1', to: '20' }, + { id: 1, text: 'ELVA', type: MappingType.ValueToText, value: 'elva' }, ]; const value = 'elva'; diff --git a/packages/grafana-ui/src/components/ValueMappingsEditor/ValueMappingsEditor.test.tsx b/packages/grafana-ui/src/components/ValueMappingsEditor/ValueMappingsEditor.test.tsx index 33b22f75747..56bcf01153d 100644 --- a/packages/grafana-ui/src/components/ValueMappingsEditor/ValueMappingsEditor.test.tsx +++ b/packages/grafana-ui/src/components/ValueMappingsEditor/ValueMappingsEditor.test.tsx @@ -12,8 +12,8 @@ const setup = (spy?: any, propOverrides?: object) => { } }, valueMappings: [ - { id: 1, operator: '', type: MappingType.ValueToText, value: '20', text: 'Ok' }, - { id: 2, operator: '', type: MappingType.RangeToText, from: '21', to: '30', text: 'Meh' }, + { id: 1, type: MappingType.ValueToText, value: '20', text: 'Ok' }, + { 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"]'); remove.at(0).simulate('click'); - expect(onChangeSpy).toBeCalledWith([ - { id: 2, operator: '', type: MappingType.RangeToText, from: '21', to: '30', text: 'Meh' }, - ]); + expect(onChangeSpy).toBeCalledWith([{ id: 2, type: MappingType.RangeToText, from: '21', to: '30', text: 'Meh' }]); }); 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"]'); remove.at(1).simulate('click'); - expect(onChangeSpy).toBeCalledWith([ - { id: 1, operator: '', type: MappingType.ValueToText, value: '20', text: 'Ok' }, - ]); + expect(onChangeSpy).toBeCalledWith([{ id: 1, type: MappingType.ValueToText, value: '20', text: 'Ok' }]); }); }); @@ -62,9 +58,9 @@ describe('Next id to add', () => { add.at(0).simulate('click'); expect(onChangeSpy).toBeCalledWith([ - { id: 1, operator: '', type: MappingType.ValueToText, value: '20', text: 'Ok' }, - { id: 2, operator: '', type: MappingType.RangeToText, from: '21', to: '30', text: 'Meh' }, - { id: 3, operator: '', type: MappingType.ValueToText, from: '', to: '', text: '' }, + { id: 1, type: MappingType.ValueToText, value: '20', text: 'Ok' }, + { id: 2, type: MappingType.RangeToText, from: '21', to: '30', text: 'Meh' }, + { id: 3, type: MappingType.ValueToText, from: '', to: '', text: '' }, ]); }); @@ -73,8 +69,6 @@ describe('Next id to add', () => { const wrapper = setup(onChangeSpy, { valueMappings: [] }); const add = wrapper.find('*[aria-label="ValueMappingsEditor add mapping button"]'); add.at(0).simulate('click'); - expect(onChangeSpy).toBeCalledWith([ - { id: 0, operator: '', type: MappingType.ValueToText, from: '', to: '', text: '' }, - ]); + expect(onChangeSpy).toBeCalledWith([{ id: 0, type: MappingType.ValueToText, from: '', to: '', text: '' }]); }); }); diff --git a/packages/grafana-ui/src/components/ValueMappingsEditor/ValueMappingsEditor.tsx b/packages/grafana-ui/src/components/ValueMappingsEditor/ValueMappingsEditor.tsx index ee838b5c481..d1fc93f8217 100644 --- a/packages/grafana-ui/src/components/ValueMappingsEditor/ValueMappingsEditor.tsx +++ b/packages/grafana-ui/src/components/ValueMappingsEditor/ValueMappingsEditor.tsx @@ -15,7 +15,6 @@ export const ValueMappingsEditor: React.FC = ({ valueMappings, onChange, type: MappingType.ValueToText, from: '', to: '', - operator: '', text: '', }; const id = update && update.length > 0 ? Math.max(...update.map(v => v.id)) + 1 : 0; diff --git a/packages/grafana-ui/src/utils/standardEditors.tsx b/packages/grafana-ui/src/utils/standardEditors.tsx index 56bfa3289bf..ac66c10ba93 100644 --- a/packages/grafana-ui/src/utils/standardEditors.tsx +++ b/packages/grafana-ui/src/utils/standardEditors.tsx @@ -155,6 +155,7 @@ export const getStandardFieldConfigs = () => { id: 'mappings', path: 'mappings', name: 'Value mappings', + description: 'Modify the display text based on input value', editor: standardEditorsRegistry.get('mappings').editor as any, override: standardEditorsRegistry.get('mappings').editor as any,