import {
CollectionPanelFiles as Component,
CollectionPanelFilesProps
-} from "~/components/collection-panel-files/collection-panel-files";
-import { RootState } from "~/store/store";
-import { TreeItem, TreeItemStatus } from "~/components/tree/tree";
-import {
- CollectionPanelDirectory,
- CollectionPanelFile,
- CollectionPanelFilesState
-} from "~/store/collection-panel/collection-panel-files/collection-panel-files-state";
-import { FileTreeData } from "~/components/file-tree/file-tree-data";
+} from "components/collection-panel-files/collection-panel-files";
+import { RootState } from "store/store";
import { Dispatch } from "redux";
-import { collectionPanelFilesAction } from "~/store/collection-panel/collection-panel-files/collection-panel-files-actions";
+import { collectionPanelFilesAction } from "store/collection-panel/collection-panel-files/collection-panel-files-actions";
import { ContextMenuKind } from "../context-menu/context-menu";
-import { getNode, getNodeChildrenIds, Tree } from "~/models/tree";
-import { CollectionFileType } from "~/models/collection-file";
-import { openContextMenu, openCollectionFilesContextMenu } from '~/store/context-menu/context-menu-actions';
-import { openUploadCollectionFilesDialog } from '~/store/collections/collection-upload-actions';
-import { ResourceKind } from "~/models/resource";
-
-const memoizedMapStateToProps = () => {
- let prevState: CollectionPanelFilesState;
- let prevTree: Array<TreeItem<FileTreeData>>;
+import { openContextMenu, openCollectionFilesContextMenu } from 'store/context-menu/context-menu-actions';
+import { openUploadCollectionFilesDialog } from 'store/collections/collection-upload-actions';
+import { ResourceKind } from "models/resource";
+import { openDetailsPanel } from 'store/details-panel/details-panel-action';
- return (state: RootState): Pick<CollectionPanelFilesProps, "items"> => {
- if (prevState !== state.collectionPanelFiles) {
- prevState = state.collectionPanelFiles;
- prevTree = getNodeChildrenIds('')(state.collectionPanelFiles)
- .map(collectionItemToTreeItem(state.collectionPanelFiles));
- }
- return {
- items: prevTree
- };
- };
-};
+const mapStateToProps = (state: RootState): Pick<CollectionPanelFilesProps, "currentItemUuid"> => ({
+ currentItemUuid: state.detailsPanel.resourceUuid
+});
-const mapDispatchToProps = (dispatch: Dispatch): Pick<CollectionPanelFilesProps, 'onUploadDataClick' | 'onCollapseToggle' | 'onSelectionToggle' | 'onItemMenuOpen' | 'onOptionsMenuOpen'> => ({
- onUploadDataClick: () => {
- dispatch<any>(openUploadCollectionFilesDialog());
+const mapDispatchToProps = (dispatch: Dispatch): Pick<CollectionPanelFilesProps, 'onSearchChange' | 'onFileClick' | 'onUploadDataClick' | 'onCollapseToggle' | 'onSelectionToggle' | 'onItemMenuOpen' | 'onOptionsMenuOpen'> => ({
+ onUploadDataClick: (targetLocation?: string) => {
+ dispatch<any>(openUploadCollectionFilesDialog(targetLocation));
},
onCollapseToggle: (id) => {
dispatch(collectionPanelFilesAction.TOGGLE_COLLECTION_FILE_COLLAPSE({ id }));
onSelectionToggle: (event, item) => {
dispatch(collectionPanelFilesAction.TOGGLE_COLLECTION_FILE_SELECTION({ id: item.id }));
},
- onItemMenuOpen: (event, item) => {
- dispatch<any>(openContextMenu(event, { menuKind: ContextMenuKind.COLLECTION_FILES_ITEM, kind: ResourceKind.COLLECTION, name: item.data.name, uuid: item.id, ownerUuid: '' }));
+ onItemMenuOpen: (event, item, isWritable) => {
+ const isDirectory = item.data.type === 'directory';
+ dispatch<any>(openContextMenu(
+ event,
+ {
+ menuKind: isWritable
+ ? isDirectory
+ ? ContextMenuKind.COLLECTION_DIRECTORY_ITEM
+ : ContextMenuKind.COLLECTION_FILE_ITEM
+ : isDirectory
+ ? ContextMenuKind.READONLY_COLLECTION_DIRECTORY_ITEM
+ : ContextMenuKind.READONLY_COLLECTION_FILE_ITEM,
+ kind: ResourceKind.COLLECTION,
+ name: item.data.name,
+ uuid: item.id,
+ ownerUuid: ''
+ }
+ ));
+ },
+ onSearchChange: (searchValue: string) => {
+ dispatch(collectionPanelFilesAction.ON_SEARCH_CHANGE(searchValue));
},
- onOptionsMenuOpen: (event) => {
- dispatch<any>(openCollectionFilesContextMenu(event));
+ onOptionsMenuOpen: (event, isWritable) => {
+ dispatch<any>(openCollectionFilesContextMenu(event, isWritable));
+ },
+ onFileClick: (id) => {
+ dispatch<any>(openDetailsPanel(id));
},
});
-
-export const CollectionPanelFiles = connect(memoizedMapStateToProps(), mapDispatchToProps)(Component);
-
-const collectionItemToTreeItem = (tree: Tree<CollectionPanelDirectory | CollectionPanelFile>) =>
- (id: string): TreeItem<FileTreeData> => {
- const node = getNode(id)(tree) || {
- id: '',
- children: [],
- parent: '',
- value: {
- name: 'Invalid node',
- type: CollectionFileType.DIRECTORY,
- selected: false,
- collapsed: true
- }
- };
- return {
- active: false,
- data: {
- name: node.value.name,
- size: node.value.type === CollectionFileType.FILE ? node.value.size : undefined,
- type: node.value.type
- },
- id: node.id,
- items: getNodeChildrenIds(node.id)(tree)
- .map(collectionItemToTreeItem(tree)),
- open: node.value.type === CollectionFileType.DIRECTORY ? !node.value.collapsed : false,
- selected: node.value.selected,
- status: TreeItemStatus.LOADED
- };
- };
+export const CollectionPanelFiles = connect(mapStateToProps, mapDispatchToProps)(Component);