Skip to content

Commit bb5921f

Browse files
[Web UI] Use cron value in check list (#1910)
Signed-off-by: James Phillips <jamesdphillips@gmail.com>
1 parent 7bfce36 commit bb5921f

5 files changed

Lines changed: 88 additions & 20 deletions

File tree

dashboard/src/components/partials/CheckDetailsContainer/CheckDetailsContainer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class CheckDetailsContainer extends React.PureComponent {
102102
if (interval > 0) {
103103
return `Every ${interval}s`;
104104
} else if (cron && cron.length > 0) {
105-
return <CronDescriptor expression={cron} />;
105+
return <CronDescriptor capitalize expression={cron} />;
106106
}
107107
return "Never";
108108
}

dashboard/src/components/partials/ChecksList/ChecksListItem.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import gql from "graphql-tag";
55
import Checkbox from "@material-ui/core/Checkbox";
66
import Code from "/components/Code";
77
import ConfirmDelete from "/components/partials/ConfirmDelete";
8+
import CronDescriptor from "/components/partials/CronDescriptor";
89
import IconButton from "@material-ui/core/IconButton";
910
import Menu from "@material-ui/core/Menu";
1011
import MenuController from "/components/controller/MenuController";
@@ -36,6 +37,7 @@ class CheckListItem extends React.Component {
3637
command
3738
subscriptions
3839
interval
40+
cron
3941
isSilenced
4042
namespace {
4143
organization
@@ -85,9 +87,17 @@ class CheckListItem extends React.Component {
8587
<React.Fragment>
8688
<Code>{check.command}</Code>
8789
<br />
88-
Executed every{" "}
90+
Executed{" "}
8991
<strong>
90-
{check.interval} {check.interval === 1 ? "second" : "seconds"}
92+
{check.interval ? (
93+
`
94+
every
95+
${check.interval}
96+
${check.interval === 1 ? "second" : "seconds"}
97+
`
98+
) : (
99+
<CronDescriptor expression={check.cron} />
100+
)}
91101
</strong>{" "}
92102
by{" "}
93103
<strong>

dashboard/src/components/partials/CronDescriptor/CronDescriptor.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
11
import React from "react";
22
import PropTypes from "prop-types";
3+
import lowerFirst from "lodash/lowerFirst";
34
import cronstrue from "cronstrue";
45
import Tooltip from "@material-ui/core/Tooltip";
56

67
class CronDescriptor extends React.PureComponent {
78
static propTypes = {
9+
capitalize: PropTypes.bool,
810
expression: PropTypes.string.isRequired,
911
component: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
1012
};
1113

1214
static defaultProps = {
15+
capitalize: false,
1316
component: "span",
1417
};
1518

1619
render() {
17-
const { expression, component: Component } = this.props;
18-
const statement = cronstrue.toString(expression);
20+
const { capitalize, expression, component: Component } = this.props;
21+
22+
let statement = cronstrue.toString(expression);
23+
if (!capitalize) {
24+
statement = lowerFirst(statement);
25+
}
1926

2027
return (
2128
<Tooltip title={expression}>

dashboard/src/components/partials/EventsList/EventsListItem.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ class EventListItem extends React.PureComponent {
5454
name
5555
output
5656
isSilenced
57+
history(first: 1) {
58+
status
59+
}
5760
}
5861
entity {
5962
name
@@ -121,8 +124,16 @@ class EventListItem extends React.PureComponent {
121124
const { selected, event } = this.props;
122125
const { entity, check, timestamp } = event;
123126

127+
// Try to determine if the failing check just started failing and if so
128+
// highlight the row.
129+
const incidentStarted =
130+
check.status > 0 &&
131+
check.history.length > 0 &&
132+
check.history[0].status !== check.status &&
133+
new Date(new Date(timestamp).valueOf() + 2500) >= new Date();
134+
124135
return (
125-
<TableSelectableRow selected={selected}>
136+
<TableSelectableRow selected={selected} highlight={incidentStarted}>
126137
<TableCell padding="checkbox">
127138
<Checkbox
128139
color="primary"

dashboard/src/components/partials/TableSelectableRow/TableSelectableRow.js

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,74 @@ import { withStyles } from "@material-ui/core/styles";
55

66
import TableRow from "@material-ui/core/TableRow";
77

8-
const styles = theme => ({
9-
root: {
10-
verticalAlign: "top",
8+
const styles = theme => {
9+
const transitionIn = `
10+
background-color
11+
${theme.transitions.duration.shortest}ms
12+
${theme.transitions.easing.sharp}
13+
`;
14+
const transitionOut = `
15+
background-color
16+
${theme.transitions.duration.complex}ms
17+
${theme.transitions.easing.easeOut}
18+
`;
1119

12-
// hover
20+
return {
21+
root: {
22+
verticalAlign: "top",
23+
transition: transitionOut,
24+
25+
// hover
26+
// https://material.io/guidelines/components/data-tables.html#data-tables-interaction
27+
"&:hover": {
28+
backgroundColor: theme.palette.action.hover,
29+
transition: transitionIn,
30+
},
31+
},
32+
// selected
1333
// https://material.io/guidelines/components/data-tables.html#data-tables-interaction
14-
"&:hover": {
15-
backgroundColor: theme.palette.action.selected,
34+
selected: {
35+
backgroundColor: theme.palette.action.hover,
36+
transition: transitionIn,
37+
},
38+
highlight: {
39+
animation: `
40+
${theme.transitions.duration.complex}ms
41+
${theme.transitions.easing.easeInOut}
42+
0s
43+
alternate
44+
2
45+
selectable-row-highlight
46+
`,
47+
},
48+
"@keyframes selectable-row-highlight": {
49+
"0%": {
50+
backgroundColor: "inherit",
51+
},
52+
"100%": {
53+
backgroundColor: theme.palette.action.hover,
54+
},
1655
},
17-
},
18-
// selected
19-
// https://material.io/guidelines/components/data-tables.html#data-tables-interaction
20-
selected: {
21-
backgroundColor: theme.palette.action.hover,
22-
},
23-
});
56+
};
57+
};
2458

2559
class TableSelectableRow extends React.PureComponent {
2660
static propTypes = {
2761
selected: PropTypes.bool.isRequired,
2862
children: PropTypes.node.isRequired,
2963
classes: PropTypes.object.isRequired,
64+
highlight: PropTypes.bool,
65+
};
66+
67+
static defaultProps = {
68+
highlight: false,
3069
};
3170

3271
render() {
33-
const { classes, selected, children, ...props } = this.props;
72+
const { classes, selected, children, highlight, ...props } = this.props;
3473
const className = classnames(classes.root, {
3574
[classes.selected]: selected,
75+
[classes.highlight]: highlight,
3676
});
3777

3878
return (

0 commit comments

Comments
 (0)