21941: Tweak menu item names
[arvados.git] / services / workbench2 / src / views-components / context-menu / actions / collection-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 { connect } from "react-redux";
6 import { RootState } from "../../../store/store";
7 import { getNodeValue } from "models/tree";
8 import { ContextMenuKind } from 'views-components/context-menu/menu-item-sort';
9 import { CopyToClipboardAction } from "./copy-to-clipboard-action";
10 import { replaceCollectionId, getCollectionItemClipboardUrl, sanitizeToken } from "./helpers";
11
12 const mapStateToPropsUUID = (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         if (file) {
22             return {
23                 href: getCollectionItemClipboardUrl(replaceCollectionId(file.url, currentCollectionUuid),
24                                                     state.auth.config.keepWebServiceUrl,
25                                                     state.auth.config.keepWebInlineServiceUrl),
26                 kind: 'file',
27                 customText: "Copy link to latest version",
28             };
29         }
30     }
31     return {};
32 };
33
34 const mapStateToPropsPDH = (state: RootState) => {
35     const { resource } = state.contextMenu;
36     const currentCollectionPDH = state.collectionPanel.item ? state.collectionPanel.item.portableDataHash : '';
37     if (resource && [
38         ContextMenuKind.COLLECTION_FILE_ITEM,
39         ContextMenuKind.READONLY_COLLECTION_FILE_ITEM,
40         ContextMenuKind.COLLECTION_DIRECTORY_ITEM,
41         ContextMenuKind.READONLY_COLLECTION_DIRECTORY_ITEM ].indexOf(resource.menuKind as ContextMenuKind) > -1) {
42         const file = getNodeValue(resource.uuid)(state.collectionPanelFiles);
43         if (file) {
44             return {
45                 href: getCollectionItemClipboardUrl(replaceCollectionId(file.url, currentCollectionPDH),
46                                                     state.auth.config.keepWebServiceUrl,
47                                                     state.auth.config.keepWebInlineServiceUrl),
48                 kind: 'file',
49                 customText: "Copy link to immutable version",
50             };
51         }
52     }
53     return {};
54 };
55
56 const mapStateToPropsCWL = (state: RootState) => {
57     const { resource } = state.contextMenu;
58     const currentCollectionPDH = state.collectionPanel.item ? state.collectionPanel.item.portableDataHash : '';
59     if (resource && [
60         ContextMenuKind.COLLECTION_FILE_ITEM,
61         ContextMenuKind.READONLY_COLLECTION_FILE_ITEM,
62         ContextMenuKind.COLLECTION_DIRECTORY_ITEM,
63         ContextMenuKind.READONLY_COLLECTION_DIRECTORY_ITEM ].indexOf(resource.menuKind as ContextMenuKind) > -1) {
64         const file = getNodeValue(resource.uuid)(state.collectionPanelFiles);
65         if (file) {
66             let url = file.url;
67             url = replaceCollectionId(url, '');
68             url = sanitizeToken(url, false);
69             const path = new URL(url).pathname;
70             return {
71                 href: `keep:${currentCollectionPDH}${path}`,
72                 kind: 'file',
73                 customText: "Copy CWL file reference",
74             };
75         }
76     }
77     return {};
78 };
79
80 export const CollectionUUIDCopyToClipboardAction = connect(mapStateToPropsUUID)(CopyToClipboardAction);
81
82 export const CollectionPDHCopyToClipboardAction = connect(mapStateToPropsPDH)(CopyToClipboardAction);
83
84 export const CollectionCWLCopyToClipboardAction = connect(mapStateToPropsCWL)(CopyToClipboardAction);