1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-19 13:29:41 +02:00
portainer/app/react/edge/components/EdgeGroupsSelector.tsx
Chaim Lev-Ari ceaee4e175
refactor(ui): replace ng selectors with react-select [EE-3608] (#7203)
Co-authored-by: LP B <xAt0mZ@users.noreply.github.com>
2022-09-21 10:10:58 +03:00

34 lines
814 B
TypeScript

import _ from 'lodash';
import { Select } from '@@/form-components/ReactSelect';
import { EdgeGroup } from '../edge-groups/types';
type SingleValue = EdgeGroup['Id'];
interface Props {
items: EdgeGroup[];
value: SingleValue[];
onChange: (value: SingleValue[]) => void;
}
export function EdgeGroupsSelector({ items, value, onChange }: Props) {
const valueGroups = _.compact(
value.map((id) => items.find((item) => item.Id === id))
);
return (
<Select
options={items}
isMulti
getOptionLabel={(item) => item.Name}
getOptionValue={(item) => String(item.Id)}
value={valueGroups}
onChange={(value) => {
onChange(value.map((item) => item.Id));
}}
placeholder="Select one or multiple group(s)"
closeMenuOnSelect={false}
/>
);
}