// SPDX-License-Identifier: AGPL-3.0
import * as React from 'react';
+import { memoize } from 'lodash/fp';
import {
isRequiredInput,
FileCommandInputParameter,
export interface FileInputProps {
input: FileCommandInputParameter;
+ options?: { showOnlyOwned: boolean, showOnlyWritable: boolean };
}
-export const FileInput = ({ input }: FileInputProps) =>
+export const FileInput = ({ input, options }: FileInputProps) =>
<Field
name={input.id}
commandInput={input}
component={FileInputComponent}
- format={(value?: File) => 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,
- ]} />;
-
+ 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;
}
const FileInputComponent = connect()(
- class FileInputComponent extends React.Component<GenericInputProps & DispatchProp, FileInputComponentState> {
+ class FileInputComponent extends React.Component<GenericInputProps & DispatchProp & {
+ options?: { showOnlyOwned: boolean, showOnlyWritable: boolean };
+ }, FileInputComponentState> {
state: FileInputComponentState = {
open: false,
};
this.props.input.onChange(this.state.file);
}
- setFile = (event: React.MouseEvent<HTMLElement>, { data }: TreeItem<ProjectsTreePickerItem>, pickerId: string) => {
+ setFile = (_: {}, { data }: TreeItem<ProjectsTreePickerItem>) => {
if ('type' in data && data.type === CollectionFileType.FILE) {
this.setState({ file: data });
} else {
<Input
readOnly
fullWidth
+ disabled={props.commandInput.disabled}
value={props.input.value}
error={props.meta.touched && !!props.meta.error}
- onClick={this.openDialog}
- onKeyPress={this.openDialog} />}
+ onClick={!props.commandInput.disabled ? this.openDialog : undefined}
+ onKeyPress={!props.commandInput.disabled ? this.openDialog : undefined} />}
{...this.props} />;
}
open={this.state.open}
onClose={this.closeDialog}
fullWidth
+ data-cy="choose-a-file-dialog"
maxWidth='md'>
<DialogTitle>Choose a file</DialogTitle>
<DialogContent>
pickerId={this.props.commandInput.id}
includeCollections
includeFiles
+ options={this.props.options}
toggleItemActive={this.setFile} />
</DialogContent>
<DialogActions>