From 299d6a351de7c80c7b189b85b4613a2b7fda97d6 Mon Sep 17 00:00:00 2001 From: Alex P Date: Mon, 12 Mar 2018 17:07:09 -0700 Subject: [PATCH] Refactor single stat colors UI into generic components --- ui/src/dashboards/components/GaugeOptions.js | 4 +- .../components/SingleStatOptions.js | 216 +----------------- ui/src/dashboards/components/Threshold.js | 14 +- .../shared/components/ThresholdColorToggle.js | 63 +++++ ui/src/shared/components/ThresholdsList.js | 184 +++++++++++++++ ui/src/style/chronograf.scss | 1 + .../style/components/threshold-controls.scss | 60 +++++ 7 files changed, 325 insertions(+), 217 deletions(-) create mode 100644 ui/src/shared/components/ThresholdColorToggle.js create mode 100644 ui/src/shared/components/ThresholdsList.js create mode 100644 ui/src/style/components/threshold-controls.scss diff --git a/ui/src/dashboards/components/GaugeOptions.js b/ui/src/dashboards/components/GaugeOptions.js index 2e75483d2..766e234ab 100644 --- a/ui/src/dashboards/components/GaugeOptions.js +++ b/ui/src/dashboards/components/GaugeOptions.js @@ -164,9 +164,9 @@ class GaugeOptions extends Component { >
Gauge Controls
-
+
- {singleStatColors.map( - color => - color.id === SINGLE_STAT_BASE - ?
-
Base Color
- -
- : - )} -
+
@@ -207,27 +55,7 @@ class SingleStatOptions extends Component { maxLength="5" />
-
- -
    -
  • - Background -
  • -
  • - Text -
  • -
-
+
@@ -235,47 +63,19 @@ class SingleStatOptions extends Component { } } -const {arrayOf, func, number, shape, string} = PropTypes - -SingleStatOptions.defaultProps = { - colors: [], -} +const {func, shape} = PropTypes SingleStatOptions.propTypes = { - singleStatType: string.isRequired, - singleStatColors: arrayOf( - shape({ - type: string.isRequired, - hex: string.isRequired, - id: string.isRequired, - name: string.isRequired, - value: number.isRequired, - }).isRequired - ), - handleUpdateSingleStatType: func.isRequired, - handleUpdateSingleStatColors: func.isRequired, handleUpdateAxes: func.isRequired, axes: shape({}).isRequired, onResetFocus: func.isRequired, } -const mapStateToProps = ({ - cellEditorOverlay: {singleStatType, singleStatColors, cell: {axes}}, -}) => ({ - singleStatType, - singleStatColors, +const mapStateToProps = ({cellEditorOverlay: {cell: {axes}}}) => ({ axes, }) const mapDispatchToProps = dispatch => ({ - handleUpdateSingleStatType: bindActionCreators( - updateSingleStatType, - dispatch - ), - handleUpdateSingleStatColors: bindActionCreators( - updateSingleStatColors, - dispatch - ), handleUpdateAxes: bindActionCreators(updateAxes, dispatch), }) diff --git a/ui/src/dashboards/components/Threshold.js b/ui/src/dashboards/components/Threshold.js index 06de69016..aa9f1edb3 100644 --- a/ui/src/dashboards/components/Threshold.js +++ b/ui/src/dashboards/components/Threshold.js @@ -53,14 +53,14 @@ class Threshold extends Component { const selectedColor = {hex, name} let label = 'Threshold' - let labelClass = 'gauge-controls--label-editable' + let labelClass = 'threshold-item--label__editable' let canBeDeleted = true if (visualizationType === 'gauge') { labelClass = isMin || isMax - ? 'gauge-controls--label' - : 'gauge-controls--label-editable' + ? 'threshold-item--label' + : 'threshold-item--label__editable' canBeDeleted = !(isMin || isMax) } @@ -72,17 +72,17 @@ class Threshold extends Component { } const inputClass = valid - ? 'form-control input-sm gauge-controls--input' - : 'form-control input-sm gauge-controls--input form-volcano' + ? 'form-control input-sm threshold-item--input' + : 'form-control input-sm threshold-item--input form-volcano' return ( -
+
{label}
{canBeDeleted ? + {singleStatColors.map( + color => + color.id === SINGLE_STAT_BASE + ?
+
Base Color
+ +
+ : + )} +
+ ) + } +} +const {arrayOf, func, number, shape, string} = PropTypes + +ThresholdsList.propTypes = { + singleStatType: string.isRequired, + singleStatColors: arrayOf( + shape({ + type: string.isRequired, + hex: string.isRequired, + id: string.isRequired, + name: string.isRequired, + value: number.isRequired, + }).isRequired + ), + handleUpdateSingleStatColors: func.isRequired, + onResetFocus: func.isRequired, +} + +const mapStateToProps = ({ + cellEditorOverlay: {singleStatType, singleStatColors}, +}) => ({ + singleStatType, + singleStatColors, +}) + +const mapDispatchToProps = dispatch => ({ + handleUpdateSingleStatColors: bindActionCreators( + updateSingleStatColors, + dispatch + ), +}) +export default connect(mapStateToProps, mapDispatchToProps)(ThresholdsList) diff --git a/ui/src/style/chronograf.scss b/ui/src/style/chronograf.scss index 0efcca69b..e00dc31a7 100644 --- a/ui/src/style/chronograf.scss +++ b/ui/src/style/chronograf.scss @@ -68,6 +68,7 @@ @import 'components/source-selector'; @import 'components/tables'; @import 'components/table-graph'; +@import 'components/threshold-controls'; @import 'components/kapacitor-logs-table'; // Pages diff --git a/ui/src/style/components/threshold-controls.scss b/ui/src/style/components/threshold-controls.scss new file mode 100644 index 000000000..96e13ced6 --- /dev/null +++ b/ui/src/style/components/threshold-controls.scss @@ -0,0 +1,60 @@ +/* + Threshold Controls + ------------------------------------------------------------------------------ + Used primarily within the Cell Editor Overlay for Single Stat, Gauge, + and Table type cells +*/ + +.thresholds-list { + display: flex; + flex-direction: column; + align-items: stretch; +} + +.threshold-item { + display: flex; + flex-wrap: nowrap; + align-items: center; + height: 30px; + margin-top: 8px; + + > * { + margin-left: 4px; + + &:first-child { + margin-left: 0; + } + } +} + +%threshold-item--label-styles { + height: 30px; + line-height: 30px; + font-weight: 600; + font-size: 13px; + padding: 0 11px; + border-radius: 4px; + @include no-user-select(); +} + +.threshold-item--label { + @extend %threshold-item--label-styles; + color: $g11-sidewalk; + background-color: $g4-onyx; + width: 120px; +} + +.threshold-item--label__editable { + @extend %threshold-item--label-styles; + color: $g16-pearl; + width: 90px; +} + +.threshold-item--input { + flex: 1 0 0; +} + +.threshold-item .color-dropdown.color-dropdown--stretch { + width: auto; + flex: 1 0 0; +}