From ed33a031db5680a7bee253952c206eef85e9d54a Mon Sep 17 00:00:00 2001 From: RachelElysia <71795832+RachelElysia@users.noreply.github.com> Date: Wed, 6 Jul 2022 13:56:31 -0400 Subject: [PATCH] Fleet UI: Host details / Device user page last restart time bug (#6500) --- .../issue-6467-fix-last-restarted-report-date | 1 + .../details/DeviceUserPage/DeviceUserPage.tsx | 1 + .../HostDetailsPage/HostDetailsPage.tsx | 1 + .../pages/hosts/details/cards/About/About.tsx | 12 ++++++++--- frontend/utilities/helpers.ts | 20 +++++++++++++++++++ 5 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 changes/issue-6467-fix-last-restarted-report-date diff --git a/changes/issue-6467-fix-last-restarted-report-date b/changes/issue-6467-fix-last-restarted-report-date new file mode 100644 index 0000000000..a2e1003209 --- /dev/null +++ b/changes/issue-6467-fix-last-restarted-report-date @@ -0,0 +1 @@ +* Fix last restarted report date to be the sum of last updated at date and uptime diff --git a/frontend/pages/hosts/details/DeviceUserPage/DeviceUserPage.tsx b/frontend/pages/hosts/details/DeviceUserPage/DeviceUserPage.tsx index 005f6ab36f..febc070086 100644 --- a/frontend/pages/hosts/details/DeviceUserPage/DeviceUserPage.tsx +++ b/frontend/pages/hosts/details/DeviceUserPage/DeviceUserPage.tsx @@ -179,6 +179,7 @@ const DeviceUserPage = ({ "primary_ip", "public_ip", "batteries", + "detail_updated_at", ]) ); diff --git a/frontend/pages/hosts/details/HostDetailsPage/HostDetailsPage.tsx b/frontend/pages/hosts/details/HostDetailsPage/HostDetailsPage.tsx index da4058a6a1..7ebd333831 100644 --- a/frontend/pages/hosts/details/HostDetailsPage/HostDetailsPage.tsx +++ b/frontend/pages/hosts/details/HostDetailsPage/HostDetailsPage.tsx @@ -343,6 +343,7 @@ const HostDetailsPage = ({ "public_ip", "geolocation", "batteries", + "detail_updated_at", ]) ); diff --git a/frontend/pages/hosts/details/cards/About/About.tsx b/frontend/pages/hosts/details/cards/About/About.tsx index 67b93e76d8..02bdce1b77 100644 --- a/frontend/pages/hosts/details/cards/About/About.tsx +++ b/frontend/pages/hosts/details/cards/About/About.tsx @@ -3,7 +3,7 @@ import React from "react"; import ReactTooltip from "react-tooltip"; import { IMDMData, IMunkiData, IDeviceUser } from "interfaces/host"; -import { humanHostUptime, humanHostEnrolled } from "utilities/helpers"; +import { humanHostLastRestart, humanHostEnrolled } from "utilities/helpers"; interface IAboutProps { aboutData: { [key: string]: any }; @@ -159,7 +159,10 @@ const About = ({
Last restarted - {wrapFleetHelper(humanHostUptime, aboutData.uptime)} + {humanHostLastRestart( + aboutData.detail_updated_at, + aboutData.uptime + )}
@@ -193,7 +196,10 @@ const About = ({
Last restarted - {wrapFleetHelper(humanHostUptime, aboutData.uptime)} + {humanHostLastRestart( + aboutData.detail_updated_at, + aboutData.uptime + )}
diff --git a/frontend/utilities/helpers.ts b/frontend/utilities/helpers.ts index 7a984a61a0..2b29e58235 100644 --- a/frontend/utilities/helpers.ts +++ b/frontend/utilities/helpers.ts @@ -591,6 +591,26 @@ export const humanHostUptime = (uptimeInNanoseconds: number): string => { return formatDistanceToNow(new Date(restartDate), { addSuffix: true }); }; +export const humanHostLastRestart = ( + detailUpdatedAt: string, + uptime: number +): string => { + const currentDate = new Date(); + const updatedDate = new Date(detailUpdatedAt); + const millisecondsLastUpdated = currentDate.getTime() - updatedDate.getTime(); + + // Sum of calculated milliseconds since last updated with uptime + const millisecondsLastRestart = + millisecondsLastUpdated + uptime / NANOSECONDS_PER_MILLISECOND; + + const restartDate = new Date(); + restartDate.setMilliseconds( + restartDate.getMilliseconds() - millisecondsLastRestart + ); + + return formatDistanceToNow(new Date(restartDate), { addSuffix: true }); +}; + export const humanHostLastSeen = (lastSeen: string): string => { return format(new Date(lastSeen), "MMM d yyyy, HH:mm:ss"); };