18874: Merge branch 'main' from arvados-workbench2.git
[arvados.git] / services / workbench2 / src / views-components / form-fields / user-form-fields.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import React from "react";
6 import { Field } from "redux-form";
7 import { TextField } from "components/text-field/text-field";
8 import { USER_EMAIL_VALIDATION, CHOOSE_VM_VALIDATION } from "validators/validators";
9 import { NativeSelectField } from "components/select-field/select-field";
10 import { InputLabel } from "@material-ui/core";
11 import { VirtualMachinesResource } from "models/virtual-machines";
12 import { VIRTUAL_MACHINE_ADD_LOGIN_GROUPS_FIELD, VIRTUAL_MACHINE_ADD_LOGIN_VM_FIELD } from "store/virtual-machines/virtual-machines-actions";
13 import { GroupArrayInput } from "views-components/virtual-machines-dialog/group-array-input";
14
15 interface VirtualMachinesProps {
16     data: {
17         items: VirtualMachinesResource[];
18     };
19 }
20
21 export const UserEmailField = () =>
22     <Field
23         name='email'
24         component={TextField as any}
25         validate={USER_EMAIL_VALIDATION}
26         autoFocus={true}
27         label="Email" />;
28
29 export const RequiredUserVirtualMachineField = ({ data }: VirtualMachinesProps) =>
30     <div style={{ marginBottom: '21px' }}>
31         <InputLabel>Virtual Machine</InputLabel>
32         <Field
33             name={VIRTUAL_MACHINE_ADD_LOGIN_VM_FIELD}
34             component={NativeSelectField as any}
35             validate={CHOOSE_VM_VALIDATION}
36             items={getVirtualMachinesList(data.items)} />
37     </div>;
38
39 export const UserVirtualMachineField = ({ data }: VirtualMachinesProps) =>
40     <div style={{ marginBottom: '21px' }}>
41         <InputLabel>Virtual Machine</InputLabel>
42         <Field
43             name={VIRTUAL_MACHINE_ADD_LOGIN_VM_FIELD}
44             component={NativeSelectField as any}
45             items={getVirtualMachinesList(data.items)} />
46     </div>;
47
48 export const UserGroupsVirtualMachineField = () =>
49     <GroupArrayInput
50         name={VIRTUAL_MACHINE_ADD_LOGIN_GROUPS_FIELD}
51         input={{id:"Add groups to VM login (eg: docker, sudo)", disabled:false}}
52         required={false}
53     />
54
55 const getVirtualMachinesList = (virtualMachines: VirtualMachinesResource[]) =>
56     [{ key: "", value: "" }].concat(virtualMachines.map(it => ({ key: it.uuid, value: it.hostname })));