Merge branch 'master' of git.curoverse.com:arvados-workbench2 into 14361-broken-input...
[arvados-workbench2.git] / src / models / workflow.ts
index 95cc926fbd09dfa19eff94abb897d2f8bcb6b053..a342dbbfc5fde437e8dbdfb101f8ae3d612ce559 100644 (file)
@@ -41,6 +41,8 @@ export type CommandInputParameter =
     FileCommandInputParameter |
     DirectoryCommandInputParameter |
     StringArrayCommandInputParameter |
+    IntArrayCommandInputParameter |
+    FloatArrayCommandInputParameter |
     FileArrayCommandInputParameter |
     DirectoryArrayCommandInputParameter |
     EnumCommandInputParameter;
@@ -104,9 +106,14 @@ export type DirectoryCommandInputParameter = GenericCommandInputParameter<CWLTyp
 export type EnumCommandInputParameter = GenericCommandInputParameter<CommandInputEnumSchema, string>;
 
 export type StringArrayCommandInputParameter = GenericArrayCommandInputParameter<CWLType.STRING, string>;
+export type IntArrayCommandInputParameter = GenericArrayCommandInputParameter<CWLType.INT, string>;
+export type FloatArrayCommandInputParameter = GenericArrayCommandInputParameter<CWLType.FLOAT, string>;
 export type FileArrayCommandInputParameter = GenericArrayCommandInputParameter<CWLType.FILE, File>;
 export type DirectoryArrayCommandInputParameter = GenericArrayCommandInputParameter<CWLType.DIRECTORY, Directory>;
 
+export type WorkflowInputsData = {
+    [key: string]: boolean | number | string | File | Directory;
+};
 export const parseWorkflowDefinition = (workflow: WorkflowResource): WorkflowResoruceDefinition => {
     const definition = safeLoad(workflow.definition);
     return definition;
@@ -118,6 +125,31 @@ export const getWorkflowInputs = (workflowDefinition: WorkflowResoruceDefinition
         ? mainWorkflow.inputs
         : undefined;
 };
+export const getInputLabel = (input: CommandInputParameter) => {
+    return `${input.label || input.id}`;
+};
+
+export const isRequiredInput = ({ type }: CommandInputParameter) => {
+    if (type instanceof Array) {
+        for (const t of type) {
+            if (t === CWLType.NULL) {
+                return false;
+            }
+        }
+    }
+    return true;
+};
+
+export const isPrimitiveOfType = (input: GenericCommandInputParameter<any, any>, type: CWLType) =>
+    input.type instanceof Array
+        ? input.type.indexOf(type) > -1
+        : input.type === type;
+
+export const isArrayOfType = (input: GenericCommandInputParameter<any, any>, type: CWLType) =>
+    typeof input.type === 'object' &&
+        input.type.type === 'array'
+        ? input.type.items === type
+        : false;
 
 export const stringifyInputType = ({ type }: CommandInputParameter) => {
     if (typeof type === 'string') {