fleet/frontend/pages/labels/components/PlatformField/PlatformField.tsx
Ian Littman 8e4e89f4e9
API + auth + UI changes for team labels (#37208)
Covers #36760, #36758.

# Checklist for submitter

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

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files)
for more information.

- [x] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)

## Testing

- [x] Added/updated automated tests
- [x] Where appropriate, [automated tests simulate multiple hosts and
test for host
isolation](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/reference/patterns-backend.md#unit-testing)
(updates to one hosts's records do not affect another)

- [ ] QA'd all new/changed functionality manually
2025-12-29 21:28:45 -06:00

61 lines
1.5 KiB
TypeScript

import React from "react";
import { noop } from "lodash";
// @ts-ignore
import Dropdown from "components/forms/fields/Dropdown";
import FormField from "components/forms/FormField";
const PLATFORM_STRINGS: { [key: string]: string } = {
darwin: "macOS",
windows: "MS Windows",
ubuntu: "Ubuntu Linux",
centos: "CentOS Linux",
};
const platformOptions = [
{ label: "All platforms", value: "" },
{ label: "macOS", value: "darwin" },
{ label: "Windows", value: "windows" },
{ label: "Ubuntu", value: "ubuntu" },
{ label: "Centos", value: "centos" },
];
const baseClass = "platform-field";
interface IPlatformFieldProps {
platform: string;
isEditing?: boolean;
onChange?: (platform: string) => void;
}
const PlatformField = ({
platform,
isEditing = false,
onChange = noop,
}: IPlatformFieldProps) => {
return (
<div className={baseClass}>
{!isEditing ? (
<div className="form-field form-field--dropdown">
<Dropdown
label="Platform"
name="platform"
onChange={onChange}
value={platform}
options={platformOptions}
classname={`${baseClass}__platform-dropdown`}
wrapperClassName={`${baseClass}__form-field ${baseClass}__form-field--platform`}
/>
</div>
) : (
<FormField label="Platform" name="platform">
<>
<p>{platform ? PLATFORM_STRINGS[platform] : "All platforms"}</p>
</>
</FormField>
)}
</div>
);
};
export default PlatformField;