basic-view-recent-queries
[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 { CollectionFileType } from "../../../models/collection-file";
10
11 const mapStateToProps = (state: RootState) => {
12     const { resource } = state.contextMenu;
13     if (resource) {
14         const file = getNodeValue(resource.uuid)(state.collectionPanelFiles);
15         if (file) {
16             return {
17                 href: file.url,
18                 download: file.type === CollectionFileType.DIRECTORY ? undefined : file.name
19             };
20         }
21     }
22     return {};
23 };
24
25 export const DownloadCollectionFileAction = connect(mapStateToProps)(DownloadAction);