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