Merge branch 'main' from workbench2.git
[arvados.git] / services / workbench2 / src / views-components / collection-panel-files / collection-panel-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 { 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';
18
19 const mapStateToProps = (state: RootState): Pick<CollectionPanelFilesProps, "currentItemUuid"> => ({
20     currentItemUuid: state.detailsPanel.resourceUuid
21 });
22
23 const mapDispatchToProps = (dispatch: Dispatch): Pick<CollectionPanelFilesProps, 'onSearchChange' | 'onFileClick' | 'onUploadDataClick' | 'onCollapseToggle' | 'onSelectionToggle' | 'onItemMenuOpen' | 'onOptionsMenuOpen'> => ({
24     onUploadDataClick: (targetLocation?: string) => {
25         dispatch<any>(openUploadCollectionFilesDialog(targetLocation));
26     },
27     onCollapseToggle: (id) => {
28         dispatch(collectionPanelFilesAction.TOGGLE_COLLECTION_FILE_COLLAPSE({ id }));
29     },
30     onSelectionToggle: (event, item) => {
31         dispatch(collectionPanelFilesAction.TOGGLE_COLLECTION_FILE_SELECTION({ id: item.id }));
32     },
33     onItemMenuOpen: (event, item, isWritable) => {
34         const isDirectory = item.data.type === 'directory';
35         dispatch<any>(openContextMenu(
36             event,
37             {
38                 menuKind: isWritable
39                     ? isDirectory
40                         ? ContextMenuKind.COLLECTION_DIRECTORY_ITEM
41                         : ContextMenuKind.COLLECTION_FILE_ITEM
42                     : isDirectory
43                         ? ContextMenuKind.READONLY_COLLECTION_DIRECTORY_ITEM
44                         : ContextMenuKind.READONLY_COLLECTION_FILE_ITEM,
45                 kind: ResourceKind.COLLECTION,
46                 name: item.data.name,
47                 uuid: item.id,
48                 ownerUuid: ''
49             }
50         ));
51     },
52     onSearchChange: (searchValue: string) => {
53         dispatch(collectionPanelFilesAction.ON_SEARCH_CHANGE(searchValue));
54     },
55     onOptionsMenuOpen: (event, isWritable) => {
56         dispatch<any>(openCollectionFilesContextMenu(event, isWritable));
57     },
58     onFileClick: (id) => {
59         dispatch<any>(openDetailsPanel(id));
60     },
61 });
62
63 export const CollectionPanelFiles = connect(mapStateToProps, mapDispatchToProps)(Component);