UI – Clarify expected behavior of policy host counts, dashboard controls software count, and controls os updates versions count (#25150)

## For #23512 

<img width="1392" alt="Screenshot 2025-01-03 at 4 13 33 PM"
src="https://github.com/user-attachments/assets/0244a2db-eb97-4cf6-b50f-fd7567e14e40"
/>

<img width="860" alt="Screenshot 2025-01-03 at 3 59 56 PM"
src="https://github.com/user-attachments/assets/cc2e6adb-ac09-4f02-8e1b-4df060e90de8"
/>

<img width="1392" alt="Screenshot 2025-01-03 at 4 14 40 PM"
src="https://github.com/user-attachments/assets/316c359e-4081-4858-b890-f8d6c8052934"
/>

- [x] Changes file added for user-visible changes in `changes/`
- [x] Manual QA for all new/changed functionality

---------

Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
This commit is contained in:
jacobshandling 2025-01-06 10:55:28 -08:00 committed by GitHub
parent e1af322b73
commit aef4bb579e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 68 additions and 62 deletions

View file

@ -0,0 +1,2 @@
- Clarify expected behavior of policy host counts, dashboard controls software count, and controls
os updates versions count.

View file

@ -322,7 +322,15 @@ const DashboardPage = ({ router, location }: IDashboardProps): JSX.Element => {
setSoftwareTitleDetail( setSoftwareTitleDetail(
<LastUpdatedText <LastUpdatedText
lastUpdatedAt={data.counts_updated_at} lastUpdatedAt={data.counts_updated_at}
whatToRetrieve="software" customTooltipText={
<>
Fleet periodically queries all hosts to
<br />
retrieve software. Click to view
<br />
hosts for the most up-to-date lists.
</>
}
/> />
); );
setShowSoftwareCard(true); setShowSoftwareCard(true);

View file

@ -81,7 +81,17 @@ const CurrentVersionSection = ({
return ( return (
<LastUpdatedText <LastUpdatedText
lastUpdatedAt={data?.counts_updated_at} lastUpdatedAt={data?.counts_updated_at}
whatToRetrieve="operating systems" customTooltipText={
<>
Fleet periodically queries all hosts to
<br />
retrieve operating systems. Click to
<br />
view hosts for the most up-to-date
<br />
lists.
</>
}
/> />
); );
}; };

View file

@ -4,6 +4,7 @@ import { useQuery } from "react-query";
import { InjectedRouter } from "react-router/lib/Router"; import { InjectedRouter } from "react-router/lib/Router";
import PATHS from "router/paths"; import PATHS from "router/paths";
import { isEqual } from "lodash"; import { isEqual } from "lodash";
import { formatDistanceToNowStrict } from "date-fns";
import { getNextLocationPath, wait } from "utilities/helpers"; import { getNextLocationPath, wait } from "utilities/helpers";
@ -44,6 +45,7 @@ import Spinner from "components/Spinner";
import TeamsDropdown from "components/TeamsDropdown"; import TeamsDropdown from "components/TeamsDropdown";
import TableDataError from "components/DataError"; import TableDataError from "components/DataError";
import MainContent from "components/MainContent"; import MainContent from "components/MainContent";
import LastUpdatedText from "components/LastUpdatedText";
import PoliciesTable from "./components/PoliciesTable"; import PoliciesTable from "./components/PoliciesTable";
import OtherWorkflowsModal from "./components/OtherWorkflowsModal"; import OtherWorkflowsModal from "./components/OtherWorkflowsModal";
@ -776,22 +778,43 @@ const ManagePolicyPage = ({
} }
} }
const renderPoliciesCount = (count?: number) => { const renderPoliciesCountAndLastUpdated = (
count?: number,
policies?: IPolicyStats[]
) => {
// Hide count if fetching count || there are errors OR there are no policy results with no a search filter // Hide count if fetching count || there are errors OR there are no policy results with no a search filter
const isFetchingCount = !isAllTeamsSelected const isFetchingCount = !isAllTeamsSelected
? isFetchingTeamCountMergeInherited ? isFetchingTeamCountMergeInherited
: isFetchingGlobalCount; : isFetchingGlobalCount;
const hideCount = const hide =
isFetchingCount || isFetchingCount ||
policiesErrors || policiesErrors ||
(!policyResults && searchQuery === ""); (!policyResults && searchQuery === "");
if (hideCount) { if (hide) {
return null; return null;
} }
// Figure the time since the host counts were updated by finding first policy item with host_count_updated_at.
const updatedAt =
policies?.find((p) => !!p.host_count_updated_at)?.host_count_updated_at ||
"";
return <TableCount name="policies" count={count} />; return (
<>
<TableCount name="policies" count={count} />
<LastUpdatedText
lastUpdatedAt={updatedAt}
customTooltipText={
<>
Counts are updated hourly. Click host
<br />
counts for the most up-to-date count.
</>
}
/>
</>
);
}; };
const renderMainTable = () => { const renderMainTable = () => {
@ -815,7 +838,12 @@ const ManagePolicyPage = ({
currentTeam={currentTeamSummary} currentTeam={currentTeamSummary}
currentAutomatedPolicies={currentAutomatedPolicies} currentAutomatedPolicies={currentAutomatedPolicies}
isPremiumTier={isPremiumTier} isPremiumTier={isPremiumTier}
renderPoliciesCount={() => renderPoliciesCount(globalPoliciesCount)} renderPoliciesCount={() =>
renderPoliciesCountAndLastUpdated(
globalPoliciesCount,
globalPolicies
)
}
searchQuery={searchQuery} searchQuery={searchQuery}
sortHeader={sortHeader} sortHeader={sortHeader}
sortDirection={sortDirection} sortDirection={sortDirection}
@ -844,7 +872,10 @@ const ManagePolicyPage = ({
currentTeam={currentTeamSummary} currentTeam={currentTeamSummary}
currentAutomatedPolicies={currentAutomatedPolicies} currentAutomatedPolicies={currentAutomatedPolicies}
renderPoliciesCount={() => renderPoliciesCount={() =>
renderPoliciesCount(teamPoliciesCountMergeInherited) renderPoliciesCountAndLastUpdated(
teamPoliciesCountMergeInherited,
teamPolicies
)
} }
isPremiumTier={isPremiumTier} isPremiumTier={isPremiumTier}
searchQuery={searchQuery} searchQuery={searchQuery}

View file

@ -295,4 +295,8 @@
} }
} }
} }
.component__last-updated-text {
font-weight: normal;
}
} }

View file

@ -1,37 +1,20 @@
import Icon from "components/Icon"; import Icon from "components/Icon";
import React from "react"; import React from "react";
import TooltipWrapper from "components/TooltipWrapper";
interface IPassingColumnHeaderProps { interface IPassingColumnHeaderProps {
isPassing: boolean; isPassing: boolean;
timeSinceHostCountUpdate: string;
} }
const baseClass = "passing-column-header"; const baseClass = "passing-column-header";
const PassingColumnHeader = ({ const PassingColumnHeader = ({ isPassing }: IPassingColumnHeaderProps) => {
isPassing,
timeSinceHostCountUpdate,
}: IPassingColumnHeaderProps) => {
const iconName = isPassing ? "success" : "error"; const iconName = isPassing ? "success" : "error";
const columnText = isPassing ? "Yes" : "No"; const columnText = isPassing ? "Yes" : "No";
const updateText = timeSinceHostCountUpdate
? `Host count updated ${timeSinceHostCountUpdate}.`
: "";
return ( return (
<div className={baseClass}> <div className={baseClass}>
<Icon name={iconName} /> <Icon name={iconName} />
<TooltipWrapper <span className="status-header-text">{columnText}</span>
tipContent={
<>
{updateText}
<br /> Counts are updated hourly.
</>
}
>
<span className="status-header-text">{columnText}</span>
</TooltipWrapper>
</div> </div>
); );
}; };

View file

@ -97,7 +97,6 @@ const PoliciesTable = ({
selectedTeamId: currentTeam?.id, selectedTeamId: currentTeam?.id,
hasPermissionAndPoliciesToDelete, hasPermissionAndPoliciesToDelete,
}, },
policiesList,
isPremiumTier isPremiumTier
)} )}
data={generateDataSet( data={generateDataSet(

View file

@ -2,11 +2,7 @@
// disable this rule as it was throwing an error in Header and Cell component // disable this rule as it was throwing an error in Header and Cell component
// definitions for the selection row for some reason when we dont really need it. // definitions for the selection row for some reason when we dont really need it.
import React from "react"; import React from "react";
import { import { millisecondsToHours, millisecondsToMinutes } from "date-fns";
formatDistanceToNowStrict,
millisecondsToHours,
millisecondsToMinutes,
} from "date-fns";
import { Tooltip as ReactTooltip5 } from "react-tooltip-5"; import { Tooltip as ReactTooltip5 } from "react-tooltip-5";
// @ts-ignore // @ts-ignore
import Checkbox from "components/forms/fields/Checkbox"; import Checkbox from "components/forms/fields/Checkbox";
@ -91,27 +87,10 @@ const generateTableHeaders = (
hasPermissionAndPoliciesToDelete?: boolean; hasPermissionAndPoliciesToDelete?: boolean;
tableType?: string; tableType?: string;
}, },
policiesList: IPolicyStats[] = [],
isPremiumTier?: boolean isPremiumTier?: boolean
): IDataColumn[] => { ): IDataColumn[] => {
const { selectedTeamId, hasPermissionAndPoliciesToDelete } = options; const { selectedTeamId, hasPermissionAndPoliciesToDelete } = options;
const viewingTeamPolicies = selectedTeamId !== -1; const viewingTeamPolicies = selectedTeamId !== -1;
// Figure the time since the host counts were updated.
// First, find first policy item with host_count_updated_at.
const updatedAt =
policiesList.find((p) => !!p.host_count_updated_at)
?.host_count_updated_at || "";
let timeSinceHostCountUpdate = "";
if (updatedAt) {
try {
timeSinceHostCountUpdate = formatDistanceToNowStrict(
new Date(updatedAt),
{ addSuffix: true }
);
} catch (e) {
// Do nothing.
}
}
const tableHeaders: IDataColumn[] = [ const tableHeaders: IDataColumn[] = [
{ {
@ -170,12 +149,7 @@ const generateTableHeaders = (
title: "Yes", title: "Yes",
Header: (cellProps) => ( Header: (cellProps) => (
<HeaderCell <HeaderCell
value={ value={<PassingColumnHeader isPassing />}
<PassingColumnHeader
isPassing
timeSinceHostCountUpdate={timeSinceHostCountUpdate}
/>
}
isSortedDesc={cellProps.column.isSortedDesc} isSortedDesc={cellProps.column.isSortedDesc}
/> />
), ),
@ -221,12 +195,7 @@ const generateTableHeaders = (
title: "No", title: "No",
Header: (cellProps) => ( Header: (cellProps) => (
<HeaderCell <HeaderCell
value={ value={<PassingColumnHeader isPassing={false} />}
<PassingColumnHeader
isPassing={false}
timeSinceHostCountUpdate={timeSinceHostCountUpdate}
/>
}
isSortedDesc={cellProps.column.isSortedDesc} isSortedDesc={cellProps.column.isSortedDesc}
/> />
), ),