From 86e0529212ca28156447d21b6ec2635f6318ffbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Leal?= <37.joao.leal@gmail.com> Date: Thu, 8 Jul 2021 16:35:39 +0100 Subject: [PATCH] fix: CSS clean up due to some orphan styling --- lib/machine-loader.js | 62 +++++++++---------- .../machineActions/MachineActions.styles.js | 51 +-------------- .../src/pages/Machines/Machines.styles.js | 33 +--------- .../Maintenance/MachineDetailsCard.styles.js | 30 +-------- 4 files changed, 33 insertions(+), 143 deletions(-) diff --git a/lib/machine-loader.js b/lib/machine-loader.js index 0f1a5727..0da73a82 100644 --- a/lib/machine-loader.js +++ b/lib/machine-loader.js @@ -12,6 +12,10 @@ const settingsLoader = require('./new-settings-loader') const notifierUtils = require('./notifier/utils') const notifierQueries = require('./notifier/queries') +const fullyFunctionalStatus = { label: 'Fully functional', type: 'success' } +const unresponsiveStatus = { label: 'Unresponsive', type: 'error' } +const stuckStatus = { label: 'Stuck', type: 'error' } + function getMachines () { return db.any('SELECT * FROM devices WHERE display=TRUE ORDER BY created') .then(rr => rr.map(r => ({ @@ -36,11 +40,32 @@ function getConfig (defaultConfig) { return settingsLoader.loadLatest().config } -function getMachineNames (config) { - const fullyFunctionalStatus = { label: 'Fully functional', type: 'success' } - const unresponsiveStatus = { label: 'Unresponsive', type: 'error' } - const stuckStatus = { label: 'Stuck', type: 'error' } +const getStatus = (ping, stuck) => { + if (ping && ping.age) return unresponsiveStatus + if (stuck && stuck.age) return stuckStatus + + return fullyFunctionalStatus +} + +function addName (pings, events, config) { + return machine => { + const cashOutConfig = configManager.getCashOut(machine.deviceId, config) + + const cashOut = !!cashOutConfig.active + + const statuses = [ + getStatus( + _.first(pings[machine.deviceId]), + _.first(checkStuckScreen(events, machine.name)) + ) + ] + + return _.assign(machine, { cashOut, statuses }) + } +} + +function getMachineNames (config) { return Promise.all([getMachines(), getConfig(config), getNetworkHeartbeat(), getNetworkPerformance()]) .then(([rawMachines, config, heartbeat, performance]) => Promise.all( [rawMachines, checkPings(rawMachines), dbm.machineEvents(), config, heartbeat, performance] @@ -92,10 +117,6 @@ function getMachineName (machineId) { } function getMachine (machineId, config) { - const fullyFunctionalStatus = { label: 'Fully functional', type: 'success' } - const unresponsiveStatus = { label: 'Unresponsive', type: 'error' } - const stuckStatus = { label: 'Stuck', type: 'error' } - const sql = 'SELECT * FROM devices WHERE device_id=$1' const queryMachine = db.oneOrNone(sql, [machineId]).then(r => ({ deviceId: r.device_id, @@ -113,31 +134,8 @@ function getMachine (machineId, config) { return Promise.all([queryMachine, dbm.machineEvents(), config]) .then(([machine, events, config]) => { const pings = checkPings([machine]) - - const getStatus = (ping, stuck) => { - if (ping && ping.age) return unresponsiveStatus - if (stuck && stuck.age) return stuckStatus - - return fullyFunctionalStatus - } - - const addName = r => { - const cashOutConfig = configManager.getCashOut(r.deviceId, config) - - const cashOut = !!cashOutConfig.active - - const statuses = [ - getStatus( - _.first(pings[r.deviceId]), - _.first(checkStuckScreen(events, r.name)) - ) - ] - - return _.assign(r, { cashOut, statuses }) - } - - return addName(machine) + return [machine].map(addName(pings, events, config))[0] }) } diff --git a/new-lamassu-admin/src/components/machineActions/MachineActions.styles.js b/new-lamassu-admin/src/components/machineActions/MachineActions.styles.js index 91bfd465..dcbacf40 100644 --- a/new-lamassu-admin/src/components/machineActions/MachineActions.styles.js +++ b/new-lamassu-admin/src/components/machineActions/MachineActions.styles.js @@ -1,24 +1,9 @@ -import { fade } from '@material-ui/core/styles/colorManipulator' - import typographyStyles from 'src/components/typography/styles' -import { - offColor, - spacer, - comet, - primaryColor, - fontSize4, - errorColor -} from 'src/styling/variables' +import { offColor, spacer, errorColor } from 'src/styling/variables' const { label1 } = typographyStyles const machineActionsStyles = { - colDivider: { - width: 1, - margin: [[spacer * 2, spacer * 4]], - backgroundColor: comet, - border: 'none' - }, label: { extend: label1, color: offColor, @@ -33,44 +18,10 @@ const machineActionsStyles = { flexWrap: 'wrap', justifyContent: 'start' }, - wrapper: { - display: 'flex', - marginTop: 12, - marginBottom: 16, - fontSize: fontSize4 - }, - row: { - display: 'flex', - flexDirection: 'row' - }, - list: { - padding: 0, - margin: 0, - listStyle: 'none' - }, - item: { - height: spacer * 3, - marginBottom: spacer * 1.5 - }, - link: { - color: primaryColor, - textDecoration: 'none' - }, - divider: { - margin: '0 1rem' - }, mr: { marginRight: spacer, marginBottom: spacer }, - separator: { - width: 1, - height: 170, - zIndex: 1, - marginRight: 60, - marginLeft: 'auto', - background: fade(comet, 0.5) - }, warning: { color: errorColor } diff --git a/new-lamassu-admin/src/pages/Machines/Machines.styles.js b/new-lamassu-admin/src/pages/Machines/Machines.styles.js index f0e1ad63..d338147d 100644 --- a/new-lamassu-admin/src/pages/Machines/Machines.styles.js +++ b/new-lamassu-admin/src/pages/Machines/Machines.styles.js @@ -1,10 +1,4 @@ -import { - spacer, - fontPrimary, - primaryColor, - white, - comet -} from 'src/styling/variables' +import { spacer, comet } from 'src/styling/variables' const styles = { grid: { @@ -18,16 +12,6 @@ const styles = { marginLeft: spacer * 6, maxWidth: 900 }, - footer: { - margin: [['auto', 0, spacer * 3, 'auto']] - }, - modalTitle: { - lineHeight: '120%', - color: primaryColor, - fontSize: 14, - fontFamily: fontPrimary, - fontWeight: 900 - }, subtitle: { display: 'flex', justifyContent: 'space-between', @@ -39,15 +23,6 @@ const styles = { color: comet, marginTop: 0 }, - white: { - color: white - }, - deleteButton: { - paddingLeft: 13 - }, - addressRow: { - marginLeft: 8 - }, row: { display: 'flex', flexDirection: 'row', @@ -60,16 +35,10 @@ const styles = { detailItem: { marginBottom: spacer * 4 }, - transactionsItem: { - marginBottom: -spacer * 4 - }, actionButtonsContainer: { display: 'flex', flexDirection: 'row' }, - actionButton: { - marginRight: 8 - }, breadcrumbsContainer: { marginTop: 32 }, diff --git a/new-lamassu-admin/src/pages/Maintenance/MachineDetailsCard.styles.js b/new-lamassu-admin/src/pages/Maintenance/MachineDetailsCard.styles.js index 33cfa009..f1c64f3b 100644 --- a/new-lamassu-admin/src/pages/Maintenance/MachineDetailsCard.styles.js +++ b/new-lamassu-admin/src/pages/Maintenance/MachineDetailsCard.styles.js @@ -4,29 +4,10 @@ import { detailsRowStyles, labelStyles } from 'src/pages/Transactions/Transactions.styles' -import { - spacer, - comet, - primaryColor, - fontSize4, - errorColor -} from 'src/styling/variables' +import { spacer, comet, primaryColor, fontSize4 } from 'src/styling/variables' const machineDetailsStyles = { ...detailsRowStyles, - colDivider: { - width: 1, - margin: [[spacer * 2, spacer * 4]], - backgroundColor: comet, - border: 'none' - }, - inlineChip: { - marginInlineEnd: '0.25em' - }, - stack: { - display: 'flex', - flexDirection: 'row' - }, wrapper: { display: 'flex', // marginTop: 24, @@ -53,12 +34,6 @@ const machineDetailsStyles = { color: primaryColor, textDecoration: 'none' }, - divider: { - margin: '0 1rem' - }, - mr: { - marginRight: spacer - }, separator: { width: 1, height: 170, @@ -66,9 +41,6 @@ const machineDetailsStyles = { marginRight: 60, marginLeft: 'auto', background: fade(comet, 0.5) - }, - warning: { - color: errorColor } }