1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { Field } from 'redux-form';
7 import { memoize } from 'lodash/fp';
8 import { require } from 'validators/require';
9 import { Select, MenuItem } from '@material-ui/core';
10 import { EnumCommandInputParameter, CommandInputEnumSchema, isRequiredInput, getEnumType } from 'models/workflow';
11 import { GenericInputProps, GenericInput } from './generic-input';
13 export interface EnumInputProps {
14 input: EnumCommandInputParameter;
17 const getValidation = memoize(
18 (input: EnumCommandInputParameter) => ([
19 isRequiredInput(input)
24 const emptyToNull = value => {
32 export const EnumInput = ({ input }: EnumInputProps) =>
36 component={EnumInputComponent}
37 validate={getValidation(input)}
38 normalize={emptyToNull}
41 const EnumInputComponent = (props: GenericInputProps) =>
46 const Input = (props: GenericInputProps) => {
47 const type = getEnumType(props.commandInput) as CommandInputEnumSchema;
49 value={props.input.value}
50 onChange={props.input.onChange}
51 disabled={props.commandInput.disabled} >
52 {(isRequiredInput(props.commandInput) ? [] : [<MenuItem key={'_empty'} value={''} />]).concat(type.symbols.map(symbol =>
53 <MenuItem key={symbol} value={extractValue(symbol)}>
54 {extractValue(symbol)}
60 * Values in workflow definition have an absolute form, for example:
62 * ```#input_collector.cwl/enum_type/Pathway table```
64 * We want a value that is in form accepted by backend.
65 * According to the example above, the correct value is:
69 const extractValue = (symbol: string) => symbol.split('/').pop();