Merge branch '16719-collection-version-basic-ui'
[arvados-workbench2.git] / src / views-components / context-menu / actions / download-collection-file-action.tsx
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 { RootState } from "../../../store/store";
7 import { DownloadAction } from "./download-action";
8 import { getNodeValue } from "../../../models/tree";
9 import { ContextMenuKind } from '../context-menu';
10 import { filterCollectionFilesBySelection } from "~/store/collection-panel/collection-panel-files/collection-panel-files-state";
11 import { sanitizeToken } from "./helpers";
12
13 const mapStateToProps = (state: RootState) => {
14     const { resource } = state.contextMenu;
15     const currentCollectionUuid = state.collectionPanel.item ? state.collectionPanel.item.uuid : '';
16     if (resource && resource.menuKind === ContextMenuKind.COLLECTION_FILES_ITEM) {
17         const file = getNodeValue(resource.uuid)(state.collectionPanelFiles);
18         if (file) {
19             return {
20                 href: sanitizeToken(file.url, true),
21                 kind: 'file',
22                 currentCollectionUuid
23             };
24         }
25     } else {
26         const files = filterCollectionFilesBySelection(state.collectionPanelFiles, true);
27         return {
28             href: files.map(file => file.url),
29             kind: 'files',
30             currentCollectionUuid
31         };
32     }
33     return {};
34 };
35
36 export const DownloadCollectionFileAction = connect(mapStateToProps)(DownloadAction);