16086: Adds default value on string array validator.
[arvados-workbench2.git] / src / views / run-process-panel / run-process-advanced-form.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 { ExpansionPanel, ExpansionPanelDetails, ExpansionPanelSummary } from '@material-ui/core';
7 import { reduxForm, Field } from 'redux-form';
8 import { Grid } from '@material-ui/core';
9 import { TextField } from '~/components/text-field/text-field';
10 import { ExpandIcon } from '~/components/icon/icon';
11 import * as IntInput from './inputs/int-input';
12 import { min } from '~/validators/min';
13 import { optional } from '~/validators/optional';
14 import { SwitchField } from '~/components/switch-field/switch-field';
15
16 export const RUN_PROCESS_ADVANCED_FORM = 'runProcessAdvancedForm';
17
18 export const OUTPUT_FIELD = 'output';
19 export const RUNTIME_FIELD = 'runtime';
20 export const RAM_FIELD = 'ram';
21 export const VCPUS_FIELD = 'vcpus';
22 export const KEEP_CACHE_RAM_FIELD = 'keep_cache_ram';
23 export const API_FIELD = 'api';
24
25 export interface RunProcessAdvancedFormData {
26     [OUTPUT_FIELD]?: string;
27     [RUNTIME_FIELD]?: number;
28     [RAM_FIELD]: number;
29     [VCPUS_FIELD]: number;
30     [KEEP_CACHE_RAM_FIELD]?: number;
31     [API_FIELD]?: boolean;
32 }
33
34 export const RunProcessAdvancedForm =
35     reduxForm<RunProcessAdvancedFormData>({
36         form: RUN_PROCESS_ADVANCED_FORM,
37     })(() =>
38         <form>
39             <ExpansionPanel elevation={0}>
40                 <ExpansionPanelSummary style={{ padding: 0 }} expandIcon={<ExpandIcon />}>
41                     Advanced
42                 </ExpansionPanelSummary>
43                 <ExpansionPanelDetails style={{ padding: 0 }}>
44                     <Grid container spacing={32}>
45                         <Grid item xs={12} md={6}>
46                             <Field
47                                 name={OUTPUT_FIELD}
48                                 component={TextField}
49                                 label="Output name" />
50                         </Grid>
51                         <Grid item xs={12} md={6}>
52                             <Field
53                                 name={RUNTIME_FIELD}
54                                 component={TextField}
55                                 helperText="Maximum running time (in seconds) that this container will be allowed to run before being cancelled."
56                                 label="Runtime limit"
57                                 parse={IntInput.parse}
58                                 format={IntInput.format}
59                                 type='number'
60                                 validate={runtimeValidation} />
61                         </Grid>
62                         <Grid item xs={12} md={6}>
63                             <Field
64                                 name={RAM_FIELD}
65                                 component={TextField}
66                                 label="RAM"
67                                 helperText="Number of ram bytes to be used to run this process."
68                                 parse={IntInput.parse}
69                                 format={IntInput.format}
70                                 type='number'
71                                 required
72                                 validate={ramValidation} />
73                         </Grid>
74                         <Grid item xs={12} md={6}>
75                             <Field
76                                 name={VCPUS_FIELD}
77                                 component={TextField}
78                                 label="VCPUs"
79                                 helperText="Number of cores to be used to run this process."
80                                 parse={IntInput.parse}
81                                 format={IntInput.format}
82                                 type='number'
83                                 required
84                                 validate={vcpusValidation} />
85                         </Grid>
86                         <Grid item xs={12} md={6}>
87                             <Field
88                                 name={KEEP_CACHE_RAM_FIELD}
89                                 component={TextField}
90                                 label="Keep cache RAM"
91                                 helperText="Number of keep cache bytes to be used to run this process."
92                                 parse={IntInput.parse}
93                                 format={IntInput.format}
94                                 type='number'
95                                 validate={keepCacheRamValidation} />
96                         </Grid>
97                         <Grid item xs={12} md={6}>
98                             <Field
99                                 name={API_FIELD}
100                                 component={SwitchField}
101                                 switchProps={{
102                                     color: 'primary'
103                                 }}
104                                 label='API'
105                                 helperText='When set, ARVADOS_API_HOST and ARVADOS_API_TOKEN will be set, and process will have networking enabled to access the Arvados API server.' />
106                         </Grid>
107                     </Grid>
108                 </ExpansionPanelDetails>
109             </ExpansionPanel>
110         </form >);
111
112 const ramValidation = [min(0)];
113 const vcpusValidation = [min(1)];
114 const keepCacheRamValidation = [optional(min(0))];
115 const runtimeValidation = [optional(min(1))];