fleet/frontend/components/LastUpdatedText/LastUpdatedText.tsx

57 lines
1.4 KiB
TypeScript
Raw Normal View History

import React from "react";
Add host's next maintenance window to the `hosts/{id}` and `hosts/identifier/{identifier}` endpoints, and render that data on the host details page (#19820) ## Addresses full stack for #18554 - Add new `timezone` column to `calendar_events` table - When fetched from Google's API, save calendar user's timezone in this new column along with rest of event data - Implement datastore method to retrieve the start time and timezone for a host's next calendar event as a `HostMaintenanceWindow` - Localize and add UTC offset to the `HostMaintenanceWindow`'s start time according to its `timezone` - Include the processed `HostMaintenanceWindow`, if present, in the response to the `GET` `hosts/{id}` and `hosts/identifier/{identifier}` endpoints - Implement UI on the host details page to display this data - Add new and update existing UI, core integration, datastore, and `fleetctl` tests - Update `date-fns` package to the latest version <img width="1062" alt="Screenshot 2024-06-26 at 1 02 34 PM" src="https://github.com/fleetdm/fleet/assets/61553566/c3ddad97-23da-42c1-b4ed-b7615ec88aed"> # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [x] Changes file added for user-visible changes in `changes/` - [x] Input data is properly validated, `SELECT *` is avoided, SQL injection is prevented (using placeholders for values in statements) - [x] Added/updated tests - [x] If database migrations are included, checked table schema to confirm autoupdate - For database migrations: - [x] Checked schema for all modified tables for columns that will auto-update timestamps during migration. - [x] Confirmed that updating the timestamps is acceptable, and will not cause unwanted side effects. - [x] Manual QA for all new/changed functionality --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2024-06-28 17:51:13 +00:00
import { formatDistanceToNowStrict } from "date-fns";
import { abbreviateTimeUnits } from "utilities/helpers";
import TooltipWrapper from "components/TooltipWrapper";
const baseClass = "component__last-updated-text";
interface ILastUpdatedTextBase {
lastUpdatedAt?: string | null;
}
interface ILastUpdatedTextWithCustomTooltip extends ILastUpdatedTextBase {
customTooltipText: React.ReactNode;
whatToRetrieve?: never;
}
interface ILastUpdatedTextWithWhatToRetrieve extends ILastUpdatedTextBase {
customTooltipText?: never;
whatToRetrieve: string;
}
const LastUpdatedText = ({
lastUpdatedAt,
whatToRetrieve,
customTooltipText,
}:
| ILastUpdatedTextWithCustomTooltip
| ILastUpdatedTextWithWhatToRetrieve): JSX.Element => {
if (!lastUpdatedAt || lastUpdatedAt === "0001-01-01T00:00:00Z") {
lastUpdatedAt = "never";
} else {
lastUpdatedAt = abbreviateTimeUnits(
formatDistanceToNowStrict(new Date(lastUpdatedAt), {
addSuffix: true,
})
);
}
const tooltipContent = customTooltipText || (
<>
Fleet periodically queries all hosts <br />
to retrieve {whatToRetrieve}.
</>
);
return (
<span className={baseClass}>
<TooltipWrapper tipContent={tooltipContent}>
{`Updated ${lastUpdatedAt}`}
</TooltipWrapper>
</span>
);
};
export default LastUpdatedText;