Handle errors while fetching fileViewersConfig
[arvados.git] / src / views-components / process-input-dialog / process-input-dialog.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 { Dialog, DialogActions, Button, CardHeader, DialogContent } from '@material-ui/core';
7 import { WithDialogProps } from '~/store/dialog/with-dialog';
8 import { withDialog } from "~/store/dialog/with-dialog";
9 import { PROCESS_INPUT_DIALOG_NAME } from '~/store/processes/process-input-actions';
10 import { RunProcessInputsForm } from "~/views/run-process-panel/run-process-inputs-form";
11
12 export const ProcessInputDialog = withDialog(PROCESS_INPUT_DIALOG_NAME)(
13     (props: WithDialogProps<any>) =>
14         <Dialog
15             open={props.open}
16             maxWidth={false}
17             onClose={props.closeDialog}>
18             <CardHeader
19                 title="Inputs - Pipeline template that generates a config file from a template" />
20             <DialogContent>
21                 <RunProcessInputsForm inputs={getInputs(props.data.containerRequest)} />
22             </DialogContent>
23             <DialogActions>
24                 <Button
25                     variant='flat'
26                     color='primary'
27                     onClick={props.closeDialog}>
28                     Close
29                 </Button>
30             </DialogActions>
31         </Dialog>
32 );
33
34 const getInputs = (data: any) =>
35     data && data.mounts.varLibCwlWorkflowJson ? data.mounts.varLibCwlWorkflowJson.content.graph[1].inputs.map((it: any) => (
36         { type: it.type, id: it.id, label: it.label, value: getInputValue(it.id, data.mounts.varLibCwlCwlInputJson.content), disabled: true }
37     )) : [];
38
39 const getInputValue = (id: string, data: any) => {
40     switch (id) {
41         case "#main/example_flag":
42             return data.exampleFlag;
43         case "#main/example_directory":
44             return data.exampleDirectory;
45         case "#main/example_double":
46             return data.exampleDouble;
47         case "#main/example_file":
48             return data.exampleFile;
49         case "#main/example_float":
50             return data.exampleFloat;
51         case "#main/example_int":
52             return data.exampleInt;
53         case "#main/example_long":
54             return data.exampleLong;
55         case "#main/example_null":
56             return data.exampleNull;
57         case "#main/example_string":
58             return data.exampleString;
59         case "#main/enum_type":
60             return data.enumType;
61         case "#main/multiple_collections":
62             return data.multipleCollections;
63         case "#main/example_string_array":
64             return data.exampleStringArray;
65         case "#main/example_int_array":
66             return data.exampleIntArray;
67         case "#main/example_float_array":
68             return data.exampleFloatArray;
69         case "#main/multiple_files":
70             return data.multipleFiles;
71         case "#main/collection":
72             return data.collection;
73         case "#main/optional_file_missing_label":
74             return data.optionalFileMissingLabel;
75         case "#main/optional_file":
76             return data.optionalFile;
77         case "#main/single_file":
78             return data.singleFile;
79         default:
80             return data.exampleString;
81     }
82 };