Merge branch 'master' into 14490-workflow-presets
[arvados.git] / 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 * as React from "react";
6 import { Field } from "redux-form";
7 import { TextField } from "~/components/text-field/text-field";
8 import { USER_EMAIL_VALIDATION, USER_LENGTH_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
13 export const UserEmailField = () =>
14     <Field
15         name='email'
16         component={TextField}
17         validate={USER_EMAIL_VALIDATION}
18         autoFocus={true}
19         label="Email" />;
20
21 export const UserIdentityUrlField = () =>
22     <Field
23         name='identityUrl'
24         component={TextField}
25         validate={USER_LENGTH_VALIDATION}
26         label="Identity URL Prefix" />;
27
28 export const UserVirtualMachineField = ({ data }: any) =>
29     <div style={{ marginBottom: '21px' }}>
30         <InputLabel>Virtual Machine</InputLabel>
31         <Field
32             name='virtualMachine'
33             component={NativeSelectField}
34             validate={USER_LENGTH_VALIDATION}
35             items={getVirtualMachinesList(data.items)} />
36     </div>;
37
38 export const UserGroupsVirtualMachineField = () =>
39     <Field
40         name='groups'
41         component={TextField}
42         validate={USER_LENGTH_VALIDATION}
43         label="Groups for virtual machine (comma separated list)" />;
44
45 const getVirtualMachinesList = (virtualMachines: VirtualMachinesResource[]) => {
46     const mappedVirtualMachines = virtualMachines.map(it => ({ key: it.hostname, value: it.hostname }));
47     return mappedVirtualMachines;
48 };