From 0737f5067e29dea6a72a6612fddffe64d919e459 Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Fri, 8 Sep 2023 16:06:37 -0400 Subject: [PATCH] 19359: Support 'optional' enum type parameters Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- src/models/workflow.ts | 18 +++++++++++++++ src/views/process-panel/process-io-card.tsx | 13 +++++------ .../run-process-panel/inputs/enum-input.tsx | 23 ++++++++++++++----- .../run-process-inputs-form.tsx | 6 ++--- 4 files changed, 43 insertions(+), 17 deletions(-) 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, typ input.type.type === 'array' && input.type.items === type); +export const getEnumType = (input: GenericCommandInputParameter) => { + 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 } {/* 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)) && <> @@ -556,9 +557,7 @@ export const getIOParamDisplayValue = (auth: AuthState, input: CommandInputParam [directoryToProcessIOValue(directory, auth, pdh)] : [{ display: }]; - 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:
{enumValue}
}] : @@ -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) => ; 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