19359: Can select empty item to clear optional enum input 19359-optional-enum
authorPeter Amstutz <peter.amstutz@curii.com>
Thu, 14 Sep 2023 21:06:11 +0000 (17:06 -0400)
committerPeter Amstutz <peter.amstutz@curii.com>
Thu, 14 Sep 2023 21:07:19 +0000 (17:07 -0400)
Sets the field value to null, which means "use default value" in CWL.

Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz@curii.com>

src/views/run-process-panel/inputs/enum-input.tsx

index 8a999786097f19626d92f4dd8bb56478b08a66a5..207a30acd0f6f0d28691fcf0d0db74e2e075efdc 100644 (file)
@@ -21,12 +21,21 @@ const getValidation = memoize(
             : () => undefined,
     ]));
 
+const emptyToNull = value => {
+    if (value === '') {
+        return null;
+    } else {
+        return value;
+    }
+};
+
 export const EnumInput = ({ input }: EnumInputProps) =>
     <Field
         name={input.id}
         commandInput={input}
         component={EnumInputComponent}
         validate={getValidation(input)}
+        normalize={emptyToNull}
     />;
 
 const EnumInputComponent = (props: GenericInputProps) =>
@@ -40,10 +49,10 @@ const Input = (props: GenericInputProps) => {
         value={props.input.value}
         onChange={props.input.onChange}
         disabled={props.commandInput.disabled} >
-        {type.symbols.map(symbol =>
+        {(isRequiredInput(props.commandInput) ? [] : [<MenuItem key={'_empty'} value={''} />]).concat(type.symbols.map(symbol =>
             <MenuItem key={symbol} value={extractValue(symbol)}>
                 {extractValue(symbol)}
-            </MenuItem>)}
+            </MenuItem>))}
     </Select>;
 };