merge conflicts
[arvados-workbench2.git] / src / views / run-process-panel / inputs / file-input.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 {
7     getInputLabel,
8     isRequiredInput,
9     FileCommandInputParameter,
10     File,
11     CWLType
12 } from '~/models/workflow';
13 import { Field } from 'redux-form';
14 import { require } from '~/validators/require';
15 import { Input } from '@material-ui/core';
16 import { GenericInputProps, GenericInput } from './generic-input';
17
18 export interface FileInputProps {
19     input: FileCommandInputParameter;
20 }
21 export const FileInput = ({ input }: FileInputProps) =>
22     <Field
23         name={input.id}
24         commandInput={input}        
25         component={FileInputComponent}
26         format={(value?: File) => value ? value.location : ''}
27         parse={(value: string): File => ({
28             class: CWLType.FILE,
29             location: value,
30             basename: value.split('/').slice(1).join('/')
31         })}
32         validate={[
33             isRequiredInput(input)
34                 ? require
35                 : () => undefined,
36         ]} />;
37
38 const FileInputComponent = (props: GenericInputProps) =>
39     <GenericInput
40         component={props =>
41             <Input readOnly fullWidth value={props.input.value} error={props.meta.touched && !!props.meta.error}/>}
42         {...props} />;