From cbbb6412b30551ff428f0092233d2da48a82852c Mon Sep 17 00:00:00 2001 From: Alex P Date: Tue, 21 Nov 2017 17:40:38 -0800 Subject: [PATCH] Send colors with save action and pass down to GaugeChart --- ui/src/dashboards/components/CellEditorOverlay.js | 7 +++++-- ui/src/dashboards/constants/gaugeColors.js | 7 +++++++ ui/src/shared/components/GaugeChart.js | 11 ++++++++++- ui/src/shared/components/Layout.js | 12 +++++++++++- ui/src/shared/components/RefreshingGraph.js | 11 +++++++++++ 5 files changed, 44 insertions(+), 4 deletions(-) diff --git a/ui/src/dashboards/components/CellEditorOverlay.js b/ui/src/dashboards/components/CellEditorOverlay.js index 6496e8734a..5f6c8c8972 100644 --- a/ui/src/dashboards/components/CellEditorOverlay.js +++ b/ui/src/dashboards/components/CellEditorOverlay.js @@ -29,13 +29,14 @@ import { GAUGE_COLORS, COLOR_TYPE_MIN, COLOR_TYPE_MAX, + validateColors, } from 'src/dashboards/constants/gaugeColors' class CellEditorOverlay extends Component { constructor(props) { super(props) - const {cell: {name, type, queries, axes}, sources} = props + const {cell: {name, type, queries, axes, colors}, sources} = props let source = _.get(queries, ['0', 'source'], null) source = sources.find(s => s.links.self === source) || props.source @@ -55,7 +56,7 @@ class CellEditorOverlay extends Component { activeQueryIndex: 0, isDisplayOptionsTabActive: false, axes, - colors: DEFAULT_COLORS, + colors: validateColors(colors) ? colors : DEFAULT_COLORS, } } @@ -211,6 +212,7 @@ class CellEditorOverlay extends Component { cellWorkingType: type, cellWorkingName: name, axes, + colors, } = this.state const {cell} = this.props @@ -232,6 +234,7 @@ class CellEditorOverlay extends Component { type, queries, axes, + colors, }) } diff --git a/ui/src/dashboards/constants/gaugeColors.js b/ui/src/dashboards/constants/gaugeColors.js index 760680917c..3d80db20ea 100644 --- a/ui/src/dashboards/constants/gaugeColors.js +++ b/ui/src/dashboards/constants/gaugeColors.js @@ -86,3 +86,10 @@ export const DEFAULT_COLORS = [ value: DEFAULT_VALUE_MAX, }, ] + +export const validateColors = colors => { + const hasMin = colors.some(color => color.type === COLOR_TYPE_MIN) + const hasMax = colors.some(color => color.type === COLOR_TYPE_MAX) + + return hasMin && hasMax +} diff --git a/ui/src/shared/components/GaugeChart.js b/ui/src/shared/components/GaugeChart.js index 36291afd11..ac05b4c8d9 100644 --- a/ui/src/shared/components/GaugeChart.js +++ b/ui/src/shared/components/GaugeChart.js @@ -45,12 +45,21 @@ class GaugeChart extends Component { } } -const {arrayOf, bool, number, shape} = PropTypes +const {arrayOf, bool, number, shape, string} = PropTypes GaugeChart.propTypes = { data: arrayOf(shape()).isRequired, isFetchingInitially: bool, cellHeight: number, + colors: arrayOf( + shape({ + type: string.isRequired, + hex: string.isRequired, + id: string.isRequired, + name: string.isRequired, + value: string.isRequired, + }).isRequired + ), } export default GaugeChart diff --git a/ui/src/shared/components/Layout.js b/ui/src/shared/components/Layout.js index ea69fe6c6d..5d1d4d9fe2 100644 --- a/ui/src/shared/components/Layout.js +++ b/ui/src/shared/components/Layout.js @@ -43,7 +43,7 @@ const Layout = ( { host, cell, - cell: {h, axes, type}, + cell: {h, axes, type, colors}, source, sources, onZoom, @@ -75,6 +75,7 @@ const Layout = ( {cell.isWidget ? :