Merge branch '19690-roject-column-options' closes #19690 Arvados-DCO-1.1-Signed-off...
[arvados-workbench2.git] / src / views / process-panel / process-output-collection-files.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { connect } from "react-redux";
6 import {
7     CollectionPanelFiles as Component,
8     CollectionPanelFilesProps
9 } from "components/collection-panel-files/collection-panel-files";
10 import { Dispatch } from "redux";
11 import { collectionPanelFilesAction } from "store/collection-panel/collection-panel-files/collection-panel-files-actions";
12 import { ContextMenuKind } from "views-components/context-menu/context-menu";
13 import { openContextMenu, openCollectionFilesContextMenu } from 'store/context-menu/context-menu-actions';
14 import { openUploadCollectionFilesDialog } from 'store/collections/collection-upload-actions';
15 import { ResourceKind } from "models/resource";
16 import { openDetailsPanel } from 'store/details-panel/details-panel-action';
17
18 const mapDispatchToProps = (dispatch: Dispatch): Pick<CollectionPanelFilesProps, 'onSearchChange' | 'onFileClick' | 'onUploadDataClick' | 'onCollapseToggle' | 'onSelectionToggle' | 'onItemMenuOpen' | 'onOptionsMenuOpen'> => ({
19     onUploadDataClick: (targetLocation?: string) => {
20         dispatch<any>(openUploadCollectionFilesDialog(targetLocation));
21     },
22     onCollapseToggle: (id) => {
23         dispatch(collectionPanelFilesAction.TOGGLE_COLLECTION_FILE_COLLAPSE({ id }));
24     },
25     onSelectionToggle: (event, item) => {
26         dispatch(collectionPanelFilesAction.TOGGLE_COLLECTION_FILE_SELECTION({ id: item.id }));
27     },
28     onItemMenuOpen: (event, item, isWritable) => {
29         const isDirectory = item.data.type === 'directory';
30         dispatch<any>(openContextMenu(
31             event,
32             {
33                 menuKind: isWritable
34                     ? isDirectory
35                         ? ContextMenuKind.COLLECTION_DIRECTORY_ITEM
36                         : ContextMenuKind.COLLECTION_FILE_ITEM
37                     : isDirectory
38                         ? ContextMenuKind.READONLY_COLLECTION_DIRECTORY_ITEM
39                         : ContextMenuKind.READONLY_COLLECTION_FILE_ITEM,
40                 kind: ResourceKind.COLLECTION,
41                 name: item.data.name,
42                 uuid: item.id,
43                 ownerUuid: ''
44             }
45         ));
46     },
47     onSearchChange: (searchValue: string) => {
48         dispatch(collectionPanelFilesAction.ON_SEARCH_CHANGE(searchValue));
49     },
50     onOptionsMenuOpen: (event, isWritable) => {
51         dispatch<any>(openCollectionFilesContextMenu(event, isWritable));
52     },
53     onFileClick: (id) => {
54         dispatch<any>(openDetailsPanel(id));
55     },
56 });
57
58 export const ProcessOutputCollectionFiles = connect(null, mapDispatchToProps)(Component);