import { sortFilesTree } from "services/collection-service/collection-service-files-response";
import { GroupClass, GroupResource } from "models/group";
import { CollectionResource } from "models/collection";
+import { getResource } from "store/resources/resources";
+import { updateResources } from "store/resources/resources-actions";
export const treePickerActions = unionize({
LOAD_TREE_PICKER_NODE: ofType<{ id: string, pickerId: string }>(),
const itemLimit = 200;
const { items, itemsAvailable } = await services.groupsService.contents((loadShared || searchProjects) ? '' : id, { filters, excludeHomeProject: loadShared || undefined, limit: itemLimit });
+ dispatch<any>(updateResources(items));
if (itemsAvailable > itemLimit) {
items.push({
pickerId: pickerTreeId,
subtree: tree
}));
- dispatch(treePickerActions.EXPAND_TREE_PICKER_NODES({ ids: [pickerTreeRootUuid], pickerId: pickerTreeId }));
dispatch(treePickerActions.ACTIVATE_TREE_PICKER_NODE({ id: initialValue, pickerId: pickerTreeId }));
dispatch(treePickerSearchActions.REFRESH_TREE_PICKER({ pickerId: pickerTreeId }));
}
id: 'Favorites',
pickerId,
data: items.filter((item) => {
- if (options.showOnlyWritable && (item as GroupResource).writableBy && (item as GroupResource).writableBy.indexOf(uuid) === -1) {
+ if (options.showOnlyWritable && !(item as GroupResource).canWrite) {
return false;
}
* if the item represents a valid target/destination location
*/
export type FileOperationLocation = {
+ name: string;
uuid: string;
- path: string;
+ pdh?: string;
+ subpath: 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) {
+export const getFileOperationLocation = (item: ProjectsTreePickerItem) =>
+ async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository): Promise<FileOperationLocation | undefined> => {
+ if ('kind' in item && item.kind === ResourceKind.COLLECTION) {
return {
- uuid,
- path: [item.path, item.name].join('/')
+ name: item.name,
+ uuid: item.uuid,
+ pdh: item.portableDataHash,
+ subpath: '/',
};
- } else {
- return undefined;
+ } else if ('type' in item && item.type === CollectionFileType.DIRECTORY) {
+ const uuid = getCollectionResourceCollectionUuid(item.id);
+ if (uuid) {
+ const collection = getResource<CollectionResource>(uuid)(getState().resources);
+ if (collection) {
+ const itemPath = [item.path, item.name].join('/');
+
+ return {
+ name: item.name,
+ uuid,
+ pdh: collection.portableDataHash,
+ subpath: itemPath,
+ };
+ }
+ }
}
- } else {
return undefined;
- }
-};
+ };
/**
* Create an expanded tree picker subtree from array of nested projects/collection
value: item,
active: false,
selected: false,
- expanded: item.uuid !== tailUuid,
+ expanded: false,
status: item.uuid !== tailUuid ? TreeNodeStatus.LOADED : TreeNodeStatus.INITIAL,
})(tree), createTree<GroupResource | CollectionResource>());
};