19700: Use correct type and check for process raw input data
[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 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
15 export const RUN_PROCESS_ADVANCED_FORM = 'runProcessAdvancedForm';
16
17 export const OUTPUT_FIELD = 'output';
18 export const RUNTIME_FIELD = 'runtime';
19 export const RAM_FIELD = 'ram';
20 export const VCPUS_FIELD = 'vcpus';
21 export const KEEP_CACHE_RAM_FIELD = 'keep_cache_ram';
22 export const RUNNER_IMAGE_FIELD = 'acr_container_image';
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     [RUNNER_IMAGE_FIELD]: string;
31 }
32
33 export const RunProcessAdvancedForm =
34     reduxForm<RunProcessAdvancedFormData>({
35         form: RUN_PROCESS_ADVANCED_FORM,
36     })(() =>
37         <form>
38             <ExpansionPanel elevation={0}>
39                 <ExpansionPanelSummary style={{ padding: 0 }} expandIcon={<ExpandIcon />}>
40                     Advanced
41                 </ExpansionPanelSummary>
42                 <ExpansionPanelDetails style={{ padding: 0 }}>
43                     <Grid container spacing={32}>
44                         <Grid item xs={12} md={6}>
45                             <Field
46                                 name={OUTPUT_FIELD}
47                                 component={TextField as any}
48                                 label="Output name" />
49                         </Grid>
50                         <Grid item xs={12} md={6}>
51                             <Field
52                                 name={RUNTIME_FIELD}
53                                 component={TextField as any}
54                                 helperText="Maximum running time (in seconds) that this container will be allowed to run before being cancelled."
55                                 label="Runtime limit"
56                                 parse={IntInput.parse}
57                                 format={IntInput.format}
58                                 type='number'
59                                 validate={runtimeValidation} />
60                         </Grid>
61                         <Grid item xs={12} md={6}>
62                             <Field
63                                 name={RAM_FIELD}
64                                 component={TextField as any}
65                                 label="RAM"
66                                 helperText="Number of ram bytes to be used to run this process."
67                                 parse={IntInput.parse}
68                                 format={IntInput.format}
69                                 type='number'
70                                 required
71                                 validate={ramValidation} />
72                         </Grid>
73                         <Grid item xs={12} md={6}>
74                             <Field
75                                 name={VCPUS_FIELD}
76                                 component={TextField as any}
77                                 label="VCPUs"
78                                 helperText="Number of cores to be used to run this process."
79                                 parse={IntInput.parse}
80                                 format={IntInput.format}
81                                 type='number'
82                                 required
83                                 validate={vcpusValidation} />
84                         </Grid>
85                         <Grid item xs={12} md={6}>
86                             <Field
87                                 name={KEEP_CACHE_RAM_FIELD}
88                                 component={TextField as any}
89                                 label="Keep cache RAM"
90                                 helperText="Number of keep cache bytes to be used to run this process."
91                                 parse={IntInput.parse}
92                                 format={IntInput.format}
93                                 type='number'
94                                 validate={keepCacheRamValidation} />
95                         </Grid>
96                         <Grid item xs={12} md={6}>
97                             <Field
98                                 name={RUNNER_IMAGE_FIELD}
99                                 component={TextField as any}
100                                 label='Runner'
101                                 required
102                                 helperText='The container image with arvados-cwl-runner that will execute this workflow.' />
103                         </Grid>
104                     </Grid>
105                 </ExpansionPanelDetails>
106             </ExpansionPanel>
107         </form >);
108
109 const ramValidation = [min(0)];
110 const vcpusValidation = [min(1)];
111 const keepCacheRamValidation = [optional(min(0))];
112 const runtimeValidation = [optional(min(1))];