mirror of
https://github.com/fleetdm/fleet
synced 2026-04-28 17:07:43 +00:00
103 lines
2.7 KiB
TypeScript
103 lines
2.7 KiB
TypeScript
import React from "react";
|
|
|
|
import { IOsqueryPlatform } from "interfaces/platform";
|
|
import { PLATFORM_DISPLAY_NAMES } from "utilities/constants";
|
|
|
|
import TooltipWrapper from "components/TooltipWrapper";
|
|
import Icon from "components/Icon";
|
|
|
|
interface IPlatformCompatibilityProps {
|
|
compatiblePlatforms: IOsqueryPlatform[] | null;
|
|
error: Error | null;
|
|
}
|
|
|
|
const baseClass = "platform-compatibility";
|
|
|
|
const DISPLAY_ORDER = [
|
|
"macOS",
|
|
"Windows",
|
|
"Linux",
|
|
"ChromeOS",
|
|
] as IOsqueryPlatform[];
|
|
|
|
const ERROR_NO_COMPATIBLE_TABLES = Error("no tables in query");
|
|
|
|
const formatPlatformsForDisplay = (
|
|
compatiblePlatforms: IOsqueryPlatform[]
|
|
): IOsqueryPlatform[] => {
|
|
return compatiblePlatforms.map((str) => PLATFORM_DISPLAY_NAMES[str] || str);
|
|
};
|
|
|
|
const displayIncompatibilityText = (err: Error) => {
|
|
switch (err) {
|
|
case ERROR_NO_COMPATIBLE_TABLES:
|
|
return (
|
|
<span>
|
|
No platforms (check your query for invalid tables or tables that are
|
|
supported on different platforms)
|
|
</span>
|
|
);
|
|
default:
|
|
return (
|
|
<span>No platforms (check your query for a possible syntax error)</span>
|
|
);
|
|
}
|
|
};
|
|
|
|
const PlatformCompatibility = ({
|
|
compatiblePlatforms,
|
|
error,
|
|
}: IPlatformCompatibilityProps): JSX.Element | null => {
|
|
if (!compatiblePlatforms) {
|
|
return null;
|
|
}
|
|
if (error || !compatiblePlatforms?.length) {
|
|
return (
|
|
<span className={baseClass}>
|
|
<b>
|
|
<TooltipWrapper
|
|
tipContent="Estimated compatiblity based on <br /> the tables used in the query."
|
|
isDelayed
|
|
>
|
|
Compatible with:
|
|
</TooltipWrapper>
|
|
</b>
|
|
|
|
{displayIncompatibilityText(error || ERROR_NO_COMPATIBLE_TABLES)}
|
|
</span>
|
|
);
|
|
}
|
|
|
|
const displayPlatforms = formatPlatformsForDisplay(compatiblePlatforms);
|
|
return (
|
|
<span className={baseClass}>
|
|
<b>
|
|
<TooltipWrapper
|
|
tipContent="Estimated compatiblity based on <br /> the tables used in the query."
|
|
isDelayed
|
|
>
|
|
Compatible with:
|
|
</TooltipWrapper>
|
|
</b>
|
|
{DISPLAY_ORDER.map((platform) => {
|
|
const isCompatible = displayPlatforms.includes(platform);
|
|
return (
|
|
<span
|
|
key={`platform-compatibility__${platform}`}
|
|
className="platform"
|
|
>
|
|
<Icon
|
|
name={isCompatible ? "check" : "ex"}
|
|
className={
|
|
isCompatible ? "compatible-platform" : "incompatible-platform"
|
|
}
|
|
color={isCompatible ? "status-success" : "status-error"}
|
|
/>
|
|
{platform}
|
|
</span>
|
|
);
|
|
})}
|
|
</span>
|
|
);
|
|
};
|
|
export default PlatformCompatibility;
|