From aac1b6c57b273aa1ca2a2181eee4f76937b53b61 Mon Sep 17 00:00:00 2001 From: Peter Holmberg Date: Mon, 26 Nov 2018 15:52:50 +0100 Subject: [PATCH] logic for adding rows, styling --- public/app/plugins/panel/gauge/Thresholds.tsx | 130 ++++++++---------- public/sass/components/_thresholds.scss | 50 ++++++- 2 files changed, 106 insertions(+), 74 deletions(-) diff --git a/public/app/plugins/panel/gauge/Thresholds.tsx b/public/app/plugins/panel/gauge/Thresholds.tsx index 72d21700421..e84247dc64e 100644 --- a/public/app/plugins/panel/gauge/Thresholds.tsx +++ b/public/app/plugins/panel/gauge/Thresholds.tsx @@ -1,7 +1,7 @@ import React, { PureComponent } from 'react'; +import classNames from 'classnames/bind'; import { PanelOptionsProps, Threshold } from 'app/types'; import { OptionsProps } from './module'; -import { Label } from '../../../core/components/Label/Label'; interface State { thresholds: Threshold[]; @@ -22,6 +22,7 @@ export default class Thresholds extends PureComponent { + console.log('add at index', index); const newThresholds = this.state.thresholds.map(threshold => { if (threshold.index >= index) { threshold = { ...threshold, index: threshold.index + 1 }; @@ -89,68 +90,70 @@ export default class Thresholds extends PureComponent - this.onChangeThresholdValue(event, thresholds[0])} - value={thresholds[0].value} - /> - - , -
-
this.onAddThreshold(1)} className="threshold-row-add"> - +
+
+
+ this.onChangeThresholdValue(event, thresholds[0])} + value={thresholds[0].value} + /> +
{thresholds[0].label}
-
, -
- this.onChangeThresholdValue(event, thresholds[1])} - value={thresholds[1].value} - /> - +
+
+
this.onAddThreshold(1)} className="threshold-row-add"> + +
+
Add new threshold by clicking the line.
+
+
, +
+
+
+ this.onChangeThresholdValue(event, thresholds[1])} + value={thresholds[1].value} + /> +
{thresholds[0].label}
+
, ]; } renderThresholds() { const { thresholds } = this.state; + return thresholds.map((threshold, index) => { + const rowStyle = classNames({ + 'threshold-row': true, + 'threshold-row-min': index === 0, + 'threshold-row-max': index === thresholds.length, + }); + return ( -
- this.onChangeThresholdValue(event, threshold)} - value={threshold.value} - onBlur={this.onBlur} - /> - {threshold.canRemove ? ( -
this.onRemoveThreshold(threshold)} - style={{ - display: 'flex', - alignItems: 'center', - justifyContent: 'center', - width: '36px', - height: '36px', - }} - > - -
- ) : ( - - )} +
+
+
+ this.onChangeThresholdValue(event, threshold)} + value={threshold.value} + onBlur={this.onBlur} + /> + {threshold.canRemove ? ( +
this.onRemoveThreshold(threshold)} className="threshold-row-remove"> + +
+ ) : ( +
{threshold.label}
+ )} +
); }); @@ -161,16 +164,9 @@ export default class Thresholds extends PureComponent 1 && index === this.state.thresholds.length) { - return index - 1; - } else if (index === 0) { - return 1; - } else if (index > 0) { - return index; } - // SAD - return -1; + return index; } renderIndicatorSection(index) { @@ -206,24 +202,20 @@ export default class Thresholds extends PureComponent
this.onAddThreshold(this.insertAtIndex(index - 1))} + onClick={() => this.onAddThreshold(this.insertAtIndex(index))} style={{ height: '50%', background: this.getIndicatorColor(index), }} - > - d -
+ />
this.onAddThreshold(this.insertAtIndex(index))} + onClick={() => this.onAddThreshold(this.insertAtIndex(index + 1))} style={{ height: `50%`, cursor: 'pointer', background: this.getIndicatorColor(index), }} - > - i -
+ />
); } diff --git a/public/sass/components/_thresholds.scss b/public/sass/components/_thresholds.scss index beb2a6e0f4f..9faf3a5d03b 100644 --- a/public/sass/components/_thresholds.scss +++ b/public/sass/components/_thresholds.scss @@ -9,6 +9,11 @@ } .threshold-row { + display: flex; + align-items: center; + margin: 5px 0; + padding: 5px; + &::before { font-family: 'FontAwesome'; content: '\f0d9'; @@ -16,8 +21,37 @@ } } +.threshold-row-inner { + border: 1px solid $input-label-border-color; + border-radius: $border-radius; + display: flex; + overflow: hidden; + width: 300px; + height: 37px; +} + +.threshold-row-color { + width: 36px; + border-right: 1px solid $input-label-border-color; +} + .threshold-row-input { - border-radius: $border-radius 0 0 $border-radius; + padding: 8px 10px; + width: 230px; +} + +.threshold-row-label { + background-color: $input-label-bg; + padding: 5px; + width: 36px; + display: flex; + align-items: center; +} + +.threshold-row-add-label { + align-items: center; + display: flex; + padding: 5px 8px; } .threshold-row-min { @@ -28,14 +62,20 @@ margin-bottom: -17px; } -.threshold-row-add { - border: $border-width solid $input-label-border-color; - border-radius: $border-radius 0 0 $border-radius; +.threshold-row-remove { + display: flex; + align-items: center; + justify-content: center; + width: 36px; + cursor: pointer; +} + +.threshold-row-add { + border-right: $border-width solid $input-label-border-color; display: flex; align-items: center; justify-content: center; width: 36px; - height: 36px; background-color: $green; }