X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/23180724fefb8b4b31e2c07e711101367942f721..691afce5b8573b3a89592b506b3a37d615d60bc1:/src/views/run-process-panel/inputs/directory-input.tsx

diff --git a/src/views/run-process-panel/inputs/directory-input.tsx b/src/views/run-process-panel/inputs/directory-input.tsx
index aa25fefc..29ccd6e0 100644
--- a/src/views/run-process-panel/inputs/directory-input.tsx
+++ b/src/views/run-process-panel/inputs/directory-input.tsx
@@ -3,23 +3,24 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from 'react';
+import { connect, DispatchProp } from 'react-redux';
+import { memoize } from 'lodash/fp';
+import { Field } from 'redux-form';
+import { Input, Dialog, DialogTitle, DialogContent, DialogActions, Button } from '@material-ui/core';
 import {
     isRequiredInput,
     DirectoryCommandInputParameter,
     CWLType,
     Directory
 } from '~/models/workflow';
-import { Field } from 'redux-form';
-import { Input, Dialog, DialogTitle, DialogContent, DialogActions, Button } from '@material-ui/core';
 import { GenericInputProps, GenericInput } from './generic-input';
 import { ProjectsTreePicker } from '~/views-components/projects-tree-picker/projects-tree-picker';
-import { connect, DispatchProp } from 'react-redux';
 import { initProjectsTreePicker } from '~/store/tree-picker/tree-picker-actions';
 import { TreeItem } from '~/components/tree/tree';
 import { ProjectsTreePickerItem } from '~/views-components/projects-tree-picker/generic-projects-tree-picker';
 import { CollectionResource } from '~/models/collection';
 import { ResourceKind } from '~/models/resource';
-import { ERROR_MESSAGE } from '../../../validators/require';
+import { ERROR_MESSAGE } from '~/validators/require';
 
 export interface DirectoryInputProps {
     input: DirectoryCommandInputParameter;
@@ -29,18 +30,25 @@ export const DirectoryInput = ({ input }: DirectoryInputProps) =>
         name={input.id}
         commandInput={input}
         component={DirectoryInputComponent}
-        format={(value?: Directory) => value ? value.basename : ''}
-        parse={(directory: CollectionResource): Directory => ({
-            class: CWLType.DIRECTORY,
-            location: `keep:${directory.portableDataHash}`,
-            basename: directory.name,
-        })}
-        validate={[
-            isRequiredInput(input)
-                ? (directory?: Directory) => directory ? undefined : ERROR_MESSAGE
-                : () => undefined,
-        ]} />;
-
+        format={format}
+        parse={parse}
+        validate={getValidation(input)} />;
+
+const format = (value?: Directory) => value ? value.basename : '';
+
+const parse = (directory: CollectionResource): Directory => ({
+    class: CWLType.DIRECTORY,
+    location: `keep:${directory.portableDataHash}`,
+    basename: directory.name,
+});
+
+const getValidation = memoize(
+    (input: DirectoryCommandInputParameter) => ([
+        isRequiredInput(input)
+            ? (directory?: Directory) => directory ? undefined : ERROR_MESSAGE
+            : () => undefined,
+    ])
+);
 
 interface DirectoryInputComponentState {
     open: boolean;
@@ -78,7 +86,7 @@ const DirectoryInputComponent = connect()(
             this.props.input.onChange(this.state.directory);
         }
 
-        setDirectory = (event: React.MouseEvent<HTMLElement>, { data }: TreeItem<ProjectsTreePickerItem>, pickerId: string) => {
+        setDirectory = (_: {}, { data }: TreeItem<ProjectsTreePickerItem>) => {
             if ('kind' in data && data.kind === ResourceKind.COLLECTION) {
                 this.setState({ directory: data });
             } else {
