fleet/frontend/components/TableContainer/DataTable/PlatformCell/PlatformCell.tsx
jacobshandling fea4dd791a
UI - Update targeted platforms display logic in the queries table (#25037)
### Unreleased bug where queries targeting all platforms display as
targeting no platforms in the Queries table.

The below query is set to target _all_ platforms.

**Bug:**
<img width="1248" alt="Screenshot 2024-12-29 at 8 24 50 PM"
src="https://github.com/user-attachments/assets/90c9a498-f7d8-4d86-88f1-061c985fb4fa"
/>

**Fix:**
Targeting all platforms, frequency set, displays platform icons:
<img width="1248" alt="Screenshot 2024-12-29 at 8 25 25 PM"
src="https://github.com/user-attachments/assets/d03c1bba-e5ea-461a-b506-1840cf4ffa8e"
/>

Targeting all paltforms but no frequency set (i.e., no schedule), no
targeted platforms displayed:
<img width="1248" alt="Screenshot 2024-12-29 at 8 25 38 PM"
src="https://github.com/user-attachments/assets/9b08a8c3-b682-4eb0-aeb4-59a6e0144e14"
/>

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

---------

Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2024-12-30 13:06:59 -08:00

45 lines
1.2 KiB
TypeScript

import React from "react";
import Icon from "components/Icon";
import { ScheduledQueryablePlatform } from "interfaces/platform";
interface IPlatformCellProps {
platforms: ScheduledQueryablePlatform[];
}
const baseClass = "platform-cell";
const ICONS: Record<string, ScheduledQueryablePlatform> = {
darwin: "darwin",
windows: "windows",
linux: "linux",
};
const DISPLAY_ORDER: ScheduledQueryablePlatform[] = [
"darwin",
"windows",
"linux",
];
const PlatformCell = ({ platforms }: IPlatformCellProps): JSX.Element => {
let orderedList: ScheduledQueryablePlatform[] = [];
orderedList = platforms.length
? // if no platforms, interpret as targeting all schedule-targetable platforms
DISPLAY_ORDER.filter((platform) => platforms.includes(platform))
: DISPLAY_ORDER;
return (
<span className={`${baseClass}__wrapper`} data-testid="icons">
{orderedList.map((platform) => {
return ICONS[platform] ? (
<Icon
className={`${baseClass}__icon`}
name={ICONS[platform]}
size="small"
key={ICONS[platform]}
/>
) : null;
})}
</span>
);
};
export default PlatformCell;