2022-02-28 21:25:06 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import formatDistanceToNowStrict from "date-fns/formatDistanceToNowStrict";
|
2022-04-22 16:45:35 +00:00
|
|
|
import { abbreviateTimeUnits } from "utilities/helpers";
|
2022-02-28 21:25:06 +00:00
|
|
|
|
|
|
|
|
import TooltipWrapper from "components/TooltipWrapper";
|
|
|
|
|
|
|
|
|
|
const baseClass = "component__last-updated-text";
|
|
|
|
|
|
2022-07-20 16:39:19 +00:00
|
|
|
interface ILastUpdatedTextProps {
|
|
|
|
|
lastUpdatedAt: string;
|
|
|
|
|
whatToRetrieve: string;
|
|
|
|
|
}
|
|
|
|
|
const LastUpdatedText = ({
|
|
|
|
|
lastUpdatedAt,
|
|
|
|
|
whatToRetrieve,
|
|
|
|
|
}: ILastUpdatedTextProps): JSX.Element => {
|
2022-02-28 21:25:06 +00:00
|
|
|
if (!lastUpdatedAt || lastUpdatedAt === "0001-01-01T00:00:00Z") {
|
|
|
|
|
lastUpdatedAt = "never";
|
|
|
|
|
} else {
|
2022-04-07 19:12:38 +00:00
|
|
|
lastUpdatedAt = abbreviateTimeUnits(
|
|
|
|
|
formatDistanceToNowStrict(new Date(lastUpdatedAt), {
|
|
|
|
|
addSuffix: true,
|
|
|
|
|
})
|
|
|
|
|
);
|
2022-02-28 21:25:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<span className={baseClass}>
|
|
|
|
|
<TooltipWrapper
|
2022-08-05 13:21:02 +00:00
|
|
|
tipContent={`Fleet periodically queries all hosts <br />to retrieve ${whatToRetrieve}.`}
|
2022-02-28 21:25:06 +00:00
|
|
|
>
|
2022-04-07 19:12:38 +00:00
|
|
|
{`Updated ${lastUpdatedAt}`}
|
2022-02-28 21:25:06 +00:00
|
|
|
</TooltipWrapper>
|
|
|
|
|
</span>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2022-07-20 16:39:19 +00:00
|
|
|
export default LastUpdatedText;
|