import { IAggregateMacSettingsStatus } from "interfaces/mdm"; import MacSettingsIndicator from "pages/hosts/details/MacSettingsIndicator"; import React from "react"; import { useQuery } from "react-query"; import paths from "router/paths"; import mdmAPI from "services/entities/mdm"; import { buildQueryStringFromParams } from "utilities/url"; const baseClass = "aggregate-mac-settings-indicators"; interface AggregateMacSettingsIndicatorsProps { teamId: number; } const AggregateMacSettingsIndicators = ({ teamId, }: AggregateMacSettingsIndicatorsProps) => { const AGGREGATE_STATUS_DISPLAY_OPTIONS = { latest: { text: "Latest", iconName: "success", tooltipText: "Hosts that applied the latest settings.", }, pending: { text: "Pending", iconName: "pending", tooltipText: "Hosts that haven’t applied the latest settings because they are asleep, disconnected from the internet, or require action.", }, failing: { text: "Failing", iconName: "error", tooltipText: "Hosts that failed to apply the latest settings. View hosts to see errors.", }, } as const; const { data: aggregateProfileStatusesResponse, } = useQuery( ["aggregateProfileStatuses", teamId], () => mdmAPI.getAggregateProfileStatuses(teamId), { refetchOnWindowFocus: false } ); const DISPLAY_ORDER = ["latest", "pending", "failing"] as const; const orderedResponseKVArr: [ keyof IAggregateMacSettingsStatus, number ][] = aggregateProfileStatusesResponse ? DISPLAY_ORDER.map((key) => { return [key, aggregateProfileStatusesResponse[key]]; }) : []; const indicators = orderedResponseKVArr.map(([status, count]) => { const { text, iconName, tooltipText } = AGGREGATE_STATUS_DISPLAY_OPTIONS[ status ]; return (
{/* NOTE - below will be renamed as a general component and moved into the components dir by Gabe */} {count} hosts
); }); return
{indicators}
; }; export default AggregateMacSettingsIndicators;