+ 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<GenericInputProps & DispatchProp & {
+ options?: { showOnlyOwned: boolean, showOnlyWritable: boolean };
+ }, FileInputComponentState> {
+ state: FileInputComponentState = {
+ open: false,
+ };
+
+ componentDidMount() {
+ this.props.dispatch<any>(
+ initProjectsTreePicker(this.props.commandInput.id));
+ }
+
+ render() {
+ return <>
+ {this.renderInput()}
+ <this.dialog />
+ </>;
+ }
+
+ 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<ProjectsTreePickerItem>) => {
+ if ('type' in data && data.type === CollectionFileType.FILE) {
+ this.setState({ file: data });
+ } else {
+ this.setState({ file: undefined });
+ }
+ }
+
+ renderInput() {
+ return <GenericInput
+ component={props =>
+ <Input
+ readOnly
+ fullWidth
+ disabled={props.commandInput.disabled}
+ value={props.input.value}
+ error={props.meta.touched && !!props.meta.error}
+ onClick={!props.commandInput.disabled ? this.openDialog : undefined}
+ onKeyPress={!props.commandInput.disabled ? this.openDialog : undefined} />}
+ {...this.props} />;
+ }
+
+ dialogContentStyles: StyleRulesCallback<DialogContentCssRules> = ({ spacing }) => ({
+ root: {
+ display: 'flex',
+ flexDirection: 'column',
+ },
+ pickerWrapper: {
+ flexBasis: `${spacing.unit * 8}vh`,
+ flexShrink: 1,
+ minHeight: 0,
+ },
+ });