16812: Reverted changes in download action, fixed keep links
[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
12 const mapStateToProps = (state: RootState) => {
13     const { resource } = state.contextMenu;
14     const currentCollectionUuid = state.collectionPanel.item ? state.collectionPanel.item.uuid : '';
15     if (resource && resource.menuKind === ContextMenuKind.COLLECTION_FILES_ITEM) {
16         const file = getNodeValue(resource.uuid)(state.collectionPanelFiles);
17         if (file) {
18             return {
19                 href: file.url,
20                 kind: 'file',
21                 currentCollectionUuid
22             };
23         }
24     } else {
25         const files = filterCollectionFilesBySelection(state.collectionPanelFiles, true);
26         return {
27             href: files.map(file => file.url),
28             kind: 'files',
29             currentCollectionUuid
30         };
31     }
32     return {};
33 };
34
35 export const DownloadCollectionFileAction = connect(mapStateToProps)(DownloadAction);