Merge branch '17018-readonly-file-actions-fix'
[arvados-workbench2.git] / src / views-components / context-menu / actions / copy-to-clipboard-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 * as copy from 'copy-to-clipboard';
7 import { ListItemIcon, ListItemText, ListItem } from "@material-ui/core";
8 import { Link } from "~/components/icon/icon";
9 import { getClipboardUrl } from "./helpers";
10
11 export const CopyToClipboardAction = (props: { href?: any, download?: any, onClick?: () => void, kind?: string, currentCollectionUuid?: string; }) => {
12     const copyToClipboard = () => {
13         if (props.href) {
14             const clipboardUrl = getClipboardUrl(props.href);
15             copy(clipboardUrl);
16         }
17
18         if (props.onClick) {
19             props.onClick();
20         }
21     };
22
23     return props.href
24         ? <ListItem button onClick={copyToClipboard}>
25             <ListItemIcon>
26                 <Link />
27             </ListItemIcon>
28             <ListItemText>
29                 Copy to clipboard
30             </ListItemText>
31         </ListItem>
32         : null;
33 };