Commit 346f5f25 by Peter Holmberg

Using drop down instead

parent db87c512
...@@ -11,7 +11,7 @@ interface Props { ...@@ -11,7 +11,7 @@ interface Props {
onSelected: (item: any) => {} | void; onSelected: (item: any) => {} | void;
options: any[]; options: any[];
placeholder?: string; placeholder?: string;
width: number; width?: number;
value: any; value: any;
} }
...@@ -29,7 +29,7 @@ const SimplePicker: SFC<Props> = ({ ...@@ -29,7 +29,7 @@ const SimplePicker: SFC<Props> = ({
return ( return (
<Select <Select
classNamePrefix={`gf-form-select-box`} classNamePrefix={`gf-form-select-box`}
className={`width-${width} gf-form-input gf-form-input--form-dropdown ${className || ''}`} className={`${width ? 'width-' + width : ''} gf-form-input gf-form-input--form-dropdown ${className || ''}`}
components={{ components={{
Option: DescriptionOption, Option: DescriptionOption,
}} }}
......
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import { Label } from 'app/core/components/Label/Label'; import { Label } from 'app/core/components/Label/Label';
import ToggleButtonGroup, { ToggleButton } from 'app/core/components/ToggleButtonGroup/ToggleButtonGroup'; import SimplePicker from 'app/core/components/Picker/SimplePicker';
import { MappingType, RangeMap, ValueMap } from 'app/types'; import { MappingType, RangeMap, ValueMap } from 'app/types';
interface Props { interface Props {
...@@ -13,6 +13,11 @@ interface State { ...@@ -13,6 +13,11 @@ interface State {
mapping: ValueMap | RangeMap; mapping: ValueMap | RangeMap;
} }
const mappingOptions = [
{ value: MappingType.ValueToText, label: 'Value' },
{ value: MappingType.RangeToText, label: 'Range' },
];
export default class MappingRow extends PureComponent<Props, State> { export default class MappingRow extends PureComponent<Props, State> {
constructor(props) { constructor(props) {
super(props); super(props);
...@@ -147,34 +152,13 @@ export default class MappingRow extends PureComponent<Props, State> { ...@@ -147,34 +152,13 @@ export default class MappingRow extends PureComponent<Props, State> {
return ( return (
<div className="mapping-row"> <div className="mapping-row">
<div className="mapping-row-type"> <div className="mapping-row-type">
<ToggleButtonGroup <SimplePicker
onChange={mappingType => this.onMappingTypeChange(mappingType)} placeholder="Choose type"
value={mapping.type} options={mappingOptions}
stackedButtons={true} value={mappingOptions.find(o => o.value === mapping.type)}
render={({ selectedValue, onChange, stackedButtons }) => { getOptionLabel={i => i.label}
return [ getOptionValue={i => i.value}
<ToggleButton onSelected={type => this.onMappingTypeChange(type)}
className="btn-small"
key="value"
onChange={onChange}
selected={selectedValue === MappingType.ValueToText}
value={MappingType.ValueToText}
stackedButtons={stackedButtons}
>
Value
</ToggleButton>,
<ToggleButton
className="btn-small"
key="range"
onChange={onChange}
selected={selectedValue === MappingType.RangeToText}
value={MappingType.RangeToText}
stackedButtons={stackedButtons}
>
Range
</ToggleButton>,
];
}}
/> />
</div> </div>
<div>{this.renderRow()}</div> <div>{this.renderRow()}</div>
......
import React from 'react'; import React from 'react';
import { shallow } from 'enzyme'; import { shallow } from 'enzyme';
import { defaultProps, OptionModuleProps } from './module';
import { MappingType } from '../../../types';
import ValueMappings from './ValueMappings'; import ValueMappings from './ValueMappings';
import { defaultProps, OptionModuleProps } from './module';
import { MappingType } from 'app/types';
const setup = (propOverrides?: object) => { const setup = (propOverrides?: object) => {
const props: OptionModuleProps = { const props: OptionModuleProps = {
...@@ -20,12 +20,25 @@ const setup = (propOverrides?: object) => { ...@@ -20,12 +20,25 @@ const setup = (propOverrides?: object) => {
const wrapper = shallow(<ValueMappings {...props} />); const wrapper = shallow(<ValueMappings {...props} />);
return wrapper.instance() as ValueMappings; const instance = wrapper.instance() as ValueMappings;
return {
instance,
wrapper,
};
}; };
describe('Render', () => {
it('should render component', () => {
const { wrapper } = setup();
expect(wrapper).toMatchSnapshot();
});
});
describe('On remove mapping', () => { describe('On remove mapping', () => {
it('Should remove mapping with id 0', () => { it('Should remove mapping with id 0', () => {
const instance = setup(); const { instance } = setup();
instance.onRemoveMapping(1); instance.onRemoveMapping(1);
expect(instance.state.mappings).toEqual([ expect(instance.state.mappings).toEqual([
...@@ -34,7 +47,7 @@ describe('On remove mapping', () => { ...@@ -34,7 +47,7 @@ describe('On remove mapping', () => {
}); });
it('should remove mapping with id 1', () => { it('should remove mapping with id 1', () => {
const instance = setup(); const { instance } = setup();
instance.onRemoveMapping(2); instance.onRemoveMapping(2);
expect(instance.state.mappings).toEqual([ expect(instance.state.mappings).toEqual([
...@@ -45,7 +58,7 @@ describe('On remove mapping', () => { ...@@ -45,7 +58,7 @@ describe('On remove mapping', () => {
describe('Next id to add', () => { describe('Next id to add', () => {
it('should be 4', () => { it('should be 4', () => {
const instance = setup(); const { instance } = setup();
instance.addMapping(); instance.addMapping();
...@@ -53,7 +66,7 @@ describe('Next id to add', () => { ...@@ -53,7 +66,7 @@ describe('Next id to add', () => {
}); });
it('should default to 1', () => { it('should default to 1', () => {
const instance = setup({ options: { ...defaultProps.options } }); const { instance } = setup({ options: { ...defaultProps.options } });
expect(instance.state.nextIdToAdd).toEqual(1); expect(instance.state.nextIdToAdd).toEqual(1);
}); });
......
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Render should render component 1`] = `
<div
className="section gf-form-group"
>
<h5
className="page-heading"
>
Value mappings
</h5>
<div>
<MappingRow
key="Ok-0"
mapping={
Object {
"id": 1,
"operator": "",
"text": "Ok",
"type": 1,
"value": "20",
}
}
removeMapping={[Function]}
updateMapping={[Function]}
/>
<MappingRow
key="Meh-1"
mapping={
Object {
"from": "21",
"id": 2,
"operator": "",
"text": "Meh",
"to": "30",
"type": 2,
}
}
removeMapping={[Function]}
updateMapping={[Function]}
/>
</div>
<div
className="add-mapping-row"
onClick={[Function]}
>
<div
className="add-mapping-row-icon"
>
<i
className="fa fa-plus"
/>
</div>
<div
className="add-mapping-row-label"
>
Add mapping
</div>
</div>
</div>
`;
...@@ -77,7 +77,8 @@ ...@@ -77,7 +77,8 @@
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
width: 36px; height: 37px;
width: 37px;
cursor: pointer; cursor: pointer;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment