fleet/frontend/pages/hosts/details/OSSettingsModal/OSSettingsTable/OSSettingStatusCell/helpers.ts
Magnus Jensen 90f75f1644
simplify OS modal (#43252)
<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #40702 

New look:
<img width="812" height="350" alt="image"
src="https://github.com/user-attachments/assets/83e82480-b756-4c51-be3f-09a72e736770"
/>


# Checklist for submitter

If some of the following don't apply, delete the relevant line.

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files)
for more information.

- [x] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements), JS
inline code is prevented especially for url redirects, and untrusted
data interpolated into shell scripts/commands is validated against shell
metacharacters.
- [x] Timeouts are implemented and retries are limited to avoid infinite
loops
- [x] If paths of existing endpoints are modified without backwards
compatibility, checked the frontend/CLI for any necessary changes

## Testing

- [x] Added/updated automated tests
- [x] QA'd all new/changed functionality manually


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Simplified pending status labels in OS Settings modal by removing
"(pending)" suffix from states like "Enforcing" and "Removing
enforcement"
  * Improved OS Settings modal table layout and styling

* **New Features**
* Added dedicated action buttons to resend MDM profiles and rotate
Recovery Lock password
  * Enhanced error tooltip handling for failed profile states

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-04-09 16:30:15 -05:00

202 lines
6.3 KiB
TypeScript

import {
FLEET_FILEVAULT_PROFILE_DISPLAY_NAME,
ProfileOperationType,
RecoveryLockPasswordStatus,
} from "interfaces/mdm";
import { IconNames } from "components/icons";
import {
TooltipInnerContentFunc,
TooltipInnerContentOption,
} from "./components/Tooltip/TooltipContent";
import { OsSettingsTableStatusValue } from "../OSSettingsTableConfig";
import TooltipInnerContentActionRequired from "./components/Tooltip/ActionRequired";
export const isDiskEncryptionProfile = (profileName: string) => {
return profileName === FLEET_FILEVAULT_PROFILE_DISPLAY_NAME;
};
export type ProfileDisplayOption = {
statusText: string;
iconName: IconNames;
tooltip: TooltipInnerContentOption | null;
} | null;
type MacProfileSpecificStatus = "success" | "acknowledged";
type AndroidCertSpecificStatus = "delivered" | "delivering";
export type ProfileStatus = Exclude<
OsSettingsTableStatusValue,
AndroidCertSpecificStatus
>;
type OperationTypeOption = Record<ProfileStatus, ProfileDisplayOption>;
type ProfileDisplayConfig = Record<ProfileOperationType, OperationTypeOption>;
// Profiles for iOS and iPadOS skip the verifying step
const APPLE_PROFILE_VERIFIED_DISPLAY_CONFIG: ProfileDisplayOption = {
statusText: "Verified",
iconName: "success",
tooltip: (innerProps) =>
innerProps.isDiskEncryptionProfile
? "The host turned disk encryption on and sent the key to Fleet. " +
"Fleet verified."
: "The host applied the setting. Fleet verified.",
} as const;
const MAC_PROFILE_VERIFYING_DISPLAY_CONFIG: ProfileDisplayOption = {
statusText: "Verifying",
iconName: "success-outline",
tooltip: (innerProps) =>
innerProps.isDiskEncryptionProfile
? "The host acknowledged the MDM command to turn on disk encryption. " +
"Fleet is verifying with osquery and retrieving the disk encryption key. " +
"This may take up to one hour."
: "The host acknowledged the MDM command to apply the setting. Fleet is " +
"verifying with osquery.",
} as const;
export const PROFILE_DISPLAY_CONFIG: ProfileDisplayConfig = {
install: {
verified: APPLE_PROFILE_VERIFIED_DISPLAY_CONFIG,
success: APPLE_PROFILE_VERIFIED_DISPLAY_CONFIG,
verifying: MAC_PROFILE_VERIFYING_DISPLAY_CONFIG,
acknowledged: MAC_PROFILE_VERIFYING_DISPLAY_CONFIG,
pending: {
statusText: "Enforcing",
iconName: "pending-outline",
tooltip: (innerProps) =>
innerProps.isDiskEncryptionProfile
? "The hosts will receive the MDM command to turn on disk encryption " +
"when the hosts come online."
: "The host is running the MDM command to apply settings or will run it " +
"when the host comes online.",
},
action_required: {
statusText: "Action required",
iconName: "pending-outline",
tooltip: TooltipInnerContentActionRequired as TooltipInnerContentFunc,
},
failed: {
statusText: "Failed",
iconName: "error",
tooltip: null,
},
},
remove: {
pending: {
statusText: "Removing enforcement",
iconName: "pending-outline",
tooltip: (innerProps) =>
innerProps.isDiskEncryptionProfile
? "The host will receive the MDM command to remove the disk encryption profile when the " +
"host comes online."
: "The host is running the MDM command to remove settings or will run " +
"it when the host comes online.",
},
action_required: null, // should not be reached
verified: null, // should not be reached
verifying: null, // should not be reached
success: null, // should not be reached
acknowledged: null, // should not be reached
failed: {
statusText: "Failed",
iconName: "error",
tooltip: null,
},
},
};
export type WindowsDiskEncryptionDisplayStatus = Exclude<
ProfileStatus,
MacProfileSpecificStatus | AndroidCertSpecificStatus
>;
type WindowsDiskEncryptionDisplayConfig = Pick<
OperationTypeOption,
WindowsDiskEncryptionDisplayStatus
>;
export const WINDOWS_DISK_ENCRYPTION_DISPLAY_CONFIG: WindowsDiskEncryptionDisplayConfig = {
verified: {
statusText: "Verified",
iconName: "success",
tooltip: () =>
"The host turned disk encryption on and sent the key to Fleet. Fleet verified.",
},
verifying: {
statusText: "Verifying",
iconName: "success-outline",
tooltip: () =>
"The host acknowledged the MDM command to turn on disk encryption. Fleet is verifying with " +
"osquery and retrieving the disk encryption key. This may take up to one hour.",
},
pending: {
statusText: "Enforcing",
iconName: "pending-outline",
tooltip: () =>
"The host will receive the MDM command to turn on disk encryption when the host comes online.",
},
action_required: {
statusText: "Action required",
iconName: "pending-outline",
tooltip: () =>
"Disk encryption is on, but the user has not set a BitLocker PIN yet.",
},
failed: {
statusText: "Failed",
iconName: "error",
tooltip: null,
},
};
type LinuxDiskEncryptionDisplayConfig = Omit<
OperationTypeOption,
MacProfileSpecificStatus | AndroidCertSpecificStatus | "pending" | "verifying"
>;
export const LINUX_DISK_ENCRYPTION_DISPLAY_CONFIG: LinuxDiskEncryptionDisplayConfig = {
verified: {
statusText: "Verified",
iconName: "success",
tooltip: () =>
"The host turned disk encryption on and sent the key to Fleet. Fleet verified.",
},
failed: {
statusText: "Failed",
iconName: "error",
tooltip: null,
},
action_required: {
statusText: "Action required",
iconName: "pending-outline",
tooltip: TooltipInnerContentActionRequired as TooltipInnerContentFunc,
},
};
export const RECOVERY_LOCK_PASSWORD_DISPLAY_CONFIG: Record<
RecoveryLockPasswordStatus,
ProfileDisplayOption
> = {
verified: {
statusText: "Verified",
iconName: "success",
tooltip: "Fleet set a recovery lock password for the host.",
},
pending: {
statusText: "Enforcing",
iconName: "pending-outline",
tooltip: "Fleet is setting a recovery lock password for the host.",
},
removing_enforcement: {
statusText: "Removing enforcement",
iconName: "pending-outline",
tooltip: "Fleet is unsetting the recovery lock password for the host.",
},
failed: {
statusText: "Failed",
iconName: "error",
tooltip: "Fleet failed to set a recovery lock password for the host.",
},
};