From 36e62deaa887cea4bd475e222c37c941af70534c Mon Sep 17 00:00:00 2001 From: Michal Klobukowski Date: Thu, 29 Nov 2018 14:25:22 +0100 Subject: [PATCH] Extract FileInput's getValidation function Feature #14524 Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski --- src/views/run-process-panel/inputs/file-input.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/views/run-process-panel/inputs/file-input.tsx b/src/views/run-process-panel/inputs/file-input.tsx index e5fa9663..c135042d 100644 --- a/src/views/run-process-panel/inputs/file-input.tsx +++ b/src/views/run-process-panel/inputs/file-input.tsx @@ -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; -- 2.30.2