From 1dab3ccd0b30204d03b9bc64ac0feddce589d018 Mon Sep 17 00:00:00 2001 From: slice Date: Wed, 18 Jul 2018 17:48:16 -0700 Subject: [PATCH] general code cleanup/refactoring --- priv/frontend/src/components/Dashboard.js | 89 +++++++++++-------- .../frontend/src/components/DegradedNotice.js | 4 +- priv/frontend/src/components/Incident.js | 4 +- priv/frontend/src/components/Service.js | 4 +- .../src/components/ServicePlaceholder.css | 20 +++++ .../src/components/ServicePlaceholder.js | 55 ++++++------ priv/frontend/src/components/Stage.js | 6 +- priv/frontend/src/components/Status.js | 4 +- 8 files changed, 104 insertions(+), 82 deletions(-) diff --git a/priv/frontend/src/components/Dashboard.js b/priv/frontend/src/components/Dashboard.js index 8753363..8771c07 100644 --- a/priv/frontend/src/components/Dashboard.js +++ b/priv/frontend/src/components/Dashboard.js @@ -35,6 +35,7 @@ export default class Dashboard extends Component { const endpoint = `${DOMAIN}/api/streaming` .replace('https', 'wss') .replace('http', 'ws') + this.client = new StreamingClient(endpoint, this.state.metrics) this.client.connect() @@ -110,50 +111,62 @@ export default class Dashboard extends Component { this.setState({ incident: await resp.json() }) } - render () { - let metrics = null + renderNotice (services) { + const down = services.filter(([, { status }]) => !status) - if (this.state.metrics) { - const allServices = Object.entries(this.state.metrics.status) - const graphs = this.state.metrics.graph - - const services = allServices.map(([name, info]) => ( - - )) - - const down = allServices.filter(([, { status }]) => !status) - let notice = - if (!this.state.incident && down.length > 0) { - notice = down.length > 0 - ? - : null - } - - metrics = ( -
- {notice} - {services} -
- ) + // DegradedNotice should only be shown when there is no ongoing incident, + // and any services are reported as down. + if (!this.state.incident && down.length > 0) { + return } + return + } + + renderServices (services) { + const { graph: graphs } = this.state.metrics + return services.map(([name, info]) => ( + + )) + } + + renderPlaceholders () { + return ( + + + + + + ) + } + + renderDashboardContent () { + if (this.state.error) { + return
{this.state.error}
+ } + + if (this.state.loading) { + return this.renderPlaceholders() + } + + const allServices = Object.entries(this.state.metrics.status) + + const services = this.renderServices(allServices) + const notice = this.renderNotice(allServices) + + return ( + + {notice} + {services} + + ) + } + + render () { return (

elstatus

- - {this.state.error ? ( -
- {this.state.error} -
- ) : null} - - {this.state.loading && !this.state.error ? ( - - - - - - ) : metrics} + {this.renderDashboardContent()}
) } diff --git a/priv/frontend/src/components/DegradedNotice.js b/priv/frontend/src/components/DegradedNotice.js index fe5e088..885ec88 100644 --- a/priv/frontend/src/components/DegradedNotice.js +++ b/priv/frontend/src/components/DegradedNotice.js @@ -3,7 +3,7 @@ import PropTypes from 'prop-types' import './DegradedNotice.css' -const DegradedNotice = ({ services }) => { +export default function DegradedNotice ({ services }) { const keys = Object.keys(services) const serviceNames = keys.join(', ') @@ -23,5 +23,3 @@ const DegradedNotice = ({ services }) => { DegradedNotice.propTypes = { services: PropTypes.object.isRequired, } - -export default DegradedNotice diff --git a/priv/frontend/src/components/Incident.js b/priv/frontend/src/components/Incident.js index 88f789c..b61504d 100644 --- a/priv/frontend/src/components/Incident.js +++ b/priv/frontend/src/components/Incident.js @@ -12,7 +12,7 @@ const OUTAGE_TYPES = { degraded_service: 'Degraded Service', } -const Incident = ({ incident }) => { +export default function Incident ({ incident }) { const { content, end_date: end, start_date: start, title, type, stages } = incident const ago = ms(Date.now() - start * 1000) const agoEnd = end ? ms(Date.now - end * 1000) : null @@ -51,5 +51,3 @@ Incident.propTypes = { stages: PropTypes.array, }), } - -export default Incident diff --git a/priv/frontend/src/components/Service.js b/priv/frontend/src/components/Service.js index e14dfdd..5349c63 100644 --- a/priv/frontend/src/components/Service.js +++ b/priv/frontend/src/components/Service.js @@ -38,7 +38,7 @@ function getServiceState (status, latency) { return status ? 'alive' : 'dead' } -const Service = ({ graph, name, status, latency, description }) => { +export default function Service ({ graph, name, status, latency, description }) { const state = getServiceState(status, latency) const title = titles[state] @@ -81,5 +81,3 @@ Service.propTypes = { latency: PropTypes.number, description: PropTypes.string.isRequired, } - -export default Service diff --git a/priv/frontend/src/components/ServicePlaceholder.css b/priv/frontend/src/components/ServicePlaceholder.css index 0bcc6ed..d457594 100644 --- a/priv/frontend/src/components/ServicePlaceholder.css +++ b/priv/frontend/src/components/ServicePlaceholder.css @@ -7,3 +7,23 @@ grid-template-columns: 3rem 1fr; grid-gap: 1rem; } + +.service-placeholder .emoji { + width: 3rem !important; + height: 3rem !important; +} + +.service-placeholder .name { + width: 100% !important; + height: 3rem !important; +} + +.service-placeholder .text { + margin-top: 1rem !important; +} + +.service-placeholder .graph { + width: 100% !important; + height: 175px !important; + margin-top: 1rem !important; +} diff --git a/priv/frontend/src/components/ServicePlaceholder.js b/priv/frontend/src/components/ServicePlaceholder.js index 80ba7dd..236090f 100644 --- a/priv/frontend/src/components/ServicePlaceholder.js +++ b/priv/frontend/src/components/ServicePlaceholder.js @@ -5,45 +5,44 @@ import 'react-placeholder/lib/reactPlaceholder.css' import './ServicePlaceholder.css' -const ServicePlaceholder = () => ( -
-
+export default function ServicePlaceholder () { + return ( +
+
+ + {' '} + + + {' '} + +
{' '} {' '}
- - {' '} - - - {' '} - -
-) - -export default ServicePlaceholder + ) +} diff --git a/priv/frontend/src/components/Stage.js b/priv/frontend/src/components/Stage.js index cc8ae67..fe3a258 100644 --- a/priv/frontend/src/components/Stage.js +++ b/priv/frontend/src/components/Stage.js @@ -3,7 +3,7 @@ import PropTypes from 'prop-types' import ms from 'ms' -const Stage = ({ stage }) => { +export default function Stage ({ stage }) { const { created_at: createdAt, title, content } = stage const ago = ms(Date.now() - createdAt * 1000) @@ -21,7 +21,5 @@ Stage.propTypes = { created_at: PropTypes.number, title: PropTypes.string, content: PropTypes.string, - }) + }), } - -export default Stage diff --git a/priv/frontend/src/components/Status.js b/priv/frontend/src/components/Status.js index fada855..6fe1d86 100644 --- a/priv/frontend/src/components/Status.js +++ b/priv/frontend/src/components/Status.js @@ -5,7 +5,7 @@ import classnames from 'classnames' import './Status.css' import Incident from './Incident' -const Status = ({ incident }) => { +export default function Status ({ incident }) { let view = null if (incident) { view = @@ -27,5 +27,3 @@ const Status = ({ incident }) => { Status.propTypes = { incident: PropTypes.object, } - -export default Status