Merge branch '16812-token-appears-in-the-download-URL'
[arvados-workbench2.git] / src / views-components / context-menu / actions / file-viewer-action.tsx
index 20dcece400a2955aeaeeb42ebe55280464aa8bac..a631424e67bde5f46dbca5e370c3e6bdaa70eb29 100644 (file)
@@ -3,27 +3,40 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from "react";
+import { connect } from 'react-redux';
 import { ListItemIcon, ListItemText, ListItem } from "@material-ui/core";
 import { OpenIcon } from "~/components/icon/icon";
+import { sanitizeToken } from "./helpers";
+import { RootState } from "~/store/store";
 
-export const FileViewerAction = (props: { href?: any, download?: any, onClick?: () => void, kind?: string, currentCollectionUuid?: string; }) => {
-    const fileProps = props.download ? { download: props.download } : {};
+export const FileViewerAction = (props: any) => {
+    const {
+        keepWebServiceUrl,
+        keepWebInlineServiceUrl,
+    } = props;
 
     return props.href
         ? <a
             style={{ textDecoration: 'none' }}
-            href={props.href}
+            href={sanitizeToken(props.href.replace(keepWebServiceUrl, keepWebInlineServiceUrl), true)}
             target="_blank"
-            onClick={props.onClick}
-            {...fileProps}>
+            onClick={props.onClick}>
             <ListItem button>
-                    <ListItemIcon>
-                        <OpenIcon />
-                    </ListItemIcon>
+                <ListItemIcon>
+                    <OpenIcon />
+                </ListItemIcon>
                 <ListItemText>
                     Open in new tab
-                </ListItemText>
+                    </ListItemText>
             </ListItem>
         </a>
         : null;
-};
\ No newline at end of file
+};
+
+const mapStateToProps = ({ auth }: RootState): any => ({
+    keepWebServiceUrl: auth.config.keepWebServiceUrl,
+    keepWebInlineServiceUrl: auth.config.keepWebInlineServiceUrl,
+});
+
+
+export default connect(mapStateToProps, null)(FileViewerAction);