37e15469909c668fd52586bad2897cd8be862cd7
[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 { require } from '~/validators/require';
13 import { min } from '~/validators/min';
14 import { optional } from '~/validators/optional';
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 = 'keepCacheRam';
23
24 export interface RunProcessAdvancedFormData {
25     [OUTPUT_FIELD]?: string;
26     [RUNTIME_FIELD]?: number;
27     [RAM_FIELD]: number;
28     [VCPUS_FIELD]: number;
29     [KEEP_CACHE_RAM_FIELD]?: number;
30 }
31
32 export const RunProcessAdvancedForm =
33     reduxForm<RunProcessAdvancedFormData>({
34         form: RUN_PROCESS_ADVANCED_FORM,
35     })(() =>
36         <form>
37             <ExpansionPanel elevation={0}>
38                 <ExpansionPanelSummary style={{ padding: 0 }} expandIcon={<ExpandIcon />}>
39                     Advanced
40                 </ExpansionPanelSummary>
41                 <ExpansionPanelDetails style={{ padding: 0 }}>
42                     <Grid container spacing={32}>
43                         <Grid item xs={12} md={6}>
44                             <Field
45                                 name={OUTPUT_FIELD}
46                                 component={TextField}
47                                 label="Output name" />
48                         </Grid>
49                         <Grid item xs={12} md={6}>
50                             <Field
51                                 name={RUNTIME_FIELD}
52                                 component={TextField}
53                                 helperText="Maximum running time (in seconds) that this container will be allowed to run before being cancelled."
54                                 label="Runtime limit"
55                                 parse={IntInput.parse}
56                                 format={IntInput.format}
57                                 type='number'
58                                 validate={runtimeValidation} />
59                         </Grid>
60                         <Grid item xs={12} md={6}>
61                             <Field
62                                 name={RAM_FIELD}
63                                 component={TextField}
64                                 label="RAM"
65                                 helperText="Number of ram bytes to be used to run this process."
66                                 parse={IntInput.parse}
67                                 format={IntInput.format}
68                                 type='number'
69                                 required
70                                 validate={ramValidation} />
71                         </Grid>
72                         <Grid item xs={12} md={6}>
73                             <Field
74                                 name={VCPUS_FIELD}
75                                 component={TextField}
76                                 label="VCPUs"
77                                 helperText="Number of cores to be used to run this process."
78                                 parse={IntInput.parse}
79                                 format={IntInput.format}
80                                 type='number'
81                                 required
82                                 validate={vcpusValidation} />
83                         </Grid>
84                         <Grid item xs={12} md={6}>
85                             <Field
86                                 name={KEEP_CACHE_RAM_FIELD}
87                                 component={TextField}
88                                 label="Keep cache RAM"
89                                 helperText="Number of keep cache bytes to be used to run this process."
90                                 parse={IntInput.parse}
91                                 format={IntInput.format}
92                                 type='number'
93                                 validate={keepCacheRamValdation} />
94                         </Grid>
95                     </Grid>
96                 </ExpansionPanelDetails>
97             </ExpansionPanel>
98         </form >);
99
100 const ramValidation = [min(0)];
101 const vcpusValidation = [min(1)];
102 const keepCacheRamValdation = [optional(min(0))];
103 const runtimeValidation = [optional(min(1))];