X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/9c15617f293ab41ea8b8e2962ecd1d109b80a026..e8e0182d65a74b1a222127eb8b36f31a906b14c8:/src/views/run-process-panel/inputs/file-input.tsx diff --git a/src/views/run-process-panel/inputs/file-input.tsx b/src/views/run-process-panel/inputs/file-input.tsx index a356d829..7e0925e8 100644 --- a/src/views/run-process-panel/inputs/file-input.tsx +++ b/src/views/run-process-panel/inputs/file-input.tsx @@ -4,16 +4,21 @@ import * as React from 'react'; import { - getInputLabel, isRequiredInput, FileCommandInputParameter, File, CWLType } from '~/models/workflow'; import { Field } from 'redux-form'; -import { require } from '~/validators/require'; -import { Input } from '@material-ui/core'; +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; @@ -21,22 +26,104 @@ export interface FileInputProps { export const FileInput = ({ input }: FileInputProps) => value ? value.location : ''} - parse={(value: string): File => ({ + format={(value?: File) => value ? value.basename : ''} + parse={(file: CollectionFile): File => ({ class: CWLType.FILE, - location: value, - basename: value.split('/').slice(1).join('/') + location: `keep:${file.id}`, + basename: file.name, })} validate={[ isRequiredInput(input) - ? require + ? (file?: File) => file ? undefined : ERROR_MESSAGE : () => undefined, ]} />; -const FileInputComponent = (props: GenericInputProps) => - - } - {...props} />; + +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 = (event: React.MouseEvent, { data }: TreeItem, pickerId: string) => { + 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 + + + + + + + + ; + } + + }); + +