From ad1505b346da7b07f97c480e718724ea19fedd6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=A4ggmark?= Date: Tue, 15 Jan 2019 09:35:37 +0100 Subject: [PATCH] Reordered the input row --- .../ThresholdsEditor.test.tsx | 20 +++++++++++ .../ThresholdsEditor/ThresholdsEditor.tsx | 33 +++++++++++++------ .../ThresholdsEditor/_ThresholdsEditor.scss | 30 +++++++++-------- 3 files changed, 59 insertions(+), 24 deletions(-) diff --git a/packages/grafana-ui/src/components/ThresholdsEditor/ThresholdsEditor.test.tsx b/packages/grafana-ui/src/components/ThresholdsEditor/ThresholdsEditor.test.tsx index f87d56a5bb5..304e210d3df 100644 --- a/packages/grafana-ui/src/components/ThresholdsEditor/ThresholdsEditor.test.tsx +++ b/packages/grafana-ui/src/components/ThresholdsEditor/ThresholdsEditor.test.tsx @@ -69,6 +69,26 @@ describe('Add threshold', () => { }); }); +describe('Remove threshold', () => { + it('should remove threshold', () => { + const thresholds = [ + { index: 0, value: -Infinity, color: '#299c46' }, + { index: 1, value: 50, color: '#EAB839' }, + { index: 2, value: 75, color: '#6ED0E0' }, + ]; + const instance = setup({ + thresholds, + }); + + instance.onRemoveThreshold(thresholds[1]); + + expect(instance.state.thresholds).toEqual([ + { index: 0, value: -Infinity, color: '#299c46' }, + { index: 1, value: 75, color: '#6ED0E0' }, + ]); + }); +}); + describe('change threshold value', () => { it('should update value and resort rows', () => { const instance = setup(); diff --git a/packages/grafana-ui/src/components/ThresholdsEditor/ThresholdsEditor.tsx b/packages/grafana-ui/src/components/ThresholdsEditor/ThresholdsEditor.tsx index 720c70c3ec5..8c336f38063 100644 --- a/packages/grafana-ui/src/components/ThresholdsEditor/ThresholdsEditor.tsx +++ b/packages/grafana-ui/src/components/ThresholdsEditor/ThresholdsEditor.tsx @@ -69,7 +69,19 @@ export class ThresholdsEditor extends PureComponent { onRemoveThreshold = (threshold: Threshold) => { this.setState( - prevState => ({ thresholds: prevState.thresholds.filter(t => t !== threshold) }), + prevState => { + const newThresholds = prevState.thresholds.map(t => { + if (t.index > threshold.index) { + const index = t.index - 1; + t = { ...t, index }; + } + return t; + }); + + return { + thresholds: newThresholds.filter(t => t !== threshold), + }; + }, () => this.updateGauge() ); }; @@ -128,15 +140,7 @@ export class ThresholdsEditor extends PureComponent { const value = threshold.index === 0 ? 'Base' : threshold.value; return (
-
- this.onChangeThresholdValue(event, threshold)} - value={value} - onBlur={this.onBlur} - readOnly={threshold.index === 0} - /> +
{threshold.color && (
@@ -144,6 +148,15 @@ export class ThresholdsEditor extends PureComponent {
)}
+
+ this.onChangeThresholdValue(event, threshold)} + value={value} + onBlur={this.onBlur} + readOnly={threshold.index === 0} + /> +
{threshold.index > 0 && (
this.onRemoveThreshold(threshold)}> diff --git a/packages/grafana-ui/src/components/ThresholdsEditor/_ThresholdsEditor.scss b/packages/grafana-ui/src/components/ThresholdsEditor/_ThresholdsEditor.scss index 9bc79d23e76..809f2936d27 100644 --- a/packages/grafana-ui/src/components/ThresholdsEditor/_ThresholdsEditor.scss +++ b/packages/grafana-ui/src/components/ThresholdsEditor/_ThresholdsEditor.scss @@ -48,7 +48,18 @@ height: 37px; } -.thresholds-row-input-inner > div:last-child { +.thresholds-row-input-inner > div { + border-left: 1px solid $input-label-border-color; + border-top: 1px solid $input-label-border-color; + border-bottom: 1px solid $input-label-border-color; +} + +.thresholds-row-input-inner > *:nth-child(2) { + border-top-left-radius: $border-radius; + border-bottom-left-radius: $border-radius; +} + +.thresholds-row-input-inner > *:last-child { border-top-right-radius: $border-radius; border-bottom-right-radius: $border-radius; } @@ -57,24 +68,18 @@ align-self: center; width: 0; height: 0; - border-top: 5px solid transparent; - border-bottom: 5px solid transparent; - border-right: 5px solid $input-label-border-color; + border-top: 6px solid transparent; + border-bottom: 6px solid transparent; + border-right: 6px solid $input-label-border-color; } -.thresholds-row-input-inner-value { - border: 1px solid $input-label-border-color; - border-top-left-radius: $border-radius; - border-bottom-left-radius: $border-radius; +.thresholds-row-input-inner-value > input { padding: 8px 10px; width: 150px; } .thresholds-row-input-inner-color { width: 37px; - border-top: 1px solid $input-label-border-color; - border-bottom: 1px solid $input-label-border-color; - border-right: 1px solid $input-label-border-color; display: flex; align-items: center; justify-content: center; @@ -96,8 +101,5 @@ height: 37px; width: 37px; background-color: $input-label-border-color; - border-top: 1px solid $input-label-border-color; - border-bottom: 1px solid $input-label-border-color; - border-right: 1px solid $input-label-border-color; cursor: pointer; }