15255: Log missing workbench2Url value to console.
[arvados.git] / src / models / workflow.ts
index 923a9cbd31efb6bcff7bae863e239664b55973c6..a858c0d7dec98e62d65087740bdf902d1153ec08 100644 (file)
@@ -13,7 +13,8 @@ export interface WorkflowResource extends Resource {
 }
 export interface WorkflowResoruceDefinition {
     cwlVersion: string;
-    $graph: Array<Workflow | CommandLineTool>;
+    graph?: Array<Workflow | CommandLineTool>;
+    $graph?: Array<Workflow | CommandLineTool>;
 }
 export interface Workflow {
     class: 'Workflow';
@@ -31,13 +32,21 @@ export interface CommandLineTool {
     outputs: any[];
 }
 
-export interface CommandInputParameter {
-    id: string;
-    label?: string;
-    doc?: string | string[];
-    default?: any;
-    type?: CWLType | CWLType[] | CommandInputEnumSchema | CommandInputArraySchema;
-}
+export type CommandInputParameter =
+    BooleanCommandInputParameter |
+    IntCommandInputParameter |
+    LongCommandInputParameter |
+    FloatCommandInputParameter |
+    DoubleCommandInputParameter |
+    StringCommandInputParameter |
+    FileCommandInputParameter |
+    DirectoryCommandInputParameter |
+    StringArrayCommandInputParameter |
+    IntArrayCommandInputParameter |
+    FloatArrayCommandInputParameter |
+    FileArrayCommandInputParameter |
+    DirectoryArrayCommandInputParameter |
+    EnumCommandInputParameter;
 
 export enum CWLType {
     NULL = 'null',
@@ -58,8 +67,8 @@ export interface CommandInputEnumSchema {
     name?: string;
 }
 
-export interface CommandInputArraySchema {
-    items: CWLType;
+export interface CommandInputArraySchema<ItemType> {
+    items: ItemType;
     type: 'array';
     label?: string;
 }
@@ -78,18 +87,81 @@ export interface Directory {
     basename?: string;
 }
 
+export interface GenericCommandInputParameter<Type, Value> {
+    id: string;
+    label?: string;
+    doc?: string | string[];
+    default?: Value;
+    type?: Type | Array<Type | CWLType.NULL>;
+    value?: Value;
+    disabled?: boolean;
+}
+export type GenericArrayCommandInputParameter<Type, Value> = GenericCommandInputParameter<CommandInputArraySchema<Type>, Value[]>;
+
+export type BooleanCommandInputParameter = GenericCommandInputParameter<CWLType.BOOLEAN, boolean>;
+export type IntCommandInputParameter = GenericCommandInputParameter<CWLType.INT, number>;
+export type LongCommandInputParameter = GenericCommandInputParameter<CWLType.LONG, number>;
+export type FloatCommandInputParameter = GenericCommandInputParameter<CWLType.FLOAT, number>;
+export type DoubleCommandInputParameter = GenericCommandInputParameter<CWLType.DOUBLE, number>;
+export type StringCommandInputParameter = GenericCommandInputParameter<CWLType.STRING, string>;
+export type FileCommandInputParameter = GenericCommandInputParameter<CWLType.FILE, File>;
+export type DirectoryCommandInputParameter = GenericCommandInputParameter<CWLType.DIRECTORY, Directory>;
+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;
 };
 
 export const getWorkflowInputs = (workflowDefinition: WorkflowResoruceDefinition) => {
-    const mainWorkflow = workflowDefinition.$graph.find(item => item.class === 'Workflow' && item.id === '#main');
-    return mainWorkflow
-        ? mainWorkflow.inputs
-        : undefined;
+    if (workflowDefinition.graph) {
+        const mainWorkflow = workflowDefinition.graph.find(item => item.class === 'Workflow' && item.id === '#main');
+        return mainWorkflow
+            ? mainWorkflow.inputs
+            : undefined;
+    } else {
+        const mainWorkflow = workflowDefinition.$graph!.find(item => item.class === 'Workflow' && item.id === '#main');
+        return mainWorkflow
+            ? 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') {
         return type;