Thresholds: Fix undefined color in "Add threshold" #39113

This commit is contained in:
Alexander Kubyshkin
2021-09-13 07:11:13 +02:00
committed by GitHub
parent f8d79d301c
commit 3cf3e02596
@@ -59,7 +59,11 @@ export class ThresholdsEditor extends PureComponent<Props, State> {
nextValue = steps[steps.length - 1].value + 10;
}
const color = colors.filter((c) => !steps.some((t) => t.color === c))[1];
let color = colors.filter((c) => !steps.some((t) => t.color === c))[1];
if (!color) {
// Default color when all colors are used
color = '#CCCCCC';
}
const add = {
value: nextValue,
@@ -154,15 +158,13 @@ export class ThresholdsEditor extends PureComponent<Props, State> {
value={'Base'}
disabled
prefix={
threshold.color && (
<div className={styles.colorPicker}>
<ColorPicker
color={threshold.color}
onChange={(color) => this.onChangeThresholdColor(threshold, color)}
enableNamedColors={true}
/>
</div>
)
<div className={styles.colorPicker}>
<ColorPicker
color={threshold.color}
onChange={(color) => this.onChangeThresholdColor(threshold, color)}
enableNamedColors={true}
/>
</div>
}
/>
);
@@ -179,15 +181,13 @@ export class ThresholdsEditor extends PureComponent<Props, State> {
onBlur={this.onBlur}
prefix={
<div className={styles.inputPrefix}>
{threshold.color && (
<div className={styles.colorPicker}>
<ColorPicker
color={threshold.color}
onChange={(color) => this.onChangeThresholdColor(threshold, color)}
enableNamedColors={true}
/>
</div>
)}
<div className={styles.colorPicker}>
<ColorPicker
color={threshold.color}
onChange={(color) => this.onChangeThresholdColor(threshold, color)}
enableNamedColors={true}
/>
</div>
{isPercent && <div className={styles.percentIcon}>%</div>}
</div>
}