Merge branch 'master' into 14452-my-account
[arvados-workbench2.git] / src / views / run-process-panel / inputs / file-input.tsx
index e5fa9663ceeaf8e613a3ac49decaedcf0facd1d0..0611100722a2e30512a675dc770b933d34cd88b6 100644 (file)
@@ -3,6 +3,7 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from 'react';
+import { memoize } from 'lodash/fp';
 import {
     isRequiredInput,
     FileCommandInputParameter,
@@ -30,11 +31,7 @@ export const FileInput = ({ input }: FileInputProps) =>
         component={FileInputComponent}
         format={format}
         parse={parse}
-        validate={[
-            isRequiredInput(input)
-                ? (file?: File) => file ? undefined : ERROR_MESSAGE
-                : () => undefined,
-        ]} />;
+        validate={getValidation(input)} />;
 
 const format = (value?: File) => value ? value.basename : '';
 
@@ -44,6 +41,13 @@ const parse = (file: CollectionFile): File => ({
     basename: file.name,
 });
 
+const getValidation = memoize(
+    (input: FileCommandInputParameter) => ([
+        isRequiredInput(input)
+            ? (file?: File) => file ? undefined : ERROR_MESSAGE
+            : () => undefined,
+    ]));
+
 interface FileInputComponentState {
     open: boolean;
     file?: CollectionFile;
@@ -80,7 +84,7 @@ const FileInputComponent = connect()(
             this.props.input.onChange(this.state.file);
         }
 
-        setFile = (event: React.MouseEvent<HTMLElement>, { data }: TreeItem<ProjectsTreePickerItem>, pickerId: string) => {
+        setFile = (_: {}, { data }: TreeItem<ProjectsTreePickerItem>) => {
             if ('type' in data && data.type === CollectionFileType.FILE) {
                 this.setState({ file: data });
             } else {