21128: single-multi works again Arvados-DCO-1.1-Signed-off-by: Lisa Knox <lisa.knox...
[arvados.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, isInlineFileUrlSafe } 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         ContextMenuKind.COLLECTION_FILE_ITEM,
17         ContextMenuKind.READONLY_COLLECTION_FILE_ITEM,
18         ContextMenuKind.COLLECTION_DIRECTORY_ITEM,
19         ContextMenuKind.READONLY_COLLECTION_DIRECTORY_ITEM ].indexOf(resource.menuKind as ContextMenuKind) > -1) {
20         const file = getNodeValue(resource.uuid)(state.collectionPanelFiles);
21         const shouldShowInlineUrl = isInlineFileUrlSafe(
22                                 file ? file.url : "",
23                                 state.auth.config.keepWebServiceUrl,
24                                 state.auth.config.keepWebInlineServiceUrl
25                               ) || state.auth.config.clusterConfig.Collections.TrustAllContent;
26         if (file && shouldShowInlineUrl) {
27             const fileUrl = sanitizeToken(getInlineFileUrl(
28                 file.url,
29                 state.auth.config.keepWebServiceUrl,
30                 state.auth.config.keepWebInlineServiceUrl), true);
31             return {
32                 href: fileUrl,
33                 kind: 'file',
34                 currentCollectionUuid
35             };
36         }
37     }
38     return {};
39 };
40
41 export const CollectionFileViewerAction = connect(mapStateToProps)(FileViewerAction);