fleet/frontend/components/PlatformCompatibility/PlatformCompatibility.tsx
Jacob Shandling 53f57c44db
UI - Queries page updates, pt.1 (#12784)
## Addresses #12636 – follow-up work for PR #12713

- Update Platforms column to render the user-selected platforms for a
query if any, otherwise those that are compatible
<img width="686" alt="Screenshot 2023-07-14 at 6 03 06 PM"
src="https://github.com/fleetdm/fleet/assets/61553566/abd1f079-bdfe-45be-b1dd-58eb903672ef">

  - Clean up typing and names around this column 
- Encapsulate logic for query automations column cells into new
QueryAutomationsStatusIndicator component
  - Increase modularity and decrease coupling of StatusIndicator
- Cleanly handle overflowing queries table due to very long query name
<img width="512" alt="Screenshot 2023-07-14 at 6 07 20 PM"
src="https://github.com/fleetdm/fleet/assets/61553566/6e970038-0aac-4f71-b21d-ececfa66b94f">

- Small copy and layout fixes

- [x] Manual QA for all new/changed functionality

---------

Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2023-07-17 14:09:12 -07:00

103 lines
2.7 KiB
TypeScript

import React from "react";
import { OsqueryPlatform } from "interfaces/platform";
import { PLATFORM_DISPLAY_NAMES } from "utilities/constants";
import TooltipWrapper from "components/TooltipWrapper";
import Icon from "components/Icon";
interface IPlatformCompatibilityProps {
compatiblePlatforms: OsqueryPlatform[] | null;
error: Error | null;
}
const baseClass = "platform-compatibility";
const DISPLAY_ORDER = [
"macOS",
"Windows",
"Linux",
"ChromeOS",
] as OsqueryPlatform[];
const ERROR_NO_COMPATIBLE_TABLES = Error("no tables in query");
const formatPlatformsForDisplay = (
compatiblePlatforms: OsqueryPlatform[]
): OsqueryPlatform[] => {
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;