1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from "react";
6 import { Typography } from "@mui/material";
7 import { TreeItem } from "components/tree/tree";
8 import { WrappedFieldProps } from 'redux-form';
9 import { ProjectsTreePicker } from 'views-components/projects-tree-picker/projects-tree-picker';
10 import { ProjectsTreePickerItem } from 'store/tree-picker/tree-picker-middleware';
11 import { PickerIdProp } from 'store/tree-picker/picker-id';
12 import { FileOperationLocation, getFileOperationLocation } from "store/tree-picker/tree-picker-actions";
13 import { connect } from "react-redux";
14 import { Dispatch } from "redux";
16 export const ProjectTreePickerField = (props: WrappedFieldProps & PickerIdProp) =>
17 <div style={{ display: 'flex', minHeight: 0, flexDirection: 'column' }}>
18 <div style={{ flexBasis: '960px', flexShrink: 1, minHeight: 0, display: 'flex', flexDirection: 'column' }}>
20 pickerId={props.pickerId}
21 toggleItemActive={handleChange(props)}
22 cascadeSelection={false}
23 options={{ showOnlyOwned: false, showOnlyWritable: true }} />
24 {props.meta.dirty && props.meta.error &&
25 <Typography variant='caption' color='error'>
31 const handleChange = (props: WrappedFieldProps) =>
32 (_: any, { id }: TreeItem<ProjectsTreePickerItem>) =>
33 props.input.onChange(id);
35 export const CollectionTreePickerField = (props: WrappedFieldProps & PickerIdProp) =>
36 <div style={{ display: 'flex', minHeight: 0, flexDirection: 'column' }}>
37 <div style={{ flexBasis: '275px', flexShrink: 1, minHeight: 0, display: 'flex', flexDirection: 'column' }}>
39 pickerId={props.pickerId}
40 toggleItemActive={handleChange(props)}
41 cascadeSelection={false}
42 options={{ showOnlyOwned: false, showOnlyWritable: true }}
44 {props.meta.dirty && props.meta.error &&
45 <Typography variant='caption' color='error'>
51 type ProjectsTreePickerActionProps = {
52 getFileOperationLocation: (item: ProjectsTreePickerItem) => Promise<FileOperationLocation | undefined>;
55 const projectsTreePickerMapDispatchToProps = (dispatch: Dispatch): ProjectsTreePickerActionProps => ({
56 getFileOperationLocation: (item: ProjectsTreePickerItem) => dispatch<any>(getFileOperationLocation(item)),
59 type ProjectsTreePickerCombinedProps = ProjectsTreePickerActionProps & WrappedFieldProps & PickerIdProp;
61 export const DirectoryTreePickerField = connect(null, projectsTreePickerMapDispatchToProps)(
62 class DirectoryTreePickerFieldComponent extends React.Component<ProjectsTreePickerCombinedProps> {
64 handleDirectoryChange = (props: WrappedFieldProps) =>
65 async (_: any, { data }: TreeItem<ProjectsTreePickerItem>) => {
66 const location = await this.props.getFileOperationLocation(data);
67 props.input.onChange(location || '');
71 return <div style={{ display: 'flex', minHeight: 0, flexDirection: 'column' }}>
72 <div style={{ flexBasis: '275px', flexShrink: 1, minHeight: 0, display: 'flex', flexDirection: 'column' }}>
74 currentUuids={[this.props.input.value.uuid]}
75 pickerId={this.props.pickerId}
76 toggleItemActive={this.handleDirectoryChange(this.props)}
77 cascadeSelection={false}
78 options={{ showOnlyOwned: false, showOnlyWritable: true }}
81 {this.props.meta.dirty && this.props.meta.error &&
82 <Typography variant='caption' color='error'>
83 {this.props.meta.error}