X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/be15af4fb02ada88b6c100beee27fab243ff65f4..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 838aa5193b..b0206e1452 100644 --- a/src/views/run-process-panel/inputs/file-input.tsx +++ b/src/views/run-process-panel/inputs/file-input.tsx @@ -2,45 +2,58 @@ // // SPDX-License-Identifier: AGPL-3.0 -import * as React from 'react'; +import React from 'react'; +import { memoize } from 'lodash/fp'; import { isRequiredInput, FileCommandInputParameter, File, CWLType -} from '~/models/workflow'; +} from 'models/workflow'; import { Field } from 'redux-form'; -import { ERROR_MESSAGE } from '~/validators/require'; -import { Input, Dialog, DialogTitle, DialogContent, DialogActions, Button } 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 { 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'; -import { getFileFullPath } from '~/services/collection-service/collection-service-files-response'; +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.basename : ''} - parse={(file: CollectionFile): File => ({ - class: CWLType.FILE, - location: `keep:${file.id}`, - basename: file.name, - })} - validate={[ - isRequiredInput(input) - ? (file?: File) => file ? undefined : ERROR_MESSAGE - : () => undefined, - ]} />; - + 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; @@ -48,7 +61,9 @@ interface FileInputComponentState { } const FileInputComponent = connect()( - class FileInputComponent extends React.Component { + class FileInputComponent extends React.Component { state: FileInputComponentState = { open: false, }; @@ -61,11 +76,12 @@ const FileInputComponent = connect()( render() { return <> {this.renderInput()} - {this.renderDialog()} + ; } openDialog = () => { + this.componentDidMount(); this.setState({ open: true }); } @@ -78,7 +94,7 @@ const FileInputComponent = connect()( this.props.input.onChange(this.state.file); } - setFile = (event: React.MouseEvent, { data }: TreeItem, pickerId: string) => { + setFile = (_: {}, { data }: TreeItem) => { if ('type' in data && data.type === CollectionFileType.FILE) { this.setState({ file: data }); } else { @@ -92,38 +108,53 @@ const FileInputComponent = connect()( } + onClick={!props.commandInput.disabled ? this.openDialog : undefined} + onKeyPress={!props.commandInput.disabled ? this.openDialog : undefined} />} {...this.props} />; } - renderDialog() { - return - Choose a file - - - - - - - - ; - } - + 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 + +
+ +
+
+ + + + +
+ ); }); - -