fleet/frontend/components/PlatformCompatibility/PlatformCompatibility.tsx
RachelElysia 2641d50320
Fleet UI: Fix platform compatibility styling (#19850)
## Issue
Cerra #19710 

## Description
- Remove 12px padding to the left of platform compatibility
- Refactor to `flex-wrap` so on small widths, the chrome platform
doesn't overflow past the section

## Code cleanup
- Remove redundant `<span/>`
- Refactor 12px gaps and 4px gaps to use flex `gap` instead of `padding`
- Refactor redundant code in `<PlatformCompatibility/>`



# Checklist for submitter

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

<!-- Note that API documentation changes are now addressed by the
product design team. -->

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

---------

Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2024-06-18 15:14:20 -07:00

98 lines
2.5 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;
}
const displayPlatforms = formatPlatformsForDisplay(compatiblePlatforms);
const renderCompatiblePlatforms = () => {
if (error || !compatiblePlatforms?.length) {
return displayIncompatibilityText(error || ERROR_NO_COMPATIBLE_TABLES);
}
return DISPLAY_ORDER.map((platform) => {
const isCompatible = displayPlatforms.includes(platform);
return (
<span key={`platform-compatibility__${platform}`} className="platform">
<Icon
name={isCompatible ? "check" : "close"}
className={
isCompatible ? "compatible-platform" : "incompatible-platform"
}
color={isCompatible ? "status-success" : "status-error"}
size="small"
/>
{platform}
</span>
);
});
};
return (
<div className={baseClass}>
<b>
<TooltipWrapper
tipContent={
<>
Estimated compatiblity based on <br /> the tables used in the
query.
</>
}
>
Compatible with:
</TooltipWrapper>
</b>
{renderCompatiblePlatforms()}
</div>
);
};
export default PlatformCompatibility;