Moved ValueMappings to grafana/ui/component and renamed it ValueMappingsEditor

This commit is contained in:
Hugo Häggmark 2019-01-16 10:49:48 +01:00
parent 639dc6c3c3
commit c90979a8f0
9 changed files with 75 additions and 12 deletions

View File

@ -1,5 +1,8 @@
import React, { PureComponent } from 'react';
import { MappingType, RangeMap, Select, ValueMap, Label } from '@grafana/ui';
import { ValueMap, RangeMap, MappingType } from '../../types/panel';
import { Label } from '../Label/Label';
import { Select } from '../Select/Select';
interface Props {
mapping: ValueMap | RangeMap;

View File

@ -1,9 +1,10 @@
import React from 'react';
import { shallow } from 'enzyme';
import { GaugeOptions, MappingType, PanelOptionsProps } from '@grafana/ui';
import { defaultProps } from 'app/plugins/panel/gauge/GaugePanelOptions';
import ValueMappings from './ValueMappings';
import { defaultProps } from 'app/plugins/panel/gauge/GaugePanelOptions';
import { ValueMappingsEditor } from './ValueMappingsEditor';
import { PanelOptionsProps, MappingType } from '../../types/panel';
import { GaugeOptions } from '../../types/gauge';
const setup = (propOverrides?: object) => {
const props: PanelOptionsProps<GaugeOptions> = {
@ -19,9 +20,9 @@ const setup = (propOverrides?: object) => {
Object.assign(props, propOverrides);
const wrapper = shallow(<ValueMappings {...props} />);
const wrapper = shallow(<ValueMappingsEditor {...props} />);
const instance = wrapper.instance() as ValueMappings;
const instance = wrapper.instance() as ValueMappingsEditor;
return {
instance,

View File

@ -1,14 +1,16 @@
import React, { PureComponent } from 'react';
import { GaugeOptions, PanelOptionsProps, MappingType, RangeMap, ValueMap, PanelOptionsGroup } from '@grafana/ui';
import MappingRow from './MappingRow';
import { PanelOptionsProps, ValueMap, RangeMap, MappingType } from '../../types/panel';
import { GaugeOptions } from '../../types/gauge';
import { PanelOptionsGroup } from '../PanelOptionsGroup/PanelOptionsGroup';
interface State {
mappings: Array<ValueMap | RangeMap>;
nextIdToAdd: number;
}
export default class ValueMappings extends PureComponent<PanelOptionsProps<GaugeOptions>, State> {
export class ValueMappingsEditor extends PureComponent<PanelOptionsProps<GaugeOptions>, State> {
constructor(props) {
super(props);

View File

@ -0,0 +1,56 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Render should render component 1`] = `
<Component
title="Value Mappings"
>
<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>
</Component>
`;

View File

@ -6,3 +6,4 @@
@import 'PanelOptionsGroup/PanelOptionsGroup';
@import 'PanelOptionsGrid/PanelOptionsGrid';
@import 'ColorPicker/ColorPicker';
@import 'ValueMappingsEditor/ValueMappingsEditor';

View File

@ -19,3 +19,4 @@ export { GfFormLabel } from './GfFormLabel/GfFormLabel';
export { Graph } from './Graph/Graph';
export { PanelOptionsGroup } from './PanelOptionsGroup/PanelOptionsGroup';
export { PanelOptionsGrid } from './PanelOptionsGrid/PanelOptionsGrid';
export { ValueMappingsEditor } from './ValueMappingsEditor/ValueMappingsEditor';

View File

@ -6,10 +6,10 @@ import {
ThresholdsEditor,
Threshold,
PanelOptionsGrid,
ValueMappingsEditor,
} from '@grafana/ui';
import ValueOptions from 'app/plugins/panel/gauge/ValueOptions';
import ValueMappings from 'app/plugins/panel/gauge/ValueMappings';
import GaugeOptionsEditor from './GaugeOptionsEditor';
export const defaultProps = {
@ -44,7 +44,7 @@ export default class GaugePanelOptions extends PureComponent<PanelOptionsProps<G
<ThresholdsEditor onChange={this.onThresholdsChanged} thresholds={options.thresholds} />
</PanelOptionsGrid>
<ValueMappings onChange={onChange} options={options} />
<ValueMappingsEditor onChange={onChange} options={options} />
</>
);
}

View File

@ -1,4 +1,4 @@
// DEPENDENCIES
// DEPENDENCIES
@import '../../node_modules/react-table/react-table.css';
// VENDOR
@ -97,7 +97,6 @@
@import 'components/add_data_source.scss';
@import 'components/page_loader';
@import 'components/toggle_button_group';
@import 'components/value-mappings';
@import 'components/popover-box';
// LOAD @grafana/ui components