import { array, object, string } from 'yup'; import { r2a } from '@/react-tools/react2angular'; import { withControlledInput } from '@/react-tools/withControlledInput'; import { InputList } from '@@/form-components/InputList'; import { ItemProps } from '@@/form-components/InputList/InputList'; import { InputGroup } from '@@/form-components/InputGroup'; export interface Gpu { value: string; name: string; } interface Props { value: Gpu[]; onChange(value: Gpu[]): void; } function Item({ item, onChange }: ItemProps) { return (
GPU Name { onChange({ ...item, name: e.target.value }); }} /> Index or UUID { onChange({ ...item, value: e.target.value }); }} />
); } export function GpusList({ value, onChange }: Props) { return ( label="GPUs" tooltip="You may optionally set up the GPUs that will be selectable against containers, although 'All GPUs' will always be available." value={value} onChange={onChange} itemBuilder={() => ({ value: '', name: '' })} addLabel="Add GPU" item={Item} /> ); } export function gpusListValidation() { const gpuShape = object().shape({ name: string().required(), value: string().required(), }); return array().of(gpuShape).default([]); } export const GpusListAngular = r2a(withControlledInput(GpusList), [ 'value', 'onChange', ]);