1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { connect } from "react-redux";
7 CollectionPanelFiles as Component,
8 CollectionPanelFilesProps
9 } from "components/collection-panel-files/collection-panel-files";
10 import { RootState } from "store/store";
11 import { Dispatch } from "redux";
12 import { collectionPanelFilesAction } from "store/collection-panel/collection-panel-files/collection-panel-files-actions";
13 import { ContextMenuKind } from "../context-menu/context-menu";
14 import { openContextMenu, openCollectionFilesContextMenu } from 'store/context-menu/context-menu-actions';
15 import { openUploadCollectionFilesDialog } from 'store/collections/collection-upload-actions';
16 import { ResourceKind } from "models/resource";
17 import { openDetailsPanel } from 'store/details-panel/details-panel-action';
19 const mapStateToProps = (state: RootState): Pick<CollectionPanelFilesProps, "currentItemUuid"> => ({
20 currentItemUuid: state.detailsPanel.resourceUuid
23 const mapDispatchToProps = (dispatch: Dispatch): Pick<CollectionPanelFilesProps, 'onSearchChange' | 'onFileClick' | 'onUploadDataClick' | 'onCollapseToggle' | 'onSelectionToggle' | 'onItemMenuOpen' | 'onOptionsMenuOpen'> => ({
24 onUploadDataClick: (targetLocation?: string) => {
25 dispatch<any>(openUploadCollectionFilesDialog(targetLocation));
27 onCollapseToggle: (id) => {
28 dispatch(collectionPanelFilesAction.TOGGLE_COLLECTION_FILE_COLLAPSE({ id }));
30 onSelectionToggle: (event, item) => {
31 dispatch(collectionPanelFilesAction.TOGGLE_COLLECTION_FILE_SELECTION({ id: item.id }));
33 onItemMenuOpen: (event, item, isWritable) => {
34 const isDirectory = item.data.type === 'directory';
35 dispatch<any>(openContextMenu(
40 ? ContextMenuKind.COLLECTION_DIRECTORY_ITEM
41 : ContextMenuKind.COLLECTION_FILE_ITEM
43 ? ContextMenuKind.READONLY_COLLECTION_DIRECTORY_ITEM
44 : ContextMenuKind.READONLY_COLLECTION_FILE_ITEM,
45 kind: ResourceKind.COLLECTION,
52 onSearchChange: (searchValue: string) => {
53 dispatch(collectionPanelFilesAction.ON_SEARCH_CHANGE(searchValue));
55 onOptionsMenuOpen: (event, isWritable) => {
56 dispatch<any>(openCollectionFilesContextMenu(event, isWritable));
58 onFileClick: (id) => {
59 dispatch<any>(openDetailsPanel(id));
63 export const CollectionPanelFiles = connect(mapStateToProps, mapDispatchToProps)(Component);