Merge branch '17415-Mountainduck-Bookmark-files'
[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 import { getInlineFileUrl, sanitizeToken } from "./helpers";
11
12 const mapStateToProps = (state: RootState) => {
13     const { resource } = state.contextMenu;
14     const currentCollectionUuid = state.collectionPanel.item ? state.collectionPanel.item.uuid : '';
15     if (resource && (
16         resource.menuKind === ContextMenuKind.COLLECTION_FILES_ITEM ||
17         resource.menuKind === ContextMenuKind.READONLY_COLLECTION_FILES_ITEM)) {
18         const file = getNodeValue(resource.uuid)(state.collectionPanelFiles);
19         if (file) {
20             const fileUrl = sanitizeToken(getInlineFileUrl(
21                 file.url,
22                 state.auth.config.keepWebServiceUrl,
23                 state.auth.config.keepWebInlineServiceUrl), true);
24             return {
25                 href: fileUrl,
26                 kind: 'file',
27                 currentCollectionUuid
28             };
29         }
30     }
31     return {};
32 };
33
34 export const CollectionFileViewerAction = connect(mapStateToProps)(FileViewerAction);