1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
8 DirectoryCommandInputParameter,
11 } from '~/models/workflow';
12 import { Field } from 'redux-form';
13 import { Input, Dialog, DialogTitle, DialogContent, DialogActions, Button } from '@material-ui/core';
14 import { GenericInputProps, GenericInput } from './generic-input';
15 import { ProjectsTreePicker } from '~/views-components/projects-tree-picker/projects-tree-picker';
16 import { connect, DispatchProp } from 'react-redux';
17 import { initProjectsTreePicker } from '~/store/tree-picker/tree-picker-actions';
18 import { TreeItem } from '~/components/tree/tree';
19 import { ProjectsTreePickerItem } from '~/views-components/projects-tree-picker/generic-projects-tree-picker';
20 import { CollectionResource } from '~/models/collection';
21 import { ResourceKind } from '~/models/resource';
22 import { ERROR_MESSAGE } from '../../../validators/require';
24 export interface DirectoryInputProps {
25 input: DirectoryCommandInputParameter;
27 export const DirectoryInput = ({ input }: DirectoryInputProps) =>
31 component={DirectoryInputComponent}
32 format={(value?: Directory) => value ? value.basename : ''}
33 parse={(directory: CollectionResource): Directory => ({
34 class: CWLType.DIRECTORY,
35 location: `keep:${directory.portableDataHash}`,
36 basename: directory.name,
39 isRequiredInput(input)
40 ? (directory?: Directory) => directory ? undefined : ERROR_MESSAGE
45 interface DirectoryInputComponentState {
47 directory?: CollectionResource;
50 const DirectoryInputComponent = connect()(
51 class FileInputComponent extends React.Component<GenericInputProps & DispatchProp, DirectoryInputComponentState> {
52 state: DirectoryInputComponentState = {
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.directory);
81 setDirectory = (event: React.MouseEvent<HTMLElement>, { data }: TreeItem<ProjectsTreePickerItem>, pickerId: string) => {
82 if ('kind' in data && data.kind === ResourceKind.COLLECTION) {
83 this.setState({ directory: data });
85 this.setState({ directory: 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 directory</DialogTitle>
111 pickerId={this.props.commandInput.id}
113 toggleItemActive={this.setDirectory} />
116 <Button onClick={this.closeDialog}>Cancel</Button>
118 disabled={!this.state.directory}
121 onClick={this.submit}>Ok</Button>