1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
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";
12 const mapStateToProps = (state: RootState) => {
13 const { resource } = state.contextMenu;
14 const currentCollectionUuid = state.collectionPanel.item ? state.collectionPanel.item.uuid : '';
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(
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(
29 state.auth.config.keepWebServiceUrl,
30 state.auth.config.keepWebInlineServiceUrl), true);
41 export const CollectionFileViewerAction = connect(mapStateToProps)(FileViewerAction);