2022-02-28 21:25:06 +00:00
|
|
|
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";
|
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";
|
|
|
|
|
|
2024-06-27 13:41:35 +00:00
|
|
|
interface ILastUpdatedTextBase {
|
2025-08-29 15:08:04 +00:00
|
|
|
lastUpdatedAt?: string | null;
|
2024-06-27 13:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface ILastUpdatedTextWithCustomTooltip extends ILastUpdatedTextBase {
|
|
|
|
|
customTooltipText: React.ReactNode;
|
|
|
|
|
whatToRetrieve?: never;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface ILastUpdatedTextWithWhatToRetrieve extends ILastUpdatedTextBase {
|
|
|
|
|
customTooltipText?: never;
|
2022-07-20 16:39:19 +00:00
|
|
|
whatToRetrieve: string;
|
|
|
|
|
}
|
2024-06-27 13:41:35 +00:00
|
|
|
|
2022-07-20 16:39:19 +00:00
|
|
|
const LastUpdatedText = ({
|
|
|
|
|
lastUpdatedAt,
|
|
|
|
|
whatToRetrieve,
|
2024-06-27 13:41:35 +00:00
|
|
|
customTooltipText,
|
|
|
|
|
}:
|
|
|
|
|
| ILastUpdatedTextWithCustomTooltip
|
|
|
|
|
| ILastUpdatedTextWithWhatToRetrieve): 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
|
|
|
}
|
|
|
|
|
|
2024-06-27 13:41:35 +00:00
|
|
|
const tooltipContent = customTooltipText || (
|
|
|
|
|
<>
|
|
|
|
|
Fleet periodically queries all hosts <br />
|
|
|
|
|
to retrieve {whatToRetrieve}.
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
|
2022-02-28 21:25:06 +00:00
|
|
|
return (
|
|
|
|
|
<span className={baseClass}>
|
2024-06-27 13:41:35 +00:00
|
|
|
<TooltipWrapper tipContent={tooltipContent}>
|
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;
|