// Copyright (C) The Arvados Authors. All rights reserved.
//
// SPDX-License-Identifier: AGPL-3.0
import React from "react";
import { Typography } from "@mui/material";
import { TreeItem } from "components/tree/tree";
import { WrappedFieldProps } from 'redux-form';
import { ProjectsTreePicker } from 'views-components/projects-tree-picker/projects-tree-picker';
import { ProjectsTreePickerItem } from 'store/tree-picker/tree-picker-middleware';
import { PickerIdProp } from 'store/tree-picker/picker-id';
import { FileOperationLocation, getFileOperationLocation, SEARCH_PROJECT_ID_PREFIX } from "store/tree-picker/tree-picker-actions";
import { connect } from "react-redux";
import { Dispatch } from "redux";
export const ProjectTreePickerField = (props: WrappedFieldProps & PickerIdProp) =>
{props.meta.dirty && props.meta.error &&
{props.meta.error}
}
;
const handleChange = (props: WrappedFieldProps) =>
(_: any, { id }: TreeItem) => {
if (id.startsWith(SEARCH_PROJECT_ID_PREFIX)) {
props.input.onChange(id.slice(SEARCH_PROJECT_ID_PREFIX.length));
} else {
props.input.onChange(id);
}
}
export const CollectionTreePickerField = (props: WrappedFieldProps & PickerIdProp) =>
{props.meta.dirty && props.meta.error &&
{props.meta.error}
}
;
type ProjectsTreePickerActionProps = {
getFileOperationLocation: (item: ProjectsTreePickerItem) => Promise;
}
const projectsTreePickerMapDispatchToProps = (dispatch: Dispatch): ProjectsTreePickerActionProps => ({
getFileOperationLocation: (item: ProjectsTreePickerItem) => dispatch(getFileOperationLocation(item)),
});
type ProjectsTreePickerCombinedProps = ProjectsTreePickerActionProps & WrappedFieldProps & PickerIdProp;
export const DirectoryTreePickerField = connect(null, projectsTreePickerMapDispatchToProps)(
class DirectoryTreePickerFieldComponent extends React.Component {
handleDirectoryChange = (props: WrappedFieldProps) =>
async (_: any, { data }: TreeItem) => {
const location = await this.props.getFileOperationLocation(data);
props.input.onChange(location || '');
}
render() {
return
{this.props.meta.dirty && this.props.meta.error &&
{this.props.meta.error}
}
;
}
});