diff --git a/frontend/pages/hosts/HostDetailsPage/HostDetailsPage.jsx b/frontend/pages/hosts/HostDetailsPage/HostDetailsPage.jsx index cc88ba6a22..6ec8740a76 100644 --- a/frontend/pages/hosts/HostDetailsPage/HostDetailsPage.jsx +++ b/frontend/pages/hosts/HostDetailsPage/HostDetailsPage.jsx @@ -5,7 +5,7 @@ import classnames from "classnames"; import { Link } from "react-router"; import ReactTooltip from "react-tooltip"; -import { noop, pick } from "lodash"; +import { isEmpty, noop, pick, reduce } from "lodash"; import Spinner from "components/loaders/Spinner"; import Button from "components/buttons/Button"; @@ -434,41 +434,52 @@ export class HostDetailsPage extends Component { renderRefetch, } = this; - const titleData = pick(host, [ - "status", - "memory", - "host_cpu", - "os_version", - "enroll_secret_name", - "detail_updated_at", - ]); - const aboutData = pick(host, [ - "seen_time", - "uptime", - "last_enrolled_at", - "hardware_model", - "hardware_serial", - "primary_ip", - ]); - const osqueryData = pick(host, [ - "config_tls_refresh", - "logger_tls_period", - "distributed_interval", - ]); - const data = [titleData, aboutData, osqueryData]; - data.forEach((object) => { - Object.keys(object).forEach((key) => { - if (object[key] === "") { - object[key] = "--"; - } else if ( - key === "logger_tls_period" || - key === "config_tls_refresh" || - key === "distributed_interval" - ) { - object[key] = secondsToHms(object[key]); - } - }); - }); + const normalizeEmptyValues = (hostData) => { + return reduce( + hostData, + (result, value, key) => { + if ((Number.isFinite(value) && value !== 0) || !isEmpty(value)) { + Object.assign(result, { [key]: value }); + } else { + Object.assign(result, { [key]: "---" }); + } + return result; + }, + {} + ); + }; + + const wrapKolideHelper = (helperFn, value) => { + return value === "---" ? value : helperFn(value); + }; + + const titleData = normalizeEmptyValues( + pick(host, [ + "status", + "memory", + "host_cpu", + "os_version", + "enroll_secret_name", + "detail_updated_at", + ]) + ); + const aboutData = normalizeEmptyValues( + pick(host, [ + "seen_time", + "uptime", + "last_enrolled_at", + "hardware_model", + "hardware_serial", + "primary_ip", + ]) + ); + const osqueryData = normalizeEmptyValues( + pick(host, [ + "config_tls_refresh", + "logger_tls_period", + "distributed_interval", + ]) + ); const statusClassName = classnames("status", `status--${host.status}`); @@ -501,7 +512,9 @@ export class HostDetailsPage extends Component {
{`Last fetched ${humanHostDetailUpdated( titleData.detail_updated_at @@ -520,7 +533,7 @@ export class HostDetailsPage extends Component {