UI - Update policies table pass/fail empty state logic (#17956)

## Addresses frontend portion of #17895 

![Screenshot 2024-03-28 at 4 27
25 PM](https://github.com/fleetdm/fleet/assets/61553566/ab8fb729-ed81-43a3-9777-26e87ea52435)

- [x] Manual QA for all new/changed functionality

Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
This commit is contained in:
Jacob Shandling 2024-03-29 10:07:19 -07:00 committed by GitHub
parent a8c80aadd3
commit 2682e411a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -345,13 +345,15 @@ const generateDataSet = (
// So, we need to add `osquery_policy` to the time of the cron update.
let policiesLastRun: Date;
let osqueryPolicyMs = 0;
const hostCountUpdatedAt =
const policiesThatHaveRunHostCountUpdatedAt =
// host counts of all policies that have run are updated at the same time, and are therefore
// identical, so we can use the first one. Those that haven't run will be `null`.
policiesList.find((p) => !!p.host_count_updated_at)
?.host_count_updated_at || "";
// If host_count_updated_at is not present, we assume the worst case.
const hostCountUpdateIntervalMs = 60 * 60 * 1000; // 1 hour (from server's `cron.go`)
const hostCountUpdatedAtDate = hostCountUpdatedAt
? new Date(hostCountUpdatedAt)
const hostCountUpdatedAtDate = policiesThatHaveRunHostCountUpdatedAt
? new Date(policiesThatHaveRunHostCountUpdatedAt)
: new Date(Date.now() - hostCountUpdateIntervalMs);
if (osquery_policy) {
// Convert from nanosecond to milliseconds
@ -360,13 +362,14 @@ const generateDataSet = (
hostCountUpdatedAtDate.getTime() - osqueryPolicyMs
);
} else {
// temporarily unused - will restore use with upcoming DB update
policiesLastRun = hostCountUpdatedAtDate;
}
// Now we figure out when the next host count update will be.
// The % (mod) is used below in case server was restarted and previously scheduled host count update was skipped.
const nextHostCountUpdateMs =
hostCountUpdateIntervalMs -
(hostCountUpdatedAt
(policiesThatHaveRunHostCountUpdatedAt
? (Date.now() - hostCountUpdatedAtDate.getTime()) %
hostCountUpdateIntervalMs
: 0);
@ -380,7 +383,14 @@ const generateDataSet = (
// Define policy has_run based on updated_at compared against last time policies ran.
const policyItemUpdatedAt = new Date(policyItem.updated_at);
policyItem.has_run = isAfter(policiesLastRun, policyItemUpdatedAt);
// TODO: restore and update setting of policyItem.has_run based on upcoming custom
// `policy_membership_updated_at`(ish) DB column/API response field
// policyItem.has_run = isAfter(policiesLastRun, policyItemUpdatedAt);
// all of the policiess `has_run` will be either true (cron has run, so host_count_updated_at
// has a value that is the same for all such policies) or false (policy is new, wasn't included
// in last cron run, host_count_updated_at is `null`)
policyItem.has_run = !!policyItem.host_count_updated_at;
if (!policyItem.has_run) {
// Include time for next update for reference in tooltip, which is only present if policy has not run.
policyItem.next_update_ms = nextPolicyUpdateMs(