diff --git a/packages/grafana-ui/src/components/ValueMappingsEditor/ValueMappingEditRow.tsx b/packages/grafana-ui/src/components/ValueMappingsEditor/ValueMappingEditRow.tsx index 3c3578908f9..ca7bdb11c3a 100644 --- a/packages/grafana-ui/src/components/ValueMappingsEditor/ValueMappingEditRow.tsx +++ b/packages/grafana-ui/src/components/ValueMappingsEditor/ValueMappingEditRow.tsx @@ -154,7 +154,7 @@ export function ValueMappingEditRow({ mapping, index, onChange, onRemove }: Prop )} - + {result.color && ( diff --git a/packages/grafana-ui/src/components/ValueMappingsEditor/ValueMappingsEditorModal.test.tsx b/packages/grafana-ui/src/components/ValueMappingsEditor/ValueMappingsEditorModal.test.tsx index daac4a6f6f4..e907a155b14 100644 --- a/packages/grafana-ui/src/components/ValueMappingsEditor/ValueMappingsEditorModal.test.tsx +++ b/packages/grafana-ui/src/components/ValueMappingsEditor/ValueMappingsEditorModal.test.tsx @@ -2,6 +2,8 @@ import React from 'react'; import { fireEvent, render, screen } from '@testing-library/react'; import { ValueMappingsEditorModal, Props } from './ValueMappingsEditorModal'; import { MappingType } from '@grafana/data'; +import { selectors } from '@grafana/e2e-selectors'; +import selectEvent from 'react-select-event'; const setup = (spy?: any, propOverrides?: object) => { const props: Props = { @@ -75,12 +77,14 @@ describe('When adding and updating value mapp', () => { const onChangeSpy = jest.fn(); setup(onChangeSpy); - fireEvent.click(screen.getByTestId('add value map')); + fireEvent.click(screen.getByLabelText(selectors.components.ValuePicker.button('Add a new mapping'))); + const selectComponent = await screen.findByLabelText(selectors.components.ValuePicker.select('Add a new mapping')); + await selectEvent.select(selectComponent, 'Value'); const input = (await screen.findAllByPlaceholderText('Exact value to match'))[1]; fireEvent.change(input, { target: { value: 'New' } }); - fireEvent.change(screen.getAllByPlaceholderText('Display text')[2], { target: { value: 'display' } }); + fireEvent.change(screen.getAllByPlaceholderText('Optional display text')[2], { target: { value: 'display' } }); fireEvent.click(screen.getByText('Update')); expect(onChangeSpy).toBeCalledWith([ @@ -117,11 +121,13 @@ describe('When adding and updating range map', () => { const onChangeSpy = jest.fn(); setup(onChangeSpy, { value: [] }); - fireEvent.click(screen.getByTestId('add range map')); + fireEvent.click(screen.getByLabelText(selectors.components.ValuePicker.button('Add a new mapping'))); + const selectComponent = await screen.findByLabelText(selectors.components.ValuePicker.select('Add a new mapping')); + await selectEvent.select(selectComponent, 'Range'); fireEvent.change(screen.getByPlaceholderText('Range start'), { target: { value: '10' } }); fireEvent.change(screen.getByPlaceholderText('Range end'), { target: { value: '20' } }); - fireEvent.change(screen.getByPlaceholderText('Display text'), { target: { value: 'display' } }); + fireEvent.change(screen.getByPlaceholderText('Optional display text'), { target: { value: 'display' } }); fireEvent.click(screen.getByText('Update')); diff --git a/packages/grafana-ui/src/components/ValueMappingsEditor/ValueMappingsEditorModal.tsx b/packages/grafana-ui/src/components/ValueMappingsEditor/ValueMappingsEditorModal.tsx index 7882f99e59a..2a333a9b5dc 100644 --- a/packages/grafana-ui/src/components/ValueMappingsEditor/ValueMappingsEditorModal.tsx +++ b/packages/grafana-ui/src/components/ValueMappingsEditor/ValueMappingsEditorModal.tsx @@ -1,12 +1,12 @@ import React, { useEffect, useState } from 'react'; -import { GrafanaTheme2, MappingType, SpecialValueMatch, ValueMapping } from '@grafana/data'; +import { GrafanaTheme2, MappingType, SelectableValue, SpecialValueMatch, ValueMapping } from '@grafana/data'; import { Button } from '../Button/Button'; import { Modal } from '../Modal/Modal'; import { useStyles2 } from '../../themes'; import { ValueMappingEditRow, ValueMappingEditRowModel } from './ValueMappingEditRow'; import { DragDropContext, Droppable, DropResult } from 'react-beautiful-dnd'; -import { HorizontalGroup } from '../Layout/Layout'; import { css } from '@emotion/css'; +import { ValuePicker } from '../ValuePicker/ValuePicker'; export interface Props { value: ValueMapping[]; @@ -46,39 +46,23 @@ export function ValueMappingsEditorModal({ value, onChange, onClose }: Props) { updateRows(newList); }; - const onAddValueMap = () => { - updateRows([ - ...rows, - { - type: MappingType.ValueToText, - isNew: true, - result: {}, - }, - ]); - }; + const mappingTypes: Array> = [ + { label: 'Value', value: MappingType.ValueToText, description: 'Match a specific text value' }, + { label: 'Range', value: MappingType.RangeToText, description: 'Match a numerical range of values' }, + { label: 'Special', value: MappingType.SpecialValue, description: 'Match on null, NaN, boolean and empty values' }, + ]; - const onAddRangeMap = () => { + const onAddValueMapping = (value: SelectableValue) => { updateRows([ ...rows, { - type: MappingType.RangeToText, + type: value.value!, isNew: true, result: {}, }, ]); }; - const onAddSpecialValueMap = () => { - updateRows([ - ...rows, - { - type: MappingType.SpecialValue, - specialMatch: SpecialValueMatch.Null, - result: {}, - }, - ]); - }; - const onUpdate = () => { onChange(editModelToSaveModel(rows)); onClose(); @@ -90,10 +74,11 @@ export function ValueMappingsEditorModal({ value, onChange, onClose }: Props) { - Type - Match - Display text - Color + + Condition + + Display text + Color @@ -116,17 +101,16 @@ export function ValueMappingsEditorModal({ value, onChange, onClose }: Props) { - - - - - +