Manage Host UI: Convert uptime column to last restarted (#6812)

This commit is contained in:
RachelElysia 2022-07-25 09:37:12 -04:00 committed by GitHub
parent 345b0a0cd2
commit 6ec08b405b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 16 deletions

View file

@ -0,0 +1 @@
* Convert uptime column to last restarted on the Manage hosts page

View file

@ -15,7 +15,7 @@ import StatusCell from "components/TableContainer/DataTable/StatusCell/StatusCel
import TextCell from "components/TableContainer/DataTable/TextCell/TextCell";
import {
humanHostMemory,
humanHostUptime,
humanHostLastRestart,
humanHostLastSeen,
humanHostDetailUpdated,
hostTeamName,
@ -324,7 +324,7 @@ const allHostTableHeaders: IDataColumn[] = [
Cell: (cellProps: ICellProps) => <TextCell value={cellProps.cell.value} />,
},
{
title: "Uptime",
title: "Last restarted",
Header: (cellProps: IHeaderProps) => (
<HeaderCell
value={cellProps.column.title}
@ -332,9 +332,13 @@ const allHostTableHeaders: IDataColumn[] = [
/>
),
accessor: "uptime",
Cell: (cellProps: ICellProps) => (
<TextCell value={cellProps.cell.value} formatter={humanHostUptime} />
),
Cell: (cellProps: ICellProps) => {
const { uptime, detail_updated_at } = cellProps.row.original;
return (
<TextCell value={humanHostLastRestart(detail_updated_at, uptime)} />
);
},
},
{
title: "CPU",

View file

@ -580,16 +580,6 @@ export const inMilliseconds = (nanoseconds: number): number => {
return nanoseconds / NANOSECONDS_PER_MILLISECOND;
};
export const humanHostUptime = (uptimeInNanoseconds: number): string => {
const uptimeMilliseconds = inMilliseconds(uptimeInNanoseconds);
const restartDate = new Date();
restartDate.setMilliseconds(
restartDate.getMilliseconds() - uptimeMilliseconds
);
return formatDistanceToNow(new Date(restartDate), { addSuffix: true });
};
export const humanHostLastRestart = (
detailUpdatedAt: string,
uptime: number
@ -817,7 +807,6 @@ export default {
generateRole,
generateTeam,
greyCell,
humanHostUptime,
humanHostLastSeen,
humanHostEnrolled,
humanHostMemory,