mirror of
https://github.com/fleetdm/fleet
synced 2026-04-27 08:27:42 +00:00
related to #9402 and #9404 Implements UI for toggling off and on fleet mdm disk encryption management and also the disk encryption aggregate data tables. **Toggling disk encryption:**  **disk encryption aggregate:**  - [x] Changes file added for user-visible changes in `changes/` or `orbit/changes/`. - [x] Manual QA for all new/changed functionality
84 lines
2.5 KiB
TypeScript
84 lines
2.5 KiB
TypeScript
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<IAggregateMacSettingsStatus>(
|
||
["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 (
|
||
<div className="aggregate-mac-settings-indicator">
|
||
{/* NOTE - below will be renamed as a general component and moved into the components dir by Gabe */}
|
||
<MacSettingsIndicator
|
||
indicatorText={text}
|
||
iconName={iconName}
|
||
tooltip={{ tooltipText, position: "top" }}
|
||
/>
|
||
<a
|
||
href={`${paths.MANAGE_HOSTS}?${buildQueryStringFromParams({
|
||
team_id: teamId,
|
||
macos_settings: status,
|
||
})}`}
|
||
>
|
||
{count} hosts
|
||
</a>
|
||
</div>
|
||
);
|
||
});
|
||
|
||
return <div className={baseClass}>{indicators}</div>;
|
||
};
|
||
|
||
export default AggregateMacSettingsIndicators;
|