import { snackbarActions, SnackbarKind } from 'store/snackbar/snackbar-actions';
import { getCommonResourceServiceError, CommonResourceServiceError } from 'services/common-service/common-resource-service';
import { progressIndicatorActions } from "store/progress-indicator/progress-indicator-actions";
+import { FileOperationLocation } from "store/tree-picker/tree-picker-actions";
import { updateResources } from 'store/resources/resources-actions';
import { navigateTo } from 'store/navigation/navigation-action';
}
export interface CollectionPartialCopyToExistingCollectionFormData {
- destination: {uuid: string, path?: string};
+ destination: FileOperationLocation;
}
export interface CollectionPartialCopyToSeparateCollectionsFormData {
// Get current collection
const sourceCollection = state.collectionPanel.item;
- if (sourceCollection && destination.uuid) {
+ if (sourceCollection && destination && destination.uuid) {
try {
dispatch(startSubmit(COLLECTION_PARTIAL_COPY_TO_SELECTED_COLLECTION));
dispatch(progressIndicatorActions.START_WORKING(COLLECTION_PARTIAL_COPY_TO_SELECTED_COLLECTION));
// SPDX-License-Identifier: AGPL-3.0
import { Dispatch } from "redux";
-import { FormErrors, initialize, startSubmit, stopSubmit } from "redux-form";
+import { initialize, startSubmit } from "redux-form";
import { CommonResourceServiceError, getCommonResourceServiceError } from "services/common-service/common-resource-service";
import { ServiceRepository } from "services/services";
import { filterCollectionFilesBySelection } from "store/collection-panel/collection-panel-files/collection-panel-files-state";
import { updateResources } from "store/resources/resources-actions";
import { SnackbarKind, snackbarActions } from "store/snackbar/snackbar-actions";
import { RootState } from "store/store";
+import { FileOperationLocation } from "store/tree-picker/tree-picker-actions";
export const COLLECTION_PARTIAL_MOVE_TO_NEW_COLLECTION = 'COLLECTION_PARTIAL_MOVE_TO_NEW_DIALOG';
export const COLLECTION_PARTIAL_MOVE_TO_SELECTED_COLLECTION = 'COLLECTION_PARTIAL_MOVE_TO_SELECTED_DIALOG';
}
export interface CollectionPartialMoveToExistingCollectionFormData {
- destination: {uuid: string, path?: string};
+ destination: FileOperationLocation;
}
export interface CollectionPartialMoveToSeparateCollectionsFormData {
import { unionize, ofType, UnionOf } from "common/unionize";
import { TreeNode, initTreeNode, getNodeDescendants, TreeNodeStatus, getNode, TreePickerId, Tree } from 'models/tree';
-import { CollectionFileType, createCollectionFilesTree } from "models/collection-file";
+import { CollectionFileType, createCollectionFilesTree, getCollectionResourceCollectionUuid } from "models/collection-file";
import { Dispatch } from 'redux';
import { RootState } from 'store/store';
import { getUserUuid } from "common/getuser";
.getOrder()
};
};
+
+/**
+ * Given a tree picker item, return collection uuid and path
+ * if the item represents a valid target/destination location
+ */
+export type FileOperationLocation = {
+ uuid: string;
+ path: string;
+}
+export const getFileOperationLocation = (item: ProjectsTreePickerItem): FileOperationLocation | undefined => {
+ if ('kind' in item && item.kind === ResourceKind.COLLECTION) {
+ return {
+ uuid: item.uuid,
+ path: '/'
+ };
+ } else if ('type' in item && item.type === CollectionFileType.DIRECTORY) {
+ const uuid = getCollectionResourceCollectionUuid(item.id);
+ if (uuid) {
+ return {
+ uuid,
+ path: [item.path, item.name].join('/')
+ };
+ } else {
+ return undefined;
+ }
+ } else {
+ return undefined;
+ }
+};
component={CollectionTreePickerField}
validate={COLLECTION_PROJECT_VALIDATION} />;
-const validateDirectory = (val) => (val ? undefined : ERROR_MESSAGE);
+const validateDirectory = (val) => (val && val.uuid ? undefined : ERROR_MESSAGE);
export const DirectoryPickerField = (props: PickerIdProp) =>
<Field
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 { CollectionFileType, getCollectionResourceCollectionUuid } from "models/collection-file";
-import { ResourceKind } from "models/resource";
+import { getFileOperationLocation } from "store/tree-picker/tree-picker-actions";
export const ProjectTreePickerField = (props: WrappedFieldProps & PickerIdProp) =>
<div style={{ display: 'flex', minHeight: 0, flexDirection: 'column' }}>
</div>;
const handleDirectoryChange = (props: WrappedFieldProps) =>
- (_: any, data: TreeItem<ProjectsTreePickerItem>) => {
- if ('kind' in data.data && data.data.kind === ResourceKind.COLLECTION) {
- props.input.onChange({
- uuid: data.data.uuid,
- path: '/'
- });
- } else if ('type' in data.data && data.data.type === CollectionFileType.DIRECTORY) {
- props.input.onChange({
- uuid: getCollectionResourceCollectionUuid(data.data.id),
- path: [data.data.path, data.data.name].join('/')
- });
- } else {
- props.input.onChange('');
- }
+ (_: any, { data }: TreeItem<ProjectsTreePickerItem>) => {
+ props.input.onChange(getFileOperationLocation(data) || '');
}
export const DirectoryTreePickerField = (props: WrappedFieldProps & PickerIdProp) =>