Create enum input
authorMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Tue, 2 Oct 2018 11:53:26 +0000 (13:53 +0200)
committerMichal Klobukowski <michal.klobukowski@contractors.roche.com>
Tue, 2 Oct 2018 11:53:26 +0000 (13:53 +0200)
Feature #13863

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

src/index.tsx
src/views/run-process-panel/inputs/enum-input.tsx [new file with mode: 0644]
src/views/run-process-panel/run-process-inputs-form.tsx

index 71d10fe26546d7b234678ed6f7e10536d3f3b60a..a4a5e366a26b1c93713e580c4ce717a1c4e4a117 100644 (file)
@@ -113,12 +113,12 @@ const initListener = (history: History, store: RootStore, services: ServiceRepos
             initWebSocket(config, services.authService, store);
             await store.dispatch(loadWorkbench());
             addRouteChangeHandlers(history, store);
-            
+            // createEnumCollectorWorkflow(services);
         }
     };
 };
 
-const createSampleWorkflow = ({workflowService}:ServiceRepository) => {
+const createPrimitivesCollectorWorkflow = ({workflowService}:ServiceRepository) => {
     workflowService.create({
             name: 'Primitive values collector',
             description: 'Workflow for collecting primitive values',
@@ -126,6 +126,14 @@ const createSampleWorkflow = ({workflowService}:ServiceRepository) => {
         });
 };
 
+const createEnumCollectorWorkflow = ({workflowService}:ServiceRepository) => {
+    workflowService.create({
+            name: 'Enum values collector',
+            description: 'Workflow for collecting enum values',
+            definition: "cwlVersion: v1.0\n$graph:\n- class: CommandLineTool\n  requirements:\n  - listing:\n    - entryname: input_collector.log\n      entry: |\n        \"enum_type\":\n          $(inputs.enum_type)\n\n    class: InitialWorkDirRequirement\n  inputs:\n  - type:\n      type: enum\n      symbols: ['#input_collector.cwl/enum_type/OTU table', '#input_collector.cwl/enum_type/Pathway\n          table', '#input_collector.cwl/enum_type/Function table', '#input_collector.cwl/enum_type/Ortholog\n          table']\n    id: '#input_collector.cwl/enum_type'\n  outputs:\n  - type: File\n    outputBinding:\n      glob: '*'\n    id: '#input_collector.cwl/output'\n  baseCommand: [echo]\n  id: '#input_collector.cwl'\n- class: Workflow\n  doc: This is the description of the workflow\n  inputs:\n  - type:\n      type: enum\n      symbols: ['#main/enum_type/OTU table', '#main/enum_type/Pathway table', '#main/enum_type/Function\n          table', '#main/enum_type/Ortholog table']\n      name: '#enum_typef4179c7f-45f9-482d-a5db-1abb86698384'\n    label: Enumeration Type\n    doc: This should render as a drop-down menu.\n    id: '#main/enum_type'\n    default: OTU table\n  outputs:\n  - type: File\n    outputSource: '#main/input_collector/output'\n    id: '#main/log_file'\n  steps:\n  - run: '#input_collector.cwl'\n    in:\n    - source: '#main/enum_type'\n      id: '#main/input_collector/enum_type'\n    out: ['#main/input_collector/output']\n    id: '#main/input_collector'\n  id: '#main'\n",
+        });
+};
+
 const createSampleProcess = ({ containerRequestService }: ServiceRepository) => {
     containerRequestService.create({
         ownerUuid: 'c97qk-j7d0g-s3ngc1z0748hsmf',
diff --git a/src/views/run-process-panel/inputs/enum-input.tsx b/src/views/run-process-panel/inputs/enum-input.tsx
new file mode 100644 (file)
index 0000000..967d8fc
--- /dev/null
@@ -0,0 +1,36 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import * as React from 'react';
+import { EnumCommandInputParameter, CommandInputEnumSchema } from '~/models/workflow';
+import { Field } from 'redux-form';
+import { Select, MenuItem } from '@material-ui/core';
+import { GenericInputProps, GenericInput } from './generic-input';
+
+export interface EnumInputProps {
+    input: EnumCommandInputParameter;
+}
+export const EnumInput = ({ input }: EnumInputProps) =>
+    <Field
+        name={input.id}
+        commandInput={input}
+        component={EnumInputComponent}
+    />;
+
+const EnumInputComponent = (props: GenericInputProps) =>
+    <GenericInput
+        component={Input}
+        {...props} />;
+
+const Input = (props: GenericInputProps) => {
+    const type = props.commandInput.type as CommandInputEnumSchema;
+    return <Select
+        value={props.input.value}
+        onChange={props.input.onChange}>
+        {type.symbols.map(symbol =>
+            <MenuItem key={symbol} value={symbol.split('/').pop()}>
+                {symbol.split('/').pop()}
+            </MenuItem>)}
+    </Select>;
+};
\ No newline at end of file
index 9e6f5907f847279903df93ceb0c45658018bf756..b0d5d5fefb4505537a1322e1be47f6332aa01033 100644 (file)
@@ -7,13 +7,14 @@ import { reduxForm, InjectedFormProps } from 'redux-form';
 import { CommandInputParameter, CWLType, IntCommandInputParameter, BooleanCommandInputParameter, FileCommandInputParameter } 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, File, Directory, WorkflowInputsData } from '../../models/workflow';
+import { StringCommandInputParameter, FloatCommandInputParameter, isPrimitiveOfType, File, Directory, WorkflowInputsData, EnumCommandInputParameter } 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';
 import { connect } from 'react-redux';
 import { compose } from 'redux';
 import { Grid, StyleRulesCallback, withStyles, WithStyles } from '@material-ui/core';
+import { EnumInput } from './inputs/enum-input';
 
 export const RUN_PROCESS_INPUTS_FORM = 'runProcessInputsForm';
 
@@ -71,6 +72,11 @@ const getInputComponent = (input: CommandInputParameter) => {
         case isPrimitiveOfType(input, CWLType.FILE):
             return <FileInput input={input as FileCommandInputParameter} />;
 
+        case typeof input.type === 'object' &&
+            !(input.type instanceof Array) &&
+            input.type.type === 'enum':
+            return <EnumInput input={input as EnumCommandInputParameter} />;
+
         default:
             return null;
     }