[arvados-workbench2] created: 2.6.3-104-g0737f506

git repository hosting git at public.arvados.org
Fri Sep 8 20:07:01 UTC 2023


        at  0737f5067e29dea6a72a6612fddffe64d919e459 (commit)


commit 0737f5067e29dea6a72a6612fddffe64d919e459
Author: Peter Amstutz <peter.amstutz at curii.com>
Date:   Fri Sep 8 16:06:37 2023 -0400

    19359: Support 'optional' enum type parameters
    
    Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz at curii.com>

diff --git a/src/models/workflow.ts b/src/models/workflow.ts
index 59b81a1d..369db4c7 100644
--- a/src/models/workflow.ts
+++ b/src/models/workflow.ts
@@ -193,6 +193,24 @@ export const isArrayOfType = (input: GenericCommandInputParameter<any, any>, typ
             input.type.type === 'array' &&
             input.type.items === type);
 
+export const getEnumType = (input: GenericCommandInputParameter<any, any>) => {
+    if (input.type instanceof Array) {
+        const f = input.type.filter(t => typeof t === 'object' &&
+            !(t instanceof Array) &&
+            t.type === 'enum');
+        if (f.length > 0) {
+            return f[0];
+        }
+    } else {
+        if ((typeof input.type === 'object' &&
+            !(input.type instanceof Array) &&
+            input.type.type === 'enum')) {
+            return input.type;
+        }
+    }
+    return null;
+};
+
 export const stringifyInputType = ({ type }: CommandInputParameter) => {
     if (typeof type === 'string') {
         return type;
diff --git a/src/views/process-panel/process-io-card.tsx b/src/views/process-panel/process-io-card.tsx
index c0dcb7f0..607bdeb7 100644
--- a/src/views/process-panel/process-io-card.tsx
+++ b/src/views/process-panel/process-io-card.tsx
@@ -56,6 +56,7 @@ import {
     isPrimitiveOfType,
     StringArrayCommandInputParameter,
     StringCommandInputParameter,
+    getEnumType
 } from "models/workflow";
 import { CommandOutputParameter } from 'cwlts/mappings/v1.0/CommandOutputParameter';
 import { File } from 'models/workflow';
@@ -305,9 +306,9 @@ export const ProcessIOCard = withStyles(styles)(connect(null, mapDispatchToProps
                             <CircularProgress />
                         </Grid>}
                         {/* Once loaded, either raw or params may still be empty
-			   *   Raw when all params are empty
-			   *   Params when raw is provided by containerRequest properties but workflow mount is absent for preview
-			   */}
+			  *   Raw when all params are empty
+			  *   Params when raw is provided by containerRequest properties but workflow mount is absent for preview
+			  */}
                         {(!loading && (hasRaw || hasParams)) &&
                             <>
                                 <Tabs value={mainProcTabState} onChange={handleMainProcTabChange} variant="fullWidth" className={classes.symmetricTabs}>
@@ -556,9 +557,7 @@ export const getIOParamDisplayValue = (auth: AuthState, input: CommandInputParam
                 [directoryToProcessIOValue(directory, auth, pdh)] :
                 [{ display: <EmptyValue /> }];
 
-        case typeof input.type === 'object' &&
-            !(input.type instanceof Array) &&
-            input.type.type === 'enum':
+        case getEnumType(input) !== null:
             const enumValue = (input as EnumCommandInputParameter).value;
             return enumValue !== undefined && enumValue ?
                 [{ display: <pre>{enumValue}</pre> }] :
@@ -590,7 +589,7 @@ export const getIOParamDisplayValue = (auth: AuthState, input: CommandInputParam
 
             // Convert each main and secondaryFiles into array of ProcessIOValue preserving ordering
             let fileArrayValues: ProcessIOValue[] = [];
-            for(let i = 0; i < fileArrayMainFiles.length; i++) {
+            for (let i = 0; i < fileArrayMainFiles.length; i++) {
                 const secondaryFiles = ((fileArrayMainFiles[i] as unknown) as FileWithSecondaryFiles)?.secondaryFiles || [];
                 fileArrayValues.push(
                     // Pass firstMainFilePdh to secondary files and every main file besides the first to hide pdh if equal
diff --git a/src/views/run-process-panel/inputs/enum-input.tsx b/src/views/run-process-panel/inputs/enum-input.tsx
index f554aff2..8a999786 100644
--- a/src/views/run-process-panel/inputs/enum-input.tsx
+++ b/src/views/run-process-panel/inputs/enum-input.tsx
@@ -4,18 +4,29 @@
 
 import React from 'react';
 import { Field } from 'redux-form';
+import { memoize } from 'lodash/fp';
+import { require } from 'validators/require';
 import { Select, MenuItem } from '@material-ui/core';
-import { EnumCommandInputParameter, CommandInputEnumSchema } from 'models/workflow';
+import { EnumCommandInputParameter, CommandInputEnumSchema, isRequiredInput, getEnumType } from 'models/workflow';
 import { GenericInputProps, GenericInput } from './generic-input';
 
 export interface EnumInputProps {
     input: EnumCommandInputParameter;
 }
+
+const getValidation = memoize(
+    (input: EnumCommandInputParameter) => ([
+        isRequiredInput(input)
+            ? require
+            : () => undefined,
+    ]));
+
 export const EnumInput = ({ input }: EnumInputProps) =>
     <Field
         name={input.id}
         commandInput={input}
         component={EnumInputComponent}
+        validate={getValidation(input)}
     />;
 
 const EnumInputComponent = (props: GenericInputProps) =>
@@ -24,7 +35,7 @@ const EnumInputComponent = (props: GenericInputProps) =>
         {...props} />;
 
 const Input = (props: GenericInputProps) => {
-    const type = props.commandInput.type as CommandInputEnumSchema;
+    const type = getEnumType(props.commandInput) as CommandInputEnumSchema;
     return <Select
         value={props.input.value}
         onChange={props.input.onChange}
@@ -37,13 +48,13 @@ const Input = (props: GenericInputProps) => {
 };
 
 /**
- * Values in workflow definition have an absolute form, for example: 
- * 
+ * Values in workflow definition have an absolute form, for example:
+ *
  * ```#input_collector.cwl/enum_type/Pathway table```
- * 
+ *
  * We want a value that is in form accepted by backend.
  * According to the example above, the correct value is:
- * 
+ *
  * ```Pathway table```
  */
 const extractValue = (symbol: string) => symbol.split('/').pop();
diff --git a/src/views/run-process-panel/run-process-inputs-form.tsx b/src/views/run-process-panel/run-process-inputs-form.tsx
index 46ab3c52..ca402ab0 100644
--- a/src/views/run-process-panel/run-process-inputs-form.tsx
+++ b/src/views/run-process-panel/run-process-inputs-form.tsx
@@ -7,7 +7,7 @@ import { reduxForm, InjectedFormProps } from 'redux-form';
 import { CommandInputParameter, CWLType, IntCommandInputParameter, BooleanCommandInputParameter, FileCommandInputParameter, DirectoryCommandInputParameter, DirectoryArrayCommandInputParameter, FloatArrayCommandInputParameter, IntArrayCommandInputParameter } from 'models/workflow';
 import { IntInput } from 'views/run-process-panel/inputs/int-input';
 import { StringInput } from 'views/run-process-panel/inputs/string-input';
-import { StringCommandInputParameter, FloatCommandInputParameter, isPrimitiveOfType, WorkflowInputsData, EnumCommandInputParameter, isArrayOfType, StringArrayCommandInputParameter, FileArrayCommandInputParameter } from '../../models/workflow';
+import { StringCommandInputParameter, FloatCommandInputParameter, isPrimitiveOfType, WorkflowInputsData, EnumCommandInputParameter, isArrayOfType, StringArrayCommandInputParameter, FileArrayCommandInputParameter, getEnumType } from '../../models/workflow';
 import { FloatInput } from 'views/run-process-panel/inputs/float-input';
 import { BooleanInput } from './inputs/boolean-input';
 import { FileInput } from './inputs/file-input';
@@ -94,9 +94,7 @@ const getInputComponent = (input: CommandInputParameter) => {
         case isPrimitiveOfType(input, CWLType.DIRECTORY):
             return <DirectoryInput options={{ showOnlyOwned: false, showOnlyWritable: false }} input={input as DirectoryCommandInputParameter} />;
 
-        case typeof input.type === 'object' &&
-            !(input.type instanceof Array) &&
-            input.type.type === 'enum':
+        case getEnumType(input) !== null:
             return <EnumInput input={input as EnumCommandInputParameter} />;
 
         case isArrayOfType(input, CWLType.STRING):

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list