|
|
@@ -1,22 +1,22 @@
|
|
|
-import React, { PureComponent } from 'react';
|
|
|
-import { MappingType, RangeMap, Select, ValueMap } from '@grafana/ui';
|
|
|
+import React, { ChangeEvent, PureComponent } from 'react';
|
|
|
|
|
|
-import { Label } from 'app/core/components/Label/Label';
|
|
|
+import { MappingType, ValueMapping } from '../../types';
|
|
|
+import { FormField, FormLabel, Select } from '..';
|
|
|
|
|
|
-interface Props {
|
|
|
- mapping: ValueMap | RangeMap;
|
|
|
- updateMapping: (mapping) => void;
|
|
|
- removeMapping: () => void;
|
|
|
+export interface Props {
|
|
|
+ valueMapping: ValueMapping;
|
|
|
+ updateValueMapping: (valueMapping: ValueMapping) => void;
|
|
|
+ removeValueMapping: () => void;
|
|
|
}
|
|
|
|
|
|
interface State {
|
|
|
- from: string;
|
|
|
+ from?: string;
|
|
|
id: number;
|
|
|
operator: string;
|
|
|
text: string;
|
|
|
- to: string;
|
|
|
+ to?: string;
|
|
|
type: MappingType;
|
|
|
- value: string;
|
|
|
+ value?: string;
|
|
|
}
|
|
|
|
|
|
const mappingOptions = [
|
|
|
@@ -25,36 +25,34 @@ const mappingOptions = [
|
|
|
];
|
|
|
|
|
|
export default class MappingRow extends PureComponent<Props, State> {
|
|
|
- constructor(props) {
|
|
|
+ constructor(props: Props) {
|
|
|
super(props);
|
|
|
|
|
|
- this.state = {
|
|
|
- ...props.mapping,
|
|
|
- };
|
|
|
+ this.state = { ...props.valueMapping };
|
|
|
}
|
|
|
|
|
|
- onMappingValueChange = event => {
|
|
|
+ onMappingValueChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
|
this.setState({ value: event.target.value });
|
|
|
};
|
|
|
|
|
|
- onMappingFromChange = event => {
|
|
|
+ onMappingFromChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
|
this.setState({ from: event.target.value });
|
|
|
};
|
|
|
|
|
|
- onMappingToChange = event => {
|
|
|
+ onMappingToChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
|
this.setState({ to: event.target.value });
|
|
|
};
|
|
|
|
|
|
- onMappingTextChange = event => {
|
|
|
+ onMappingTextChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
|
this.setState({ text: event.target.value });
|
|
|
};
|
|
|
|
|
|
- onMappingTypeChange = mappingType => {
|
|
|
+ onMappingTypeChange = (mappingType: MappingType) => {
|
|
|
this.setState({ type: mappingType });
|
|
|
};
|
|
|
|
|
|
updateMapping = () => {
|
|
|
- this.props.updateMapping({ ...this.state });
|
|
|
+ this.props.updateValueMapping({ ...this.state } as ValueMapping);
|
|
|
};
|
|
|
|
|
|
renderRow() {
|
|
|
@@ -63,30 +61,28 @@ export default class MappingRow extends PureComponent<Props, State> {
|
|
|
if (type === MappingType.RangeToText) {
|
|
|
return (
|
|
|
<>
|
|
|
- <div className="gf-form">
|
|
|
- <Label width={4}>From</Label>
|
|
|
- <input
|
|
|
- className="gf-form-input width-8"
|
|
|
- value={from}
|
|
|
- onBlur={this.updateMapping}
|
|
|
- onChange={this.onMappingFromChange}
|
|
|
- />
|
|
|
- </div>
|
|
|
- <div className="gf-form">
|
|
|
- <Label width={4}>To</Label>
|
|
|
+ <FormField
|
|
|
+ label="From"
|
|
|
+ labelWidth={4}
|
|
|
+ inputWidth={8}
|
|
|
+ onBlur={this.updateMapping}
|
|
|
+ onChange={this.onMappingFromChange}
|
|
|
+ value={from}
|
|
|
+ />
|
|
|
+ <FormField
|
|
|
+ label="To"
|
|
|
+ labelWidth={4}
|
|
|
+ inputWidth={8}
|
|
|
+ onBlur={this.updateMapping}
|
|
|
+ onChange={this.onMappingToChange}
|
|
|
+ value={to}
|
|
|
+ />
|
|
|
+ <div className="gf-form gf-form--grow">
|
|
|
+ <FormLabel width={4}>Text</FormLabel>
|
|
|
<input
|
|
|
- className="gf-form-input width-8"
|
|
|
- value={to}
|
|
|
+ className="gf-form-input"
|
|
|
onBlur={this.updateMapping}
|
|
|
- onChange={this.onMappingToChange}
|
|
|
- />
|
|
|
- </div>
|
|
|
- <div className="gf-form">
|
|
|
- <Label width={4}>Text</Label>
|
|
|
- <input
|
|
|
- className="gf-form-input width-10"
|
|
|
value={text}
|
|
|
- onBlur={this.updateMapping}
|
|
|
onChange={this.onMappingTextChange}
|
|
|
/>
|
|
|
</div>
|
|
|
@@ -96,17 +92,16 @@ export default class MappingRow extends PureComponent<Props, State> {
|
|
|
|
|
|
return (
|
|
|
<>
|
|
|
- <div className="gf-form">
|
|
|
- <Label width={4}>Value</Label>
|
|
|
- <input
|
|
|
- className="gf-form-input width-8"
|
|
|
- onBlur={this.updateMapping}
|
|
|
- onChange={this.onMappingValueChange}
|
|
|
- value={value}
|
|
|
- />
|
|
|
- </div>
|
|
|
+ <FormField
|
|
|
+ label="Value"
|
|
|
+ labelWidth={4}
|
|
|
+ onBlur={this.updateMapping}
|
|
|
+ onChange={this.onMappingValueChange}
|
|
|
+ value={value}
|
|
|
+ inputWidth={8}
|
|
|
+ />
|
|
|
<div className="gf-form gf-form--grow">
|
|
|
- <Label width={4}>Text</Label>
|
|
|
+ <FormLabel width={4}>Text</FormLabel>
|
|
|
<input
|
|
|
className="gf-form-input"
|
|
|
onBlur={this.updateMapping}
|
|
|
@@ -124,7 +119,7 @@ export default class MappingRow extends PureComponent<Props, State> {
|
|
|
return (
|
|
|
<div className="gf-form-inline">
|
|
|
<div className="gf-form">
|
|
|
- <Label width={5}>Type</Label>
|
|
|
+ <FormLabel width={5}>Type</FormLabel>
|
|
|
<Select
|
|
|
placeholder="Choose type"
|
|
|
isSearchable={false}
|
|
|
@@ -136,7 +131,7 @@ export default class MappingRow extends PureComponent<Props, State> {
|
|
|
</div>
|
|
|
{this.renderRow()}
|
|
|
<div className="gf-form">
|
|
|
- <button onClick={this.props.removeMapping} className="gf-form-label gf-form-label--btn">
|
|
|
+ <button onClick={this.props.removeValueMapping} className="gf-form-label gf-form-label--btn">
|
|
|
<i className="fa fa-times" />
|
|
|
</button>
|
|
|
</div>
|