18257: Adds checks to array values thay may be null or undefined.
[arvados-workbench2.git] / src / views / run-process-panel / inputs / string-array-input.tsx
index 3b29d1a8cf9fa48c822b3b1019b5e9f56cc5e877..8955009a0d52984a9393b675e9721825f4a746d0 100644 (file)
@@ -2,14 +2,15 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import * as React from 'react';
-import { isRequiredInput, StringArrayCommandInputParameter } from '~/models/workflow';
+import React from 'react';
+import { isRequiredInput, StringArrayCommandInputParameter } from 'models/workflow';
 import { Field } from 'redux-form';
-import { ERROR_MESSAGE } from '~/validators/require';
-import { GenericInputProps, GenericInput } from '~/views/run-process-panel/inputs/generic-input';
-import { ChipsInput } from '~/components/chips-input/chips-input';
+import { ERROR_MESSAGE } from 'validators/require';
+import { GenericInputProps, GenericInput } from 'views/run-process-panel/inputs/generic-input';
+import { ChipsInput } from 'components/chips-input/chips-input';
 import { identity } from 'lodash';
 import { createSelector } from 'reselect';
+import { Input } from '@material-ui/core';
 
 export interface StringArrayInputProps {
     input: StringArrayCommandInputParameter;
@@ -29,22 +30,30 @@ const validationSelector = createSelector(
         : undefined
 );
 
-const required = (value: string[]) =>
-    value.length > 0
+const required = (value: string[] = []) =>
+    value && value.length > 0
         ? undefined
         : ERROR_MESSAGE;
 
 const StringArrayInputComponent = (props: GenericInputProps) =>
     <GenericInput
-        component={Input}
+        component={InputComponent}
         {...props} />;
 
-class Input extends React.PureComponent<GenericInputProps>{
+class InputComponent extends React.PureComponent<GenericInputProps>{
     render() {
+        const { commandInput, input, meta } = this.props;
         return <ChipsInput
-            values={this.props.input.value}
+            deletable={!commandInput.disabled}
+            orderable={!commandInput.disabled}
+            disabled={commandInput.disabled}
+            values={input.value}
             onChange={this.handleChange}
-            createNewValue={identity} />;
+            createNewValue={identity}
+            inputComponent={Input}
+            inputProps={{
+                error: meta.error
+            }} />;
     }
 
     handleChange = (values: {}[]) => {