From 5ceedc4ac4aca6f33d86d93fd3ac84b6381350ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=A4ggmark?= Date: Fri, 11 Jan 2019 09:16:53 +0100 Subject: [PATCH] Moved defaultProps to ui/components --- .../ThresholdsEditor.test.tsx | 2 +- .../ThresholdsEditor/ThresholdsEditor.tsx | 4 +++- packages/grafana-ui/src/types/gauge.ts | 19 ++++++++++++++++- .../plugins/panel/gauge/GaugePanelOptions.tsx | 21 ++----------------- .../panel/gauge/ValueMappings.test.tsx | 6 +++--- public/app/plugins/panel/gauge/module.tsx | 6 ++++-- 6 files changed, 31 insertions(+), 27 deletions(-) diff --git a/packages/grafana-ui/src/components/ThresholdsEditor/ThresholdsEditor.test.tsx b/packages/grafana-ui/src/components/ThresholdsEditor/ThresholdsEditor.test.tsx index 074d3bc267b..40e6bb47f1f 100644 --- a/packages/grafana-ui/src/components/ThresholdsEditor/ThresholdsEditor.test.tsx +++ b/packages/grafana-ui/src/components/ThresholdsEditor/ThresholdsEditor.test.tsx @@ -1,8 +1,8 @@ import React from 'react'; import { shallow } from 'enzyme'; -import { BasicGaugeColor, GaugeOptions, PanelOptionsProps } from '@grafana/ui'; import { ThresholdsEditor } from './ThresholdsEditor'; +import { BasicGaugeColor, PanelOptionsProps, GaugeOptions } from '../../types'; const defaultProps = { options: { diff --git a/packages/grafana-ui/src/components/ThresholdsEditor/ThresholdsEditor.tsx b/packages/grafana-ui/src/components/ThresholdsEditor/ThresholdsEditor.tsx index df999de6c25..ed6778f7c43 100644 --- a/packages/grafana-ui/src/components/ThresholdsEditor/ThresholdsEditor.tsx +++ b/packages/grafana-ui/src/components/ThresholdsEditor/ThresholdsEditor.tsx @@ -1,6 +1,8 @@ import React, { PureComponent } from 'react'; import tinycolor, { ColorInput } from 'tinycolor2'; -import { BasicGaugeColor, ColorPicker, GaugeOptions, PanelOptionsProps, Threshold } from '@grafana/ui'; + +import { Threshold, PanelOptionsProps, GaugeOptions, BasicGaugeColor } from '../../types'; +import { ColorPicker } from '../ColorPicker/ColorPicker'; interface State { thresholds: Threshold[]; diff --git a/packages/grafana-ui/src/types/gauge.ts b/packages/grafana-ui/src/types/gauge.ts index de9c7f07328..fe422386d92 100644 --- a/packages/grafana-ui/src/types/gauge.ts +++ b/packages/grafana-ui/src/types/gauge.ts @@ -1,4 +1,4 @@ -import { RangeMap, Threshold, ValueMap } from '@grafana/ui'; +import { BasicGaugeColor, RangeMap, Threshold, ValueMap } from './panel'; export interface GaugeOptions { baseColor: string; @@ -14,3 +14,20 @@ export interface GaugeOptions { thresholds: Threshold[]; unit: string; } + +export const GaugePanelOptionsDefaultProps = { + options: { + baseColor: BasicGaugeColor.Green, + minValue: 0, + maxValue: 100, + prefix: '', + showThresholdMarkers: true, + showThresholdLabels: false, + suffix: '', + decimals: 0, + stat: 'avg', + unit: 'none', + mappings: [], + thresholds: [], + }, +}; diff --git a/public/app/plugins/panel/gauge/GaugePanelOptions.tsx b/public/app/plugins/panel/gauge/GaugePanelOptions.tsx index 951a310d29a..99bff41a0d3 100644 --- a/public/app/plugins/panel/gauge/GaugePanelOptions.tsx +++ b/public/app/plugins/panel/gauge/GaugePanelOptions.tsx @@ -1,29 +1,12 @@ import React, { PureComponent } from 'react'; -import { BasicGaugeColor, GaugeOptions, PanelOptionsProps, ThresholdsEditor } from '@grafana/ui'; +import { GaugeOptions, GaugePanelOptionsDefaultProps, PanelOptionsProps, ThresholdsEditor } 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 = { - options: { - baseColor: BasicGaugeColor.Green, - minValue: 0, - maxValue: 100, - prefix: '', - showThresholdMarkers: true, - showThresholdLabels: false, - suffix: '', - decimals: 0, - stat: 'avg', - unit: 'none', - mappings: [], - thresholds: [], - }, -}; - export default class GaugePanelOptions extends PureComponent> { - static defaultProps = defaultProps; + static defaultProps = GaugePanelOptionsDefaultProps; render() { const { onChange, options } = this.props; diff --git a/public/app/plugins/panel/gauge/ValueMappings.test.tsx b/public/app/plugins/panel/gauge/ValueMappings.test.tsx index 503e3e53617..0cf08d6d3b7 100644 --- a/public/app/plugins/panel/gauge/ValueMappings.test.tsx +++ b/public/app/plugins/panel/gauge/ValueMappings.test.tsx @@ -1,15 +1,15 @@ import React from 'react'; import { shallow } from 'enzyme'; import { GaugeOptions, MappingType, PanelOptionsProps } from '@grafana/ui'; +import { GaugePanelOptionsDefaultProps } from '@grafana/ui/src/types/gauge'; import ValueMappings from './ValueMappings'; -import { defaultProps } from 'app/plugins/panel/gauge/GaugePanelOptions'; const setup = (propOverrides?: object) => { const props: PanelOptionsProps = { onChange: jest.fn(), options: { - ...defaultProps.options, + ...GaugePanelOptionsDefaultProps.options, mappings: [ { id: 1, operator: '', type: MappingType.ValueToText, value: '20', text: 'Ok' }, { id: 2, operator: '', type: MappingType.RangeToText, from: '21', to: '30', text: 'Meh' }, @@ -67,7 +67,7 @@ describe('Next id to add', () => { }); it('should default to 1', () => { - const { instance } = setup({ options: { ...defaultProps.options } }); + const { instance } = setup({ options: { ...GaugePanelOptionsDefaultProps.options } }); expect(instance.state.nextIdToAdd).toEqual(1); }); diff --git a/public/app/plugins/panel/gauge/module.tsx b/public/app/plugins/panel/gauge/module.tsx index 783e4825657..72230eb4ba3 100644 --- a/public/app/plugins/panel/gauge/module.tsx +++ b/public/app/plugins/panel/gauge/module.tsx @@ -1,4 +1,6 @@ -import GaugePanelOptions, { defaultProps } from './GaugePanelOptions'; +import { GaugePanelOptionsDefaultProps } from '@grafana/ui'; + +import GaugePanelOptions from './GaugePanelOptions'; import { GaugePanel } from './GaugePanel'; -export { GaugePanel as Panel, GaugePanelOptions as PanelOptions, defaultProps as PanelDefaults }; +export { GaugePanel as Panel, GaugePanelOptions as PanelOptions, GaugePanelOptionsDefaultProps as PanelDefaults };