fleet/frontend/pages/hosts/details/OSSettingsModal/OSSettingsTable/OSSettingStatusCell/OSSettingStatusCell.tsx
Gabriel Hernandez de92d94dbd
update os settings table table cell layout (#18393)
relates to #18082

fixes the os settings modal table styling. We make all cells the same
width and truncate when necessary.


![image](https://github.com/fleetdm/fleet/assets/1153709/48714f3c-567a-4631-809b-c4348e9faa6e)

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://fleetdm.com/docs/contributing/committing-changes#changes-files)
for more information.
- [x] Manual QA for all new/changed functionality
2024-04-18 15:49:21 +01:00

102 lines
2.9 KiB
TypeScript

import React from "react";
import ReactTooltip from "react-tooltip";
import { uniqueId } from "lodash";
import Icon from "components/Icon";
import TextCell from "components/TableContainer/DataTable/TextCell";
import { ProfileOperationType } from "interfaces/mdm";
import { COLORS } from "styles/var/colors";
import {
isMdmProfileStatus,
OsSettingsTableStatusValue,
} from "../OSSettingsTableConfig";
import TooltipContent from "./components/Tooltip/TooltipContent";
import {
isDiskEncryptionProfile,
PROFILE_DISPLAY_CONFIG,
ProfileDisplayOption,
WINDOWS_DISK_ENCRYPTION_DISPLAY_CONFIG,
} from "./helpers";
const baseClass = "os-settings-status-cell";
interface IOSSettingStatusCellProps {
status: OsSettingsTableStatusValue;
operationType: ProfileOperationType | null;
profileName: string;
}
const OSSettingStatusCell = ({
status,
operationType,
profileName = "",
}: IOSSettingStatusCellProps) => {
let displayOption: ProfileDisplayOption = null;
// windows hosts do not have an operation type at the moment and their display options are
// different than mac hosts.
if (!operationType && isMdmProfileStatus(status)) {
displayOption = WINDOWS_DISK_ENCRYPTION_DISPLAY_CONFIG[status];
}
if (operationType) {
displayOption = PROFILE_DISPLAY_CONFIG[operationType]?.[status];
}
const isDeviceUser = window.location.pathname
.toLowerCase()
.includes("/device/");
if (displayOption) {
const { statusText, iconName, tooltip } = displayOption;
const tooltipId = uniqueId();
return (
<span className={baseClass}>
<Icon name={iconName} />
{tooltip ? (
<>
<span
className={`${baseClass}__status-text`}
data-tip
data-for={tooltipId}
data-tip-disable={false}
>
{statusText}
</span>
<ReactTooltip
place="top"
effect="solid"
backgroundColor={COLORS["tooltip-bg"]}
id={tooltipId}
data-html
>
<span className="tooltip__tooltip-text">
{status !== "action_required" ? (
<TooltipContent
innerContent={tooltip}
innerProps={{
isDiskEncryptionProfile: isDiskEncryptionProfile(
profileName
),
}}
/>
) : (
<TooltipContent
innerContent={tooltip}
innerProps={{ isDeviceUser, profileName }}
/>
)}
</span>
</ReactTooltip>
</>
) : (
statusText
)}
</span>
);
}
// graceful error - this state should not be reached based on the API spec
return <TextCell value="Unrecognized" />;
};
export default OSSettingStatusCell;