f75da23869666e248fe1f04d91cd0e500f0e1a21
[arvados-workbench2.git] / src / views-components / context-menu / actions / collection-file-viewer-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 { FileViewerAction } from '~/views-components/context-menu/actions/file-viewer-action';
8 import { getNodeValue } from "~/models/tree";
9 import { ContextMenuKind } from '~/views-components/context-menu/context-menu';
10
11 const mapStateToProps = (state: RootState) => {
12     const { resource } = state.contextMenu;
13     const currentCollectionUuid = state.collectionPanel.item ? state.collectionPanel.item.uuid : '';
14     if (resource && resource.menuKind === ContextMenuKind.COLLECTION_FILES_ITEM) {
15         const file = getNodeValue(resource.uuid)(state.collectionPanelFiles);
16         if (file) {
17             return {
18                 href: file.url.replace(state.auth.config.keepWebServiceUrl, state.auth.config.keepWebInlineServiceUrl),
19                 kind: 'file',
20                 currentCollectionUuid
21             };
22         }
23     } else {
24         return;
25     }
26     return;
27 };
28
29 export const CollectionFileViewerAction = connect(mapStateToProps)(FileViewerAction);