Extend RunProcessAdvancedForm with numeric fields with runtime constraints values
authorMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Thu, 27 Dec 2018 10:15:17 +0000 (11:15 +0100)
committerMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Thu, 27 Dec 2018 10:15:17 +0000 (11:15 +0100)
Feature #master

Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski@contractors.roche.com>

src/views/run-process-panel/run-process-advanced-form.tsx

index 19beab6be3328ee13a1c70500669557f5999de4e..5bec245a50768cae4385dee5aeebadf68935e62c 100644 (file)
@@ -8,17 +8,34 @@ import { reduxForm, Field } from 'redux-form';
 import { Grid } from '@material-ui/core';
 import { TextField } from '~/components/text-field/text-field';
 import { ExpandIcon } from '~/components/icon/icon';
+import * as IntInput from './inputs/int-input';
+import { require } from '~/validators/require';
+import { min } from '~/validators/min';
+import { optional } from '~/validators/optional';
 
 export const RUN_PROCESS_ADVANCED_FORM = 'runProcessAdvancedForm';
 
+const OUTPUT_FIELD = 'output';
+const RUNTIME_FIELD = 'runtime';
+const RAM_FIELD = 'ram';
+const VCPUS_FIELD = 'vcpus';
+const KEEP_CACHE_RAM_FIELD = 'keepCacheRam';
+
 export interface RunProcessAdvancedFormData {
-    output: string;
-    runtime: string;
+    [OUTPUT_FIELD]?: string;
+    [RUNTIME_FIELD]?: string;
+    [RAM_FIELD]: number;
+    [VCPUS_FIELD]: number;
+    [KEEP_CACHE_RAM_FIELD]?: number;
 }
 
 export const RunProcessAdvancedForm =
     reduxForm<RunProcessAdvancedFormData>({
-        form: RUN_PROCESS_ADVANCED_FORM
+        form: RUN_PROCESS_ADVANCED_FORM,
+        initialValues: {
+            [RAM_FIELD]: 1073741824,
+            [VCPUS_FIELD]: 1,
+        },
     })(() =>
         <form>
             <ExpansionPanel elevation={0}>
@@ -29,17 +46,56 @@ export const RunProcessAdvancedForm =
                     <Grid container spacing={32}>
                         <Grid item xs={12} md={6}>
                             <Field
-                                name='output'
+                                name={OUTPUT_FIELD}
                                 component={TextField}
                                 label="Output name" />
                         </Grid>
                         <Grid item xs={12} md={6}>
                             <Field
-                                name='runtime'
+                                name={RUNTIME_FIELD}
                                 component={TextField}
                                 label="Runtime limit (hh)" />
                         </Grid>
+                        <Grid item xs={12} md={6}>
+                            <Field
+                                name={RAM_FIELD}
+                                component={TextField}
+                                label="RAM"
+                                helperText="Number of ram bytes to be used to run this process."
+                                parse={IntInput.parse}
+                                format={IntInput.format}
+                                type='number'
+                                required
+                                validate={ramValidation} />
+                        </Grid>
+                        <Grid item xs={12} md={6}>
+                            <Field
+                                name={VCPUS_FIELD}
+                                component={TextField}
+                                label="VCPUs"
+                                helperText="Number of cores to be used to run this process."
+                                parse={IntInput.parse}
+                                format={IntInput.format}
+                                type='number'
+                                required
+                                validate={vcpusValidation} />
+                        </Grid>
+                        <Grid item xs={12} md={6}>
+                            <Field
+                                name={KEEP_CACHE_RAM_FIELD}
+                                component={TextField}
+                                label="Keep cache RAM"
+                                helperText="Number of keep cache bytes to be used to run this process."
+                                parse={IntInput.parse}
+                                format={IntInput.format}
+                                type='number'
+                                validate={keepCacheRamValdation} />
+                        </Grid>
                     </Grid>
                 </ExpansionPanelDetails>
             </ExpansionPanel>
         </form >);
+
+const ramValidation = [min(0)];
+const vcpusValidation = [min(1)];
+const keepCacheRamValdation = [optional(min(0))];