Guard against gauges accepting incorrect color types

pull/3122/head
Alex P 2018-04-03 21:15:30 -07:00
parent 30163ab656
commit a554e0291f
1 changed files with 15 additions and 0 deletions

View File

@ -161,6 +161,21 @@ export const validateGaugeColors = colors => {
return DEFAULT_GAUGE_COLORS
}
const colorsAreIncorrectType =
colors.reduce((acc, color) => {
if (
color.type === COLOR_TYPE_MIN ||
color.type === COLOR_TYPE_MAX ||
color.type === COLOR_TYPE_THRESHOLD
) {
return (acc += 1)
}
}, 0) !== colors.length
if (colorsAreIncorrectType) {
return DEFAULT_GAUGE_COLORS
}
// Gauge colors should have a type of min, any number of thresholds, and a max
const formattedColors = _.sortBy(colors, color => Number(color.value)).map(
color => ({