ReactUI: replace togglers tabs with checkboxes (#6543)

* replace togglers tabs with checkboxes

Signed-off-by: blalov <boiskila@gmail.com>

* create state-color tuples config for checkboxes rendering

Signed-off-by: blalov <boiskila@gmail.com>

* separate filters from show-annotations checkbox

Signed-off-by: blalov <boiskila@gmail.com>

* style improvements

Signed-off-by: blalov <boiskila@gmail.com>

* lint fix

Signed-off-by: blalov <boiskila@gmail.com>

* style adjustments

Signed-off-by: blalov <boiskila@gmail.com>
This commit is contained in:
Boyko 2020-01-07 17:12:38 +02:00 committed by Julius Volz
parent 4708915ac6
commit 1637ad2717
2 changed files with 139 additions and 122 deletions

View file

@ -1,5 +1,5 @@
.panel { .panel {
margin-bottom: 20px; margin-bottom: 20px;
} }
input[type='checkbox']:checked + label { input[type='checkbox']:checked + label {
@ -8,219 +8,232 @@ input[type='checkbox']:checked + label {
.custom-control-label { .custom-control-label {
cursor: pointer; cursor: pointer;
font-size: .875rem; }
line-height: 1.8;
.togglers-wrapper .form-group {
margin-bottom: 0.5rem;
}
[for$='-toggler'].custom-control-label::before,
[for$='-toggler'].custom-control-label::after {
top: 0.28rem;
left: -1.3rem;
width: 1.12rem;
height: 1.12rem;
} }
.capitalize-title::first-letter { .capitalize-title::first-letter {
text-transform: capitalize; text-transform: capitalize;
} }
.expression-input { .expression-input {
margin-bottom: 10px; margin-bottom: 10px;
} }
.expression-input textarea { .expression-input textarea {
/* font-family: Menlo,Monaco,Consolas,'Courier New',monospace; */ /* font-family: Menlo,Monaco,Consolas,'Courier New',monospace; */
resize: none; resize: none;
overflow: hidden; overflow: hidden;
} }
button.execute-btn { button.execute-btn {
width: 84px; width: 84px;
} }
.alert.alert-danger { .alert.alert-danger {
margin-bottom: 10px; margin-bottom: 10px;
} }
.nav-tabs .nav-link { .nav-tabs .nav-link {
cursor: pointer; cursor: pointer;
} }
.tab-content { .tab-content {
border-left: 1px solid #dee2e6; border-left: 1px solid #dee2e6;
border-right: 1px solid #dee2e6; border-right: 1px solid #dee2e6;
border-bottom: 1px solid #dee2e6; border-bottom: 1px solid #dee2e6;
padding: 10px; padding: 10px;
} }
.tab-content .alert { .tab-content .alert {
margin-bottom: 0; margin-bottom: 0;
} }
.data-table.table { .data-table.table {
margin: 10px 0 2px 0; margin: 10px 0 2px 0;
} }
.data-table > tbody > tr > td { .data-table > tbody > tr > td {
padding: 5px 0 5px 8px; padding: 5px 0 5px 8px;
font-size: 0.8em; font-size: 0.8em;
overflow: hidden; overflow: hidden;
} }
.autosuggest-dropdown { .autosuggest-dropdown {
position: absolute; position: absolute;
border: 1px solid #ced4da; border: 1px solid #ced4da;
background-color: #fff; background-color: #fff;
color: #495057; color: #495057;
font-size: 1rem; font-size: 1rem;
z-index: 1000; z-index: 1000;
left: 56px; left: 56px;
margin-top: -6px; margin-top: -6px;
} }
.autosuggest-dropdown-list { .autosuggest-dropdown-list {
padding: 0; padding: 0;
margin: 0; margin: 0;
list-style: none; list-style: none;
} }
.autosuggest-dropdown-list li { .autosuggest-dropdown-list li {
width: 100%; width: 100%;
padding: .25rem 1.5rem; padding: 0.25rem 1.5rem;
clear: both; clear: both;
white-space: nowrap; white-space: nowrap;
background-color: transparent; background-color: transparent;
border: 0; border: 0;
display: block; display: block;
} }
.autosuggest-dropdown-list li.autosuggest-dropdown-header { .autosuggest-dropdown-list li.autosuggest-dropdown-header {
background-color: #bfdeff; background-color: #bfdeff;
font-size: 10px; font-size: 10px;
line-height: 1.5; line-height: 1.5;
text-transform: uppercase; text-transform: uppercase;
text-align: center; text-align: center;
} }
.graph-controls, .table-controls { .graph-controls,
margin-bottom: 10px; .table-controls {
margin-bottom: 10px;
} }
.graph-controls input, .table-controls input { .graph-controls input,
text-align: center; .table-controls input {
text-align: center;
} }
.graph-controls .range-input input { .graph-controls .range-input input {
width: 50px; width: 50px;
} }
.time-input input { .time-input input {
border-right: none; border-right: none;
} }
.time-input { .time-input {
width: 270px !important; width: 270px !important;
} }
.graph-controls input.resolution-input { .graph-controls input.resolution-input {
width: 90px; width: 90px;
} }
.graph-controls > :not(:first-child) { .graph-controls > :not(:first-child) {
margin-left: 20px; margin-left: 20px;
} }
.graph-controls .clear-time-btn, .table-controls .clear-time-btn { .graph-controls .clear-time-btn,
background: #fff; .table-controls .clear-time-btn {
border-left: none; background: #fff;
border-top: 1px solid #ced4da; border-left: none;
border-bottom: 1px solid #ced4da; border-top: 1px solid #ced4da;
color: #495057; border-bottom: 1px solid #ced4da;
color: #495057;
} }
.graph-legend { .graph-legend {
margin: 15px 0 15px 55px; margin: 15px 0 15px 55px;
font-size: 0.75em; font-size: 0.75em;
padding: 10px 5px; padding: 10px 5px;
display: inline-block; display: inline-block;
} }
.legend-item { .legend-item {
cursor: pointer; cursor: pointer;
display: flex; display: flex;
align-items: center; align-items: center;
padding: 0 5px; padding: 0 5px;
border-radius: 3px; border-radius: 3px;
} }
.legend-swatch { .legend-swatch {
width: 7px; width: 7px;
height: 7px; height: 7px;
outline-offset: 1px; outline-offset: 1px;
outline: 1.5px solid #ccc; outline: 1.5px solid #ccc;
margin: 2px 8px 2px 0; margin: 2px 8px 2px 0;
display: inline-block; display: inline-block;
} }
.legend-item:hover { .legend-item:hover {
background: rgba(0, 0, 0, 0.18); background: rgba(0, 0, 0, 0.18);
} }
.legend-metric-name { .legend-metric-name {
margin-right: 1px; margin-right: 1px;
} }
.legend-label-name { .legend-label-name {
font-weight: bold; font-weight: bold;
} }
.graph { .graph {
margin: 0 5px 0 5px; margin: 0 5px 0 5px;
} }
.graph-chart { .graph-chart {
height: 500px; height: 500px;
width: 100%; width: 100%;
/* This is picked up by Flot's axis label font renderer, /* This is picked up by Flot's axis label font renderer,
which ignores "color" and uses "fill" instead. */ which ignores "color" and uses "fill" instead. */
fill: #495057; fill: #495057;
font-size: 0.8em; font-size: 0.8em;
} }
.graph-chart .flot-overlay { .graph-chart .flot-overlay {
cursor: crosshair; cursor: crosshair;
} }
.graph-tooltip { .graph-tooltip {
background: rgba(0,0,0,.8); background: rgba(0, 0, 0, 0.8);
color: #fff; color: #fff;
font-family: Arial, Helvetica, sans-serif; font-family: Arial, Helvetica, sans-serif;
font-size: 12px; font-size: 12px;
white-space: nowrap; white-space: nowrap;
padding: 8px; padding: 8px;
border-radius: 3px; border-radius: 3px;
} }
.graph-tooltip .labels { .graph-tooltip .labels {
font-size: 11px; font-size: 11px;
line-height: 11px; line-height: 11px;
} }
.graph-tooltip .detail-swatch { .graph-tooltip .detail-swatch {
display: inline-block; display: inline-block;
width: 10px; width: 10px;
height: 10px; height: 10px;
} }
.add-panel-btn { .add-panel-btn {
margin-bottom: 20px; margin-bottom: 20px;
} }
.target-head { .target-head {
font-weight: 700; font-weight: 700;
font-size: large; font-size: large;
} }
.status-badges { .status-badges {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
margin-bottom: 10px; margin-bottom: 10px;
padding: 10px; padding: 10px;
} }
.badges-wrapper > span { .badges-wrapper > span {
margin-right: 5px; margin-right: 5px;
max-height: 20px; max-height: 20px;
} }

View file

@ -1,5 +1,5 @@
import React, { FC, useState, Fragment } from 'react'; import React, { FC, useState, Fragment } from 'react';
import { ButtonGroup, Button, Row, Badge } from 'reactstrap'; import { Badge } from 'reactstrap';
import CollapsibleAlertPanel from './CollapsibleAlertPanel'; import CollapsibleAlertPanel from './CollapsibleAlertPanel';
import Checkbox from '../../Checkbox'; import Checkbox from '../../Checkbox';
import { isPresent } from '../../utils/func'; import { isPresent } from '../../utils/func';
@ -44,6 +44,12 @@ interface RuleGroup {
interval: number; interval: number;
} }
const stateColorTuples: Array<[RuleState, 'success' | 'warning' | 'danger']> = [
['inactive', 'success'],
['pending', 'warning'],
['firing', 'danger'],
];
const AlertsContent: FC<AlertsProps> = ({ groups = [], statsCount }) => { const AlertsContent: FC<AlertsProps> = ({ groups = [], statsCount }) => {
const [state, setState] = useState<RuleStatus<boolean>>({ const [state, setState] = useState<RuleStatus<boolean>>({
firing: true, firing: true,
@ -61,26 +67,24 @@ const AlertsContent: FC<AlertsProps> = ({ groups = [], statsCount }) => {
return ( return (
<> <>
<ButtonGroup className="mb-3"> <div className="d-flex togglers-wrapper">
<Button active={state.inactive} onClick={toggle('inactive')} color="primary"> {stateColorTuples.map(([state, color]) => {
Inactive ({statsCount.inactive}) return (
</Button> <Checkbox wrapperStyles={{ marginRight: 10 }} defaultChecked id={`${state}-toggler`} onClick={toggle(state)}>
<Button active={state.pending} onClick={toggle('pending')} color="primary"> <Badge color={color} className="text-capitalize">
Pending ({statsCount.pending}) {state} ({statsCount[state]})
</Button> </Badge>
<Button active={state.firing} onClick={toggle('firing')} color="primary"> </Checkbox>
Firing ({statsCount.firing}) );
</Button> })}
</ButtonGroup>
<Row className="mb-2">
<Checkbox <Checkbox
id="show-annotations" wrapperStyles={{ marginLeft: 'auto' }}
wrapperStyles={{ margin: '0 0 0 15px', alignSelf: 'center' }} id="show-annotations-toggler"
onClick={() => setShowAnnotations(!showAnnotations)} onClick={() => setShowAnnotations(!showAnnotations)}
> >
Show annotations <span style={{ fontSize: '0.9rem', lineHeight: 1.9 }}>Show annotations</span>
</Checkbox> </Checkbox>
</Row> </div>
{groups.map((group, i) => { {groups.map((group, i) => {
return ( return (
<Fragment key={i}> <Fragment key={i}>