Create separate types for command inputs
authorMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Fri, 28 Sep 2018 13:15:34 +0000 (15:15 +0200)
committerMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Fri, 28 Sep 2018 13:15:34 +0000 (15:15 +0200)
Feature #13863

Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski@contractors.roche.com>

src/components/workflow-inputs-form/validators.ts [new file with mode: 0644]
src/components/workflow-inputs-form/workflow-input.tsx [new file with mode: 0644]
src/models/workflow.ts
src/views/workflow-panel/workflow-description-card.tsx

diff --git a/src/components/workflow-inputs-form/validators.ts b/src/components/workflow-inputs-form/validators.ts
new file mode 100644 (file)
index 0000000..9e1e24e
--- /dev/null
@@ -0,0 +1,21 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import { CommandInputParameter } from '~/models/workflow';
+import { require } from '~/validators/require';
+import { CWLType } from '../../models/workflow';
+
+
+const alwaysValid = () => undefined;
+
+export const required = ({ type }: CommandInputParameter) => {
+    if (type instanceof Array) {
+        for (const t of type) {
+            if (t === CWLType.NULL) {
+                return alwaysValid;
+            }
+        }
+    }
+    return require;
+};
diff --git a/src/components/workflow-inputs-form/workflow-input.tsx b/src/components/workflow-inputs-form/workflow-input.tsx
new file mode 100644 (file)
index 0000000..3a15d15
--- /dev/null
@@ -0,0 +1,18 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import * as React from 'react';
+import { CommandInputParameter } from '~/models/workflow';
+import { TextField } from '@material-ui/core';
+import { required } from '~/components/workflow-inputs-form/validators';
+
+export interface WorkflowInputProps {
+    input: CommandInputParameter;
+}
+export const WorkflowInput = ({ input }: WorkflowInputProps) =>
+    <TextField
+        label={`${input.label || input.id}${required(input)() ? '*' : ''}`}
+        name={input.id}
+        helperText={input.doc}
+        fullWidth />;
\ No newline at end of file
index 923a9cbd31efb6bcff7bae863e239664b55973c6..95cc926fbd09dfa19eff94abb897d2f8bcb6b053 100644 (file)
@@ -31,13 +31,19 @@ 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 |
+    FileArrayCommandInputParameter |
+    DirectoryArrayCommandInputParameter |
+    EnumCommandInputParameter;
 
 export enum CWLType {
     NULL = 'null',
@@ -58,8 +64,8 @@ export interface CommandInputEnumSchema {
     name?: string;
 }
 
-export interface CommandInputArraySchema {
-    items: CWLType;
+export interface CommandInputArraySchema<ItemType> {
+    items: ItemType;
     type: 'array';
     label?: string;
 }
@@ -78,6 +84,29 @@ 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>;
+}
+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 FileArrayCommandInputParameter = GenericArrayCommandInputParameter<CWLType.FILE, File>;
+export type DirectoryArrayCommandInputParameter = GenericArrayCommandInputParameter<CWLType.DIRECTORY, Directory>;
+
 export const parseWorkflowDefinition = (workflow: WorkflowResource): WorkflowResoruceDefinition => {
     const definition = safeLoad(workflow.definition);
     return definition;
index 57cf89f7ea855d129413b4160c21a0300e058030..f6b2fcba38967a16b9a0800f597c1ced7e602670 100644 (file)
@@ -7,8 +7,8 @@ import { StyleRulesCallback, WithStyles, withStyles, CardContent, Tab, Tabs, Pap
 import { ArvadosTheme } from '~/common/custom-theme';
 import { WorkflowIcon } from '~/components/icon/icon';
 import { DataTableDefaultView } from '~/components/data-table-default-view/data-table-default-view';
-import { WorkflowResource, parseWorkflowDefinition, getWorkflowInputs, stringifyInputType } from '~/models/workflow';
-import { DetailsAttribute } from '~/components/details-attribute/details-attribute';
+import { WorkflowResource, parseWorkflowDefinition, getWorkflowInputs } from '~/models/workflow';
+import { WorkflowInput } from '~/components/workflow-inputs-form/workflow-input';
 
 export type CssRules = 'root' | 'tab';
 
@@ -54,7 +54,7 @@ export const WorkflowDetailsCard = withStyles(styles)(
                 </CardContent>}
                 {value === 1 && <CardContent>
                     {workflow && this.inputs
-                        ? this.inputs.map(input => <DetailsAttribute key={input.id} label={input.label || ''} value={stringifyInputType(input)} />)
+                        ? this.inputs.map(input => <WorkflowInput key={input.id} input={input}/>)
                         : <DataTableDefaultView
                             icon={WorkflowIcon}
                             messages={['Please select a workflow to see its description.']} />}