Merge branch 'master' into 14452-my-account
[arvados-workbench2.git] / src / views / run-process-panel / inputs / enum-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 { Field } from 'redux-form';
7 import { Select, MenuItem } from '@material-ui/core';
8 import { EnumCommandInputParameter, CommandInputEnumSchema } from '~/models/workflow';
9 import { GenericInputProps, GenericInput } from './generic-input';
10
11 export interface EnumInputProps {
12     input: EnumCommandInputParameter;
13 }
14 export const EnumInput = ({ input }: EnumInputProps) =>
15     <Field
16         name={input.id}
17         commandInput={input}
18         component={EnumInputComponent}
19     />;
20
21 const EnumInputComponent = (props: GenericInputProps) =>
22     <GenericInput
23         component={Input}
24         {...props} />;
25
26 const Input = (props: GenericInputProps) => {
27     const type = props.commandInput.type as CommandInputEnumSchema;
28     return <Select
29         value={props.input.value}
30         onChange={props.input.onChange}
31         disabled={props.commandInput.disabled} >
32         {type.symbols.map(symbol =>
33             <MenuItem key={symbol} value={extractValue(symbol)}>
34                 {extractValue(symbol)}
35             </MenuItem>)}
36     </Select>;
37 };
38
39 /**
40  * Values in workflow definition have an absolute form, for example: 
41  * 
42  * ```#input_collector.cwl/enum_type/Pathway table```
43  * 
44  * We want a value that is in form accepted by backend.
45  * According to the example above, the correct value is:
46  * 
47  * ```Pathway table```
48  */
49 const extractValue = (symbol: string) => symbol.split('/').pop();