X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/8a85c509e4f2100082cfed6157d31c8651b861c9..91d197b6b7066c3f37b3dbd54b2b3416e6f21bec:/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 7c4402fecd..b0206e1452 100644 --- a/src/views/run-process-panel/inputs/file-input.tsx +++ b/src/views/run-process-panel/inputs/file-input.tsx @@ -2,41 +2,159 @@ // // SPDX-License-Identifier: AGPL-3.0 -import * as React from 'react'; +import React from 'react'; +import { memoize } from 'lodash/fp'; import { - getInputLabel, isRequiredInput, FileCommandInputParameter, File, CWLType -} from '~/models/workflow'; +} 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, StyleRulesCallback, withStyles, WithStyles } 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 'store/tree-picker/tree-picker-middleware'; +import { CollectionFile, CollectionFileType } from 'models/collection-file'; export interface FileInputProps { input: FileCommandInputParameter; + options?: { showOnlyOwned: boolean, showOnlyWritable: boolean }; } -export const FileInput = ({ input }: FileInputProps) => + +type DialogContentCssRules = 'root' | 'pickerWrapper'; + +export const FileInput = ({ input, options }: FileInputProps) => value ? value.location : ''} - parse={(value: string): File => ({ - class: CWLType.FILE, - location: value, - basename: value.split('/').slice(1).join('/') - })} - validate={[ - isRequiredInput(input) - ? require - : () => undefined, - ]} />; - -const FileInputComponent = (props: GenericInputProps) => - - } - {...props} />; + commandInput={input} + component={FileInputComponent as any} + format={format} + parse={parse} + {...{ + options + }} + 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()} + + ; + } + + openDialog = () => { + this.componentDidMount(); + 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} />; + } + + dialogContentStyles: StyleRulesCallback = ({ spacing }) => ({ + root: { + display: 'flex', + flexDirection: 'column', + }, + pickerWrapper: { + flexBasis: `${spacing.unit * 8}vh`, + flexShrink: 1, + minHeight: 0, + }, + }); + + dialog = withStyles(this.dialogContentStyles)( + ({ classes }: WithStyles) => + + Choose a file + +
+ +
+
+ + + + +
+ ); + });