mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 08:58:41 +00:00
Fleet UI: Host details / Device user page last restart time bug (#6500)
This commit is contained in:
parent
1e4b76e6fd
commit
ed33a031db
5 changed files with 32 additions and 3 deletions
1
changes/issue-6467-fix-last-restarted-report-date
Normal file
1
changes/issue-6467-fix-last-restarted-report-date
Normal file
|
|
@ -0,0 +1 @@
|
|||
* Fix last restarted report date to be the sum of last updated at date and uptime
|
||||
|
|
@ -179,6 +179,7 @@ const DeviceUserPage = ({
|
|||
"primary_ip",
|
||||
"public_ip",
|
||||
"batteries",
|
||||
"detail_updated_at",
|
||||
])
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -343,6 +343,7 @@ const HostDetailsPage = ({
|
|||
"public_ip",
|
||||
"geolocation",
|
||||
"batteries",
|
||||
"detail_updated_at",
|
||||
])
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -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">
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue