X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/81eb1ca6ea7faa2b8f2646f61cc00885d4cfcb83..a1e2b8ba77e4a7273940a3fc542bc42e282618a7:/src/views/run-process-panel/inputs/file-input.tsx?ds=sidebyside diff --git a/src/views/run-process-panel/inputs/file-input.tsx b/src/views/run-process-panel/inputs/file-input.tsx index 6b001b20..06111007 100644 --- a/src/views/run-process-panel/inputs/file-input.tsx +++ b/src/views/run-process-panel/inputs/file-input.tsx @@ -3,10 +3,23 @@ // SPDX-License-Identifier: AGPL-3.0 import * as React from 'react'; -import { getInputLabel, isRequiredInput, FileCommandInputParameter, File } from '~/models/workflow'; +import { memoize } from 'lodash/fp'; +import { + isRequiredInput, + FileCommandInputParameter, + File, + CWLType +} from '~/models/workflow'; import { Field } from 'redux-form'; -import { TextField } from '~/components/text-field/text-field'; -import { require } from '~/validators/require'; +import { ERROR_MESSAGE } from '~/validators/require'; +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 { CollectionFile, CollectionFileType } from '~/models/collection-file'; export interface FileInputProps { input: FileCommandInputParameter; @@ -14,12 +27,110 @@ export interface FileInputProps { export const FileInput = ({ input }: FileInputProps) => value ? value.location : ''} - validate={[ - isRequiredInput(input) - ? require - : () => undefined, - ]} />; + commandInput={input} + component={FileInputComponent} + format={format} + parse={parse} + validate={getValidation(input)} />; + +const format = (value?: File) => value ? value.basename : ''; + +const parse = (file: CollectionFile): File => ({ + class: CWLType.FILE, + location: `keep:${file.id}`, + basename: file.name, +}); + +const getValidation = memoize( + (input: FileCommandInputParameter) => ([ + isRequiredInput(input) + ? (file?: File) => file ? undefined : ERROR_MESSAGE + : () => undefined, + ])); + +interface FileInputComponentState { + open: boolean; + file?: CollectionFile; +} + +const FileInputComponent = connect()( + class FileInputComponent extends React.Component { + state: FileInputComponentState = { + open: false, + }; + + componentDidMount() { + this.props.dispatch( + initProjectsTreePicker(this.props.commandInput.id)); + } + + render() { + return <> + {this.renderInput()} + {this.renderDialog()} + ; + } + + openDialog = () => { + this.setState({ open: true }); + } + + closeDialog = () => { + this.setState({ open: false }); + } + + submit = () => { + this.closeDialog(); + this.props.input.onChange(this.state.file); + } + + setFile = (_: {}, { data }: TreeItem) => { + if ('type' in data && data.type === CollectionFileType.FILE) { + this.setState({ file: data }); + } else { + this.setState({ file: undefined }); + } + } + + renderInput() { + return + } + {...this.props} />; + } + + renderDialog() { + return + Choose a file + + + + + + + + ; + } + + }); +