From db014a3ed4b2520ebd7bf806708cbd4be7e217ec Mon Sep 17 00:00:00 2001 From: Mauricio Navarro Miranda Date: Mon, 13 Jul 2020 15:25:43 -0500 Subject: [PATCH] fix: machine status layout bugs fix: reboot icon looks cropped fix: confirm dialog layout fix: Status chip background colors fix: detailed machine status layout fix: machine detailed status layout fix: machine status article links, status chip size fix: confirmDialog for all machine actions fix: confirm dialog on every action. reload when success fix: verbose input label fix: display software version and machine model fix: eslint fixes fix: removed machine version and update button fix: get machines statuses from ping chore: removed the support articles until they're ready fix: reset value and error states when closing the confirm dialog fix: removed unused info from the machine table styles: fixed styles in the machine details card chore: moved styles to another file fix: fixed the version gql property --- lib/machine-loader.js | 33 ++- lib/notifier.js | 6 +- .../src/components/ConfirmDialog.js | 96 +++---- new-lamassu-admin/src/components/Status.js | 21 +- .../pages/Maintenance/MachineDetailsCard.js | 244 ++++++++++-------- .../Maintenance/MachineDetailsCard.styles.js | 72 +++--- .../src/pages/Maintenance/MachineStatus.js | 16 +- .../src/styling/icons/button/reboot/white.svg | 2 +- .../styling/icons/button/reboot/zodiac.svg | 2 +- 9 files changed, 278 insertions(+), 214 deletions(-) diff --git a/lib/machine-loader.js b/lib/machine-loader.js index a3197be6..72a24ce3 100644 --- a/lib/machine-loader.js +++ b/lib/machine-loader.js @@ -4,6 +4,8 @@ const axios = require('axios') const logger = require('./logger') const db = require('./db') const pairing = require('./pairing') +const notifier = require('./notifier') +const dbm = require('./postgresql_interface') const configManager = require('./new-config-manager') const settingsLoader = require('./new-settings-loader') @@ -34,15 +36,40 @@ function getConfig (defaultConfig) { } function getMachineNames (config) { + const fullyFunctionalStatus = {label: 'Fully functional', type: 'success'} + const unresponsiveStatus = {label: 'Unresponsive', type: 'error'} + const stuckStatus = {label: 'Stuck', type: 'error'} + return Promise.all([getMachines(), getConfig(config)]) - .then(([machines, config]) => { + .then(([machines, config]) => Promise.all( + [machines, notifier.checkPings(machines), dbm.machineEvents(), config] + )) + .then(([machines, pings, events, config]) => { + const getPingStatus = (ping) => { + if (!ping) return fullyFunctionalStatus + + if (ping.age) return unresponsiveStatus + + return fullyFunctionalStatus + } + + const getStuckStatus = (stuck) => { + if (!stuck || !stuck.age) return undefined + + return stuckStatus + } + const addName = r => { const cashOutConfig = configManager.getCashOut(r.deviceId, config) const cashOut = !!cashOutConfig.active - // TODO new-admin actually load status based on ping. - const statuses = [{label: 'Unknown detailed status', type: 'warning'}] + const ping = getPingStatus(_.first(pings[r.deviceId])) + const stuck = getStuckStatus(_.first(notifier.checkStuckScreen(events, r.name))) + + const statuses = [ping] + + if (stuck) statuses.push(stuck) return _.assign(r, {cashOut, statuses}) } diff --git a/lib/notifier.js b/lib/notifier.js index 5413062f..96941bea 100644 --- a/lib/notifier.js +++ b/lib/notifier.js @@ -344,4 +344,8 @@ function buildAlertFingerprint (alertRec, notifications) { return crypto.createHash('sha256').update(subject).digest('hex') } -module.exports = { checkNotification } +module.exports = { + checkNotification, + checkPings, + checkStuckScreen +} diff --git a/new-lamassu-admin/src/components/ConfirmDialog.js b/new-lamassu-admin/src/components/ConfirmDialog.js index da195f55..e24a330e 100644 --- a/new-lamassu-admin/src/components/ConfirmDialog.js +++ b/new-lamassu-admin/src/components/ConfirmDialog.js @@ -2,51 +2,50 @@ import { Dialog, DialogActions, DialogContent, - DialogContentText, makeStyles } from '@material-ui/core' -import React, { useEffect, useState, memo } from 'react' +import React, { memo, useState } from 'react' import { Button, IconButton } from 'src/components/buttons' +import { TextInput } from 'src/components/inputs' +import { H4 } from 'src/components/typography' import { ReactComponent as CloseIcon } from 'src/styling/icons/action/close/zodiac.svg' -import { fontSize3 } from 'src/styling/variables' +import { spacer } from 'src/styling/variables' -import { TextInput } from './inputs' -import { H4, P } from './typography' +import ErrorMessage from './ErrorMessage' const useStyles = makeStyles({ - label: { - fontSize: fontSize3 + dialogContent: { + width: 434, + padding: spacer * 2, + paddingRight: spacer * 3.5 }, - spacing: { - padding: 32 + dialogTitle: { + padding: spacer * 2, + paddingRight: spacer * 1.5, + display: 'flex', + 'justify-content': 'space-between', + '& > h4': { + margin: 0 + }, + '& > button': { + padding: 0, + marginTop: -(spacer / 2) + } }, - wrapper: { - display: 'flex' - }, - title: { - margin: [[20, 0, 24, 16]] - }, - closeButton: { - padding: 0, - margin: [[12, 12, 'auto', 'auto']] - // position: 'absolute', - // right: spacer, - // top: spacer + dialogActions: { + padding: spacer * 4, + paddingTop: spacer * 2 } }) export const DialogTitle = ({ children, onClose }) => { const classes = useStyles() return ( -
+
{children} {onClose && ( - + )} @@ -57,50 +56,59 @@ export const DialogTitle = ({ children, onClose }) => { export const ConfirmDialog = memo( ({ title = 'Confirm action', - subtitle = 'This action requires confirmation', + errorMessage = 'This action requires confirmation', open, toBeConfirmed, onConfirmed, onDissmised, - className, ...props }) => { const classes = useStyles() const [value, setValue] = useState('') const [error, setError] = useState(false) - useEffect(() => setValue(''), [open]) - const handleChange = event => { - setValue(event.target.value) + const handleChange = event => setValue(event.target.value) + + const innerOnClose = () => { + setValue('') + setError(false) + onDissmised() } return ( - -

{title}

- {subtitle && ( - -

{subtitle}

-
- )} + +

{title}

- + {errorMessage && ( + + + {errorMessage.split(':').map(error => ( + <> + {error} +
+ + ))} +
+
+ )} + setError(toBeConfirmed !== value)} /> - +