1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
8 FileCommandInputParameter,
11 } from '~/models/workflow';
12 import { Field } from 'redux-form';
13 import { ERROR_MESSAGE } from '~/validators/require';
14 import { Input, Dialog, DialogTitle, DialogContent, DialogActions, Button } from '@material-ui/core';
15 import { GenericInputProps, GenericInput } from './generic-input';
16 import { ProjectsTreePicker } from '~/views-components/projects-tree-picker/projects-tree-picker';
17 import { connect, DispatchProp } from 'react-redux';
18 import { initProjectsTreePicker } from '~/store/tree-picker/tree-picker-actions';
19 import { TreeItem } from '~/components/tree/tree';
20 import { ProjectsTreePickerItem } from '~/views-components/projects-tree-picker/generic-projects-tree-picker';
21 import { CollectionFile, CollectionFileType } from '~/models/collection-file';
22 import { getFileFullPath } from '~/services/collection-service/collection-service-files-response';
24 export interface FileInputProps {
25 input: FileCommandInputParameter;
27 export const FileInput = ({ input }: FileInputProps) =>
31 component={FileInputComponent}
32 format={(value?: File) => value ? value.basename : ''}
33 parse={(file: CollectionFile): File => ({
35 location: `keep:${file.id}`,
39 isRequiredInput(input)
40 ? (file?: File) => file ? undefined : ERROR_MESSAGE
45 interface FileInputComponentState {
47 file?: CollectionFile;
50 const FileInputComponent = connect()(
51 class FileInputComponent extends React.Component<GenericInputProps & DispatchProp, FileInputComponentState> {
52 state: FileInputComponentState = {
57 this.props.dispatch<any>(
58 initProjectsTreePicker(this.props.commandInput.id));
69 this.setState({ open: true });
73 this.setState({ open: false });
78 this.props.input.onChange(this.state.file);
81 setFile = (event: React.MouseEvent<HTMLElement>, { data }: TreeItem<ProjectsTreePickerItem>, pickerId: string) => {
82 if ('type' in data && data.type === CollectionFileType.FILE) {
83 this.setState({ file: data });
85 this.setState({ file: undefined });
95 value={props.input.value}
96 error={props.meta.touched && !!props.meta.error}
97 onClick={this.openDialog}
98 onKeyPress={this.openDialog} />}
104 open={this.state.open}
105 onClose={this.closeDialog}
108 <DialogTitle>Choose a file</DialogTitle>
111 pickerId={this.props.commandInput.id}
114 toggleItemActive={this.setFile} />
117 <Button onClick={this.closeDialog}>Cancel</Button>
119 disabled={!this.state.file}
122 onClick={this.submit}>Ok</Button>