Fleet UI: Host details / Device user page last restart time bug (#6500)

This commit is contained in:
RachelElysia 2022-07-06 13:56:31 -04:00 committed by GitHub
parent 1e4b76e6fd
commit ed33a031db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 3 deletions

View file

@ -0,0 +1 @@
* Fix last restarted report date to be the sum of last updated at date and uptime

View file

@ -179,6 +179,7 @@ const DeviceUserPage = ({
"primary_ip",
"public_ip",
"batteries",
"detail_updated_at",
])
);

View file

@ -343,6 +343,7 @@ const HostDetailsPage = ({
"public_ip",
"geolocation",
"batteries",
"detail_updated_at",
])
);

View file

@ -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 = ({
<div className="info-grid__block">
<span className="info-grid__header">Last restarted</span>
<span className="info-grid__data">
{wrapFleetHelper(humanHostUptime, aboutData.uptime)}
{humanHostLastRestart(
aboutData.detail_updated_at,
aboutData.uptime
)}
</span>
</div>
<div className="info-grid__block">
@ -193,7 +196,10 @@ const About = ({
<div className="info-grid__block">
<span className="info-grid__header">Last restarted</span>
<span className="info-grid__data">
{wrapFleetHelper(humanHostUptime, aboutData.uptime)}
{humanHostLastRestart(
aboutData.detail_updated_at,
aboutData.uptime
)}
</span>
</div>
<div className="info-grid__block">

View file

@ -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");
};