16812: Reverted changes in download action, fixed keep links
[arvados-workbench2.git] / src / views-components / context-menu / actions / file-viewer-action.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from "react";
6 import { connect } from 'react-redux';
7 import { ListItemIcon, ListItemText, ListItem } from "@material-ui/core";
8 import { OpenIcon } from "~/components/icon/icon";
9 import { sanitizeToken } from "./helpers";
10 import { RootState } from "~/store/store";
11
12 export const FileViewerAction = (props: any) => {
13     const {
14         keepWebServiceUrl,
15         keepWebInlineServiceUrl,
16     } = props;
17
18     return props.href
19         ? <a
20             style={{ textDecoration: 'none' }}
21             href={sanitizeToken(props.href.replace(keepWebServiceUrl, keepWebInlineServiceUrl), true)}
22             target="_blank"
23             onClick={props.onClick}>
24             <ListItem button>
25                 <ListItemIcon>
26                     <OpenIcon />
27                 </ListItemIcon>
28                 <ListItemText>
29                     Open in new tab
30                     </ListItemText>
31             </ListItem>
32         </a>
33         : null;
34 };
35
36 const mapStateToProps = ({ auth }: RootState): any => ({
37     keepWebServiceUrl: auth.config.keepWebServiceUrl,
38     keepWebInlineServiceUrl: auth.config.keepWebInlineServiceUrl,
39 });
40
41
42 export default connect(mapStateToProps, null)(FileViewerAction);